Stream: general

Topic: Wasmtime, Rust target wasm32-wasip2 and wasi:cli/run


view this post on Zulip adam (Dec 17 2024 at 20:48):

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`

view this post on Zulip raskyld (Dec 17 2024 at 20:52):

You pass -Scli to the wasmtime CLI?

view this post on Zulip Alex Crichton (Dec 17 2024 at 20:53):

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?

view this post on Zulip adam (Dec 17 2024 at 20:56):

Just building with wasm32-wasip2 a Rust file with fn main() should create a component that exports wasi:cli/run, right?

view this post on Zulip Alex Crichton (Dec 17 2024 at 21:02):

yes, and locally rustc foo.rs --target wasm32-wasip2 && wasmtime foo.wasm works for me

view this post on Zulip adam (Dec 17 2024 at 21:05):

Haha alright thanks. Pairing helps my brain work.

The crate was a lib and not a bin.

view this post on Zulip adam (Dec 17 2024 at 21:11):

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.

view this post on Zulip Alex Crichton (Dec 17 2024 at 21:24):

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