Hi, apologies for the potentially basic question.
I'm trying to run a minimal demo of wit-bindgen. I've posted code at https://github.com/cameron1024/wasm-component-demo , though it's essentially the minimal Rust host + guest.
The WIT file looks like this:
default world myapp {
record foo {
bar: u64,
baz: u64,
}
import some-host-func: func(s: string)
export do-the-thing: func(data: foo)
}
When I build, I:
cargo build --target wasm32-wasi
wasm-tools
to create the component and add the WASI snapshotTrying to load this file gives the following error:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: import `streams` has the wrong type
Caused by:
0: instance export `drop-input-stream` has the wrong type
1: expected func found nothing', src/main.rs:19:81
To me, this suggests that WASI definitions are present in the component.wasm file I create, but aren't being provided by my host. (I can also see these if I use wasm-tools component wit component.wasm
)
In my searching, I came across this issue https://github.com/bytecodealliance/wasmtime/issues/4303 , which seems relevant. In particular, I noticed that there was a Myapp::add_to_linker
function for the struct generated by bindgen,, that I tried to use, but it seemed to give the same error.
I also tried the add_to_linker
function provided by the wasmtime-wasi
crate, but that required a wasmtime::Linker
, rather than a wasmtime::component::Linker
.
I feel like I'm missing something obvious, so any guidance would be much appreciated :sweat_smile: Thanks
you need the host from here https://github.com/bytecodealliance/preview2-prototyping for components, adding the preview2 functionality to the host is a bigger undertaking which is why it is currently still its own repo
I came across that repo, but wasn't quite sure how to use it. I've downloaded the compiled binary and linked it with wasm-tools component new ... --adapt wasi_snapshot_preview1.wasm
, but that doesn't seem to have changed anything.
Do I need to import that on the host side as well? (or instead?). Do you know if there are any examples of doing that? I had a look but wasn't able to figure it out?
Last updated: Dec 23 2024 at 13:07 UTC