diff --git a/README.md b/README.md index 4b209ef..7504900 100644 --- a/README.md +++ b/README.md @@ -149,16 +149,16 @@ create: async func( ) -> result; ``` -The WIT can be given as `text`, with any packages the world depends on defined inline in nested `package ns:name { ... }` blocks. It can also be given as `encoded`, a WIT package encoded as wasm, e.g. from `wasm-tools component wit --wasm` or `wkg build`, which carries its dependencies with it. Or it can be given as `parsed`, the `wit` record returned by `componentized:component/wit#extract`, e.g. from the [`extract-wit`](https://github.com/componentized/component/tree/main/components/extract-wit) component. `world` works the same as the CLI's `--world` flag, and `overrides` given as `wave(...)` holds the same WAVE as an `--overrides` file. `overrides` is a variant so other ways to give values can be added later. +The WIT can be given as `text`, with any packages the world depends on defined inline in nested `package ns:name { ... }` blocks. It can also be given as `encoded`, a WIT package encoded as wasm, e.g. from `wasm-tools component wit --wasm` or `wkg build`, which carries its dependencies with it. Or it can be given as `parsed`, the `wit` record returned by `componentized:component/wit#parse`, e.g. from the [`wit-tools`](https://github.com/componentized/component/tree/main/components/wit-tools) component. `world` works the same as the CLI's `--world` flag, and `overrides` given as `wave(...)` holds the same WAVE as an `--overrides` file. `overrides` is a variant so other ways to give values can be added later. `extract` also accepts components, and so can the factory: when the `parsed` WIT was extracted from a component rather than a WIT package, the factory implements that component's world unless `world` names another one. Components don't carry doc comments, so there are no `@value` tags; every value must come from `overrides`. -The factory imports `componentized:component/types` and `componentized:component/wit`, but only for their types, not their functions, so hosts can satisfy them with empty instances. Hosts must support the component model async ABI and maps; with `wasmtime run`, enable them with `-W component-model-async=y,component-model-map=y`: +The factory imports `componentized:component/types` and `componentized:component/wit`, but only for their types, not their functions, so hosts can satisfy them with empty instances. Hosts must support the component model async ABI and maps; with `wasmtime run`, enable them with `-W component-model-map=y`: ```sh -wasmtime run -W component-model-async=y,component-model-map=y \ - --invoke 'create(text("package a:b; world w { /// @value 42\n export answer: func() -> u32; }"), none, none)' \ - lib/factory.wasm +wasmtime run -W component-model-map=y \ + --invoke 'create(wit("package a:b; world w { /// @value 42\n export answer: func() -> u32; }"), none, none)' \ + target/components/factory/factory.wasm ``` ## Build @@ -172,9 +172,9 @@ Prereqs: make components ``` -The build creates each component in [`components`](./components) into `lib`, e.g. the factory at `lib/factory.wasm`, along with `lib/interface.wasm`, the `componentized:constants` WIT package. Each component is also built with debug info, e.g. `lib/factory.debug.wasm`. +The build creates each component in [`components`](./components) into `target/components`, e.g. the factory at `target/components/factory/factory.wasm`, along with `target/components/interface.wasm`, the `componentized:constants` WIT package. Each component is also built with debug info, e.g. `target/components/factory/factory.debug.wasm`. -To run the tests, which exercise the CLI and the components, using the `extract-wit` component from `componentized:component`, which the build fetches to `lib/dep-extract-wit.wasm`: +To run the tests, which exercise the CLI and the components, using the `wit-tools` component from `componentized:component`, which the build fetches to `target/components/dep-wit-tools/dep-wit-tools.wasm`: ```sh make test diff --git a/components/dep-extract-wit/README.md b/components/dep-extract-wit/README.md deleted file mode 100644 index 50f4436..0000000 --- a/components/dep-extract-wit/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# `dep-extract-wit` - -The [`extract-wit`](https://github.com/componentized/component/tree/main/components/extract-wit) component from `componentized:component`, used by the tests to exercise the factory with parsed WIT. - -## Interfaces - -Imports: - -- `componentized:component/types@0.0.0-dev`: the `component` and `error` types - -Exports: - -- `componentized:component/wit@0.0.0-dev`: extracts the WIT from a WIT package or component diff --git a/components/dep-extract-wit/dep-extract-wit.wkg b/components/dep-extract-wit/dep-extract-wit.wkg deleted file mode 100644 index eb41ca6..0000000 --- a/components/dep-extract-wit/dep-extract-wit.wkg +++ /dev/null @@ -1,2 +0,0 @@ -ghcr.io/componentized/component/extract-wit:0.0.0-dev@sha256:a76d51697da7cb82a0a4b45fd40cb18bac73996e3321c8fd3a7f83b24712c84c -ghcr.io/componentized/component/extract-wit:0.0.0-dev_debug@sha256:28e7ce10873511fef4f354f20a8df88c01e8961e2a93be2b3ce9a7580f74a98e diff --git a/components/dep-wit-tools/README.md b/components/dep-wit-tools/README.md new file mode 100644 index 0000000..29fbaf1 --- /dev/null +++ b/components/dep-wit-tools/README.md @@ -0,0 +1,13 @@ +# `dep-wit-tools` + +The [`wit-tools`](https://github.com/componentized/component/tree/main/components/wit-tools) component from `componentized:component`, used by the tests to exercise the factory with parsed WIT. + +## Interfaces + +Imports: + +- `componentized:component/types@0.1.0`: the `wasm` and `error-code` types + +Exports: + +- `componentized:component/wit@0.1.0`: extracts the WIT from a WIT package or component diff --git a/components/dep-wit-tools/dep-wit-tools.wkg b/components/dep-wit-tools/dep-wit-tools.wkg new file mode 100644 index 0000000..0d1287d --- /dev/null +++ b/components/dep-wit-tools/dep-wit-tools.wkg @@ -0,0 +1,2 @@ +ghcr.io/componentized/component/wit-tools:0.1.0@sha256:b164d67630abc2aaff9912d2453eb1dfe3c7beae727f47462412785fc7938fa2 +ghcr.io/componentized/component/wit-tools:0.1.0_debug@sha256:72af127083933b53049e11fc985ce17bb5eb8b2a030d7d071bd6414d84eca88e diff --git a/components/factory/README.md b/components/factory/README.md index 0db52ec..ed50e6e 100644 --- a/components/factory/README.md +++ b/components/factory/README.md @@ -6,8 +6,8 @@ Create components whose exported functions return constant values, from a WIT wo Imports: -- `componentized:component/types@0.0.0-dev`: the `component` and `error` types, only types are imported -- `componentized:component/wit@0.0.0-dev`: the `wit` type for parsed WIT, only types are imported +- `componentized:component/types@0.1.0`: the `component` and `error` types, only types are imported +- `componentized:component/wit@0.1.0`: the `wit` type for parsed WIT, only types are imported Exports: diff --git a/components/factory/tests/factory.rs b/components/factory/tests/factory.rs index 9f96764..766a1b4 100644 --- a/components/factory/tests/factory.rs +++ b/components/factory/tests/factory.rs @@ -1,5 +1,5 @@ //! Exercises the factory component built by make into `target/components/factory/factory.wasm`, -//! along with `target/components/dep-extract-wit/dep-extract-wit.wasm` from +//! along with `target/components/dep-wit-tools/dep-wit-tools.wasm` from //! `componentized:component`, which make also fetches. use anyhow::{Context, Result, anyhow, bail}; @@ -10,8 +10,8 @@ use wasmtime::{ component::{Component, Linker, Val}, }; -const TYPES: &str = "componentized:component/types@0.0.0-dev"; -const WIT_INTERFACE: &str = "componentized:component/wit@0.0.0-dev"; +const TYPES: &str = "componentized:component/types@0.1.0"; +const WIT_INTERFACE: &str = "componentized:component/wit@0.1.0"; const FACTORY_INTERFACE: &str = "componentized:constants/factory@0.2.0-dev"; fn engine() -> &'static Engine { @@ -48,9 +48,9 @@ fn factory() -> Result<&'static Component> { load("factory", &CACHE) } -fn extract_wit() -> Result<&'static Component> { +fn wit_tools() -> Result<&'static Component> { static CACHE: OnceLock> = OnceLock::new(); - load("dep-extract-wit", &CACHE) + load("dep-wit-tools", &CACHE) } /// Calls an async exported function, satisfying type-only imports with empty @@ -165,15 +165,18 @@ fn create( } } -/// Extracts the WIT from a component or encoded WIT package with -/// `componentized:component/wit#extract`. -fn extract(bytes: Vec) -> Result { +/// Parse the WIT from a component or encoded WIT package with +/// `componentized:component/wit#parse`. +fn parse(bytes: Vec) -> Result { let result = call_async( - extract_wit()?, + wit_tools()?, &[TYPES], WIT_INTERFACE, - "extract", - vec![bytes_val(bytes)], + "parse", + vec![Val::Variant( + "wasm".into(), + Some(Box::new(bytes_val(bytes))), + )], )?; unwrap_result(result)?.map_err(|e| anyhow!(e)) } @@ -251,7 +254,7 @@ fn it_creates_components_from_encoded_wit() -> Result<()> { #[test] fn it_creates_components_from_parsed_wit() -> Result<()> { - let wit = extract(encode(WIT)?)?; + let wit = parse(encode(WIT)?)?; let component = create(Wit::Parsed(wit), Some("config"), None)?.map_err(|e| anyhow!(e))?; assert_eq!(call_config(&component)?, vec![string("hello"), point(1, 2)]); Ok(()) @@ -262,8 +265,7 @@ fn it_creates_identical_components_from_encoded_and_parsed_wit() -> Result<()> { // exercises every supported type, including aliases and imported types let encoded = encode("crates/componentized-constants/tests/fixtures/all")?; let from_encoded = create(Wit::Wasm(encoded.clone()), None, None)?.map_err(|e| anyhow!(e))?; - let from_parsed = - create(Wit::Parsed(extract(encoded)?), None, None)?.map_err(|e| anyhow!(e))?; + let from_parsed = create(Wit::Parsed(parse(encoded)?), None, None)?.map_err(|e| anyhow!(e))?; assert!(from_encoded == from_parsed, "components differ"); Ok(()) } @@ -272,7 +274,7 @@ fn it_creates_identical_components_from_encoded_and_parsed_wit() -> Result<()> { fn it_reimplements_the_world_of_a_parsed_component() -> Result<()> { // components don't carry docs, so every value comes from the overrides let original = create(Wit::Wit(WIT), Some("config"), None)?.map_err(|e| anyhow!(e))?; - let wit = extract(original)?; + let wit = parse(original)?; let component = create( Wit::Parsed(wit), None, @@ -296,7 +298,7 @@ fn it_returns_errors() -> Result<()> { assert!(!err.is_empty()); let original = create(Wit::Wit(WIT), Some("config"), None)?.map_err(|e| anyhow!(e))?; - let err = create(Wit::Parsed(extract(original)?), None, None)?.expect_err("missing values"); + let err = create(Wit::Parsed(parse(original)?), None, None)?.expect_err("missing values"); assert!( err.contains("missing value for `example:factory/constants#greeting`"), "{err}" diff --git a/components/math/wkg.lock b/components/math/wkg.lock index 9254e46..e942a91 100644 --- a/components/math/wkg.lock +++ b/components/math/wkg.lock @@ -7,9 +7,9 @@ name = "componentized:component" registry = "componentized.dev" [[packages.versions]] -requirement = "=0.0.0-dev" -version = "0.0.0-dev" -digest = "sha256:2d7677a89ef49bef5d8d20848c431c76208753858f4871929066397d62542af7" +requirement = "=0.1.0" +version = "0.1.0" +digest = "sha256:b025920ca99a32febc514636a1dd04d1ad65cb8773d10d8e09a62445106ae90b" [[packages]] name = "wasi:config" diff --git a/components/types/wkg.lock b/components/types/wkg.lock index 9254e46..e942a91 100644 --- a/components/types/wkg.lock +++ b/components/types/wkg.lock @@ -7,9 +7,9 @@ name = "componentized:component" registry = "componentized.dev" [[packages.versions]] -requirement = "=0.0.0-dev" -version = "0.0.0-dev" -digest = "sha256:2d7677a89ef49bef5d8d20848c431c76208753858f4871929066397d62542af7" +requirement = "=0.1.0" +version = "0.1.0" +digest = "sha256:b025920ca99a32febc514636a1dd04d1ad65cb8773d10d8e09a62445106ae90b" [[packages]] name = "wasi:config" diff --git a/components/wkg.lock b/components/wkg.lock index 9254e46..e942a91 100644 --- a/components/wkg.lock +++ b/components/wkg.lock @@ -7,9 +7,9 @@ name = "componentized:component" registry = "componentized.dev" [[packages.versions]] -requirement = "=0.0.0-dev" -version = "0.0.0-dev" -digest = "sha256:2d7677a89ef49bef5d8d20848c431c76208753858f4871929066397d62542af7" +requirement = "=0.1.0" +version = "0.1.0" +digest = "sha256:b025920ca99a32febc514636a1dd04d1ad65cb8773d10d8e09a62445106ae90b" [[packages]] name = "wasi:config" diff --git a/wit/factory.wit b/wit/factory.wit index 885072b..495b431 100644 --- a/wit/factory.wit +++ b/wit/factory.wit @@ -1,7 +1,7 @@ /// Creates components whose exported functions return constant values. interface factory { - use componentized:component/types@0.0.0-dev.{wasm, error-code}; - use componentized:component/wit@0.0.0-dev.{wit, wit-source}; + use componentized:component/types@0.1.0.{wasm, error-code}; + use componentized:component/wit@0.1.0.{wit, wit-source}; /// Values replacing those from the WIT. The overrides are a record with /// an optional field per world export. Interface exports are named by the diff --git a/wkg.lock b/wkg.lock index 9254e46..e942a91 100644 --- a/wkg.lock +++ b/wkg.lock @@ -7,9 +7,9 @@ name = "componentized:component" registry = "componentized.dev" [[packages.versions]] -requirement = "=0.0.0-dev" -version = "0.0.0-dev" -digest = "sha256:2d7677a89ef49bef5d8d20848c431c76208753858f4871929066397d62542af7" +requirement = "=0.1.0" +version = "0.1.0" +digest = "sha256:b025920ca99a32febc514636a1dd04d1ad65cb8773d10d8e09a62445106ae90b" [[packages]] name = "wasi:config"