Stream: wit-bindgen

Topic: Possible linker error with wit-bindgen


view this post on Zulip Cameron M (May 09 2023 at 16:03):

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:

Trying 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

wasm-component-demo. Contribute to cameron1024/wasm-component-demo development by creating an account on GitHub.
Per bytecodealliance/wit-bindgen#259, I'm interested in upgrading the wasmtime dependency in wit-bindgen, and that has raised a more general question, which I'd like to ask here: What's the vision ...

view this post on Zulip Ramon Klass (May 09 2023 at 16:23):

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

Polyfill adapter for preview1-using wasm modules to call preview2 functions. - GitHub - bytecodealliance/preview2-prototyping: Polyfill adapter for preview1-using wasm modules to call preview2 func...

view this post on Zulip Cameron M (May 09 2023 at 16:52):

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