This is a template-like, example-driven set of non-published crates used for
building Wasm components in order to run and test them on the latest
wasmtime runtime, with the component-model
feature turned on.
We use the components compiled from this crate as fixtures for our execution-and-IPLD-focused homestar-wasm crate. We currently rely on the WIT format IDL to describe exports, for example:
default world homestar {
export add-one: func(a: s32) -> s32
export append-string: func(a: string) -> string
export transpose: func(matrix: list<list<u8>>) -> list<list<u8>>
}
We then implement these functions in lib.rs using wit-bindgen/wit-bindgen-rt, a guest language bindings generator for WIT and the Component Model.
Once functions are implemented, we can use cargo-component to
generate the necessary bindings and build the component in release-mode,
targeting wasm32-unknown-unknown
:
# from this directory:
cd test && cargo component build --target wasm32-unknown-unknown --profile release-wasm-fn
# or from the top-level workspace:
cargo component build -p homestar-functions-test --target wasm32-unknown-unknown --profile release-wasm-fn
We can also use the cargo-component default wasm32-wasi
target:
cargo component build -p homestar-functions-test --profile release-wasm-fn
Guest Wasm modules will be generated in the top-level homestar
directory:
./target/wasm32-unknown-unknown/release-wasm-fn/homestar_functions_test.wasm
or ./target/wasm32-wasi/release-wasm-fn/homestar_functions_test.wasm
.
- keyvalue-component-model-demo
- SpiderLightning - defines a set of
*.wit
files that abstract distributed application capabilities, such as key-value, messaging, http-server/client and more.
This project is licensed under the Apache License 2.0, or http://www.apache.org/licenses/LICENSE-2.0.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.