Hello again :) I'm trying to load a WASM component module that is compiled to target WASI. I have so far created the Engine, hooked up the WasiHostCtx
, and created the store. However, it seems like wasmtime_wasi::preview2::preview1::add_to_linker
expects a wasmtime::Linker
vs a wastime::component::Linker
, whereas MyWorld::add_to_linker
expects a wasmtime::component::Linker
instead :sweat_smile:
I _think_ I need a single linker with both of those hooked up in order to be able to run code from the WASM component module, is that correct? If so, is what I'm trying to do possible today? and how can I accomplish that? I'm using version 17.0.1
of both wasmtime
and wasmtime-wasi
for reference
Thanks in advance! :)
You're correct that you'll need to use a single linker. If you're using wasmtime::component::bindgen!
then you'll need to use wasmtime::component::Linker
since you're working with components rather than modules. In that case you'll want to call wasmtime_wasi::preview2::bindings::add_to_linker
. The preview1
module is specifically intended for compatibility with modules, not components.
(you probably already heard this before but apologies for the state of the docs, we're working on making them better!)
ah ok great! thanks for the info :)
hey @Alex Crichton , sorry to bother you again. I'm looking for wasmtime_wasi::preview2::bindings::add_to_linker
but I'm not seeing that symbol. Should I be looking for something else?
hmmmmm ok I found the add_to_linker
functions under sync_io::*
and those seem to work with a component::Linker
. I'm still running into a runtime error when trying to run my component though :) The guest is built from Rust targeting wasm32-wasi
and I've then run wasm-tools component new out.wasm -o out.component.wasm --adapt wasi_snapshot_preview1.reactor.wasm
to create the component. However I'm seeing the following error:
called `Result::unwrap()` on an `Err` value: import `wasi:cli/environment@0.2.0` has the wrong type
Caused by:
0: instance export `get-environment` has the wrong type
1: expected func found nothing
Ok interesting, if I compile my guest with target wasm32-unknown-unknown it seems to load and run correctly and everything, which is exciting. However, I believe that means I don't have access to e.g. the filesystem from the guest, is that correct? Is... there currently a way to do I/O in the guest?
https://docs.rs/wasmtime-wasi/17.0.1/wasmtime_wasi/preview2/command/sync/fn.add_to_linker.html might be what you're looking for.
A message was moved here from #general > Begining the process of proposing an Embedded SIG by Joel Dice.
I see, thanks! I'll give that a shot :)
nice! new error
called `Result::unwrap()` on an `Err` value: Custom { kind: Uncategorized, error: "failed to find a pre-opened file descriptor through which \"/tmp/test\" could be opened" }
which makes me think I need to do something with cap-std
to allow that to be read :thinking: will continue investigating, but thanks for the help so far!
When you create a WasiCtx
using WasiCtxBuilder
, you have the opportunity to map host directories into the guest filesystem. You'll need to do that in order for the guest to access any part of the host filesystem.
Might want to look at the wasmtime run
implementation as an example.
https://github.com/bytecodealliance/wasmtime/blob/main/src/commands/run.rs
ahhh perfect! thank you :)
Or maybe this one: https://docs.rs/wasmtime-wasi/17.0.1/wasmtime_wasi/sync/struct.WasiCtxBuilder.html#method.preopened_dir. I guess there are a few of them :) I think the one above is the right one.
ahhhhhh there we go! finally :D was able to read a file from the guest! thank you all so much for the help :grinning_face_with_smiling_eyes:
Till Schneidereit has marked this topic as resolved.
Last updated: Nov 22 2024 at 16:03 UTC