Rust target wasm32-wasi:
rustup target add wasm32-wasi
CMake
cpetig/wit-bindgen:
git clone https://github.com/cpetig/wit-bindgen.git
cd wit-bindgen
cargo install --path .
Guest | Host | |
---|---|---|
C | ✅ wit-bindgen | see below1 |
C++ | 🚧 cpetig/wit-bindgen | 🚧 cpetig/wit-bindgen + WAMR |
Rust | ✅ wit-bindgen | ✅ wasmtime 2 |
JavaScript | 🚧 3 | ✅ jco 2 |
Go | ☁️ 4 | ? |
Python | 🚧 5 | 🚧 5 |
cd guest-rust
cargo build --target wasm32-wasi --release
cd ../host-wamr
./generate.sh
mkdir build
cd build
cmake ..
make
./executor
Expected Output:
drop with value 34
Prerequisite: wasi-SDK
cd guest-c
./generate.sh
make
cd ..
ln -sf guest-c/guest-c.wasm guest.wasm
You need a preview1 adapter matching the wasmtime version, see https://github.com/bytecodealliance/wasmtime/releases for the command adapter downloads.
But most likely you will need to check out the exact same wasmtime used for the host and build the adapter:
cd wasmtime/crates/wasi-preview1-component-adapter
cargo build -p wasi-preview1-component-adapter --target wasm32-unknown-unknown --release --features command --no-default-features
cp ../../target/wasm32-unknown-unknown/release/wasi_snapshot_preview1.wasm …/resource-demo/host-wasmtime
Sorry, jco is currently broken until I figure out to compile typescript (shouldn't be that difficult to do).
Please use the adapter built from the wasmtime source (see above)
cargo install simple-http-server
./generate.sh
simple-http-server --cors --coop --coep --nocache -i html
-
Rust:
Wasmer bindgen only supports the old witx, not the newer wit format. You could write a host binding generator within wit-bindgen though.
- Python: https://pypi.org/project/componentize-py/ (?)
The wasmtime host requires wasi_snapshot_preview1.wasm from (the dev branch) (WASI has recently migrated to resources)
JCO's preview2 browser shim still needs the older adapter
JavaScript: https://github.com/bytecodealliance/javy is potentially smaller than spidermonkey embedded by jco, you will need another tool to generate guest bindings for imported functions, IIRC. A path using C bindings with yet to be written JavaScript wrapping should be viable.
Footnotes
-
Currently I generate C++ host bindings for WAMR, C would be feasible. ↩
-
JCO and wasmtime currently need a different preview1 to preview2 adapter version ↩ ↩2
-
Jco likely needs the unfinished https://github.com/bytecodealliance/componentize-js/tree/resources for resource support in guests ↩
-
Go: WIT bindgen support is being worked on ↩
-
Python: https://pypi.org/project/componentize-py/ recently gained resource support ↩ ↩2