bytecodealliance / componentize-py

Apache License 2.0
136 stars 13 forks source link

Running component without WASI #33

Closed eliabieri closed 7 months ago

eliabieri commented 11 months ago

Context

I have a Rust project that loads and executes wasm components using wasmtime. The wasmtime usage can be seen here.

If I try to instantiate a component generated using componentize-py, I get an error concerning a type mismatch with a WASI type

import `wasi:clocks/wall-clock` has the wrong type

Questions

Apologies if these questions should be clear from the documentation. I was just not able to figure these out, even after trying for some time.

Links

dicej commented 11 months ago

Am I forced to use WASI when I want to run a wasm component generated by componentiue-py?

You can use WASI-Virt to wrap the component with a virtual WASI implementation, e.g. wasi-virt my-component.wasm -o my-component-virt.wasm. The result should not import any WASI functions. Note that you won't see any stdout or stderr output from your component if you go this route, since WASI-Virt will just swallow it.

Alternatively, you can add wasmtime-wasi to the wasmtime Linker. Here's an example: https://github.com/bytecodealliance/wasmtime/blob/9e97d8e158f8a783d32f46f90b9b06f8261ed695/crates/test-programs/tests/reactor.rs#L49-L80

Note that WASI Preview 2 is still under development and changing rapidly, so you need to make sure you use a compatible version of wasmtime and wasmtime-wasi. Your best bet right now is to match the version which componentize-py uses (see the wasmtime submodule in this repo). I'm planning to update that to Wasmtime 13 once it's released.

dicej commented 7 months ago

I'm closing this to tidy up the issue list. @eliabieri please feel free to reopen if you feel there's more to discuss on this topic.