Building a component with a WIT and host it with wasmtime programmatically and call a function is good and going fine but I can't get a wasi:cli/run component built to run with wasmtime cli.
I've tried exporting explicitly wasi:cli/run
from my a wit and building with wasm32-wasip2 without a wit just a fn main()
thinking it would magically create a wasi:cli/run
.
What am I missing?
Error: failed to run main module `target/wasm32-wasip2/debug/wasm32_wasip2.wasm`
Caused by:
no exported instance named `wasi:cli/run@0.2.2`
You pass -Scli
to the wasmtime CLI?
You shouldn't need -Scli
as that should be enabled by default, but can you detail your reproduction steps or the wasm binary you're trying to run?
Just building with wasm32-wasip2 a Rust file with fn main()
should create a component that exports wasi:cli/run
, right?
yes, and locally rustc foo.rs --target wasm32-wasip2 && wasmtime foo.wasm
works for me
Haha alright thanks. Pairing helps my brain work.
The crate was a lib and not a bin.
Is it possible to create a component from a Rust crate that wit_bindgen::generates a WIT Guest and also exports cli/run?
Cargo [[bin]] and [lib] will make separate components.
for rust [[bin]] will create a single component and it's required that it's got fn main()
and it'll export wasi:cli/run
. It'll also export anything wit_bindgen::generated'd internally.
For [[lib]] it only creates a component for the cdylib crate type and it'll have no exports by default, so it'll only have those that are wit_bindgen::generate'd
Last updated: Dec 23 2024 at 12:05 UTC