I'm trying to build a simple host for components built using cargo component new
. I've basically copy/pasted the code here: https://github.com/bytecodealliance/wasmtime/blob/main/examples/component/main.rs
I deleted the bindgen call and add_to_linker from the example because my component does not use any explicit imports.
However my component (hello world from cargo component new
) can't be instantiated. I get "Error: import wasi:cli/environment@0.2.0
has the wrong type"
I believe this is because bin components _implicitly_ import the wasi:cli world, but I could be mistaken. I also get the same error with a lib component with no imports.
Is there a good working example of a host that can run these components? I know that the wasmtime command can do it, but this is far from a minimal example and I'm getting lost in the code.
Code for context: https://github.com/littlebenlittle/wasi-repl/blob/error/host/src/main.rs
The wasm32-wasi
rust target implements stdlib features with wasi imports.
See this recent thread for similar discussion: https://bytecodealliance.zulipchat.com/#narrow/stream/407292-cargo-component/topic/.E2.9C.94.20Test.20host.20and.20guest.20not.20working
Thanks for the quick reply, Lann! I think this gets me pointed in the right direction. I'll update if (when) I get confused.
Sekhar's advice was exactly what I needed. I haven't been so delighted to see "hello world" in my terminal for quite some time.
Some general takeaways:
wasm-tools component wit
to view the actual interface used by the componentwasmtime-wasi
crate and implement WasiView
on your store's Host
typeI have a working example in this repo, but the code is a mess. You can look at the build-and-run-sys.sh
script and go from there.
Last updated: Nov 22 2024 at 16:03 UTC