Stream: general

Topic: ✔ Cannot build and run wasm32-wasi components


view this post on Zulip Nick (Sep 01 2023 at 02:55):

While trying to test very simple WASI components, I am getting errors associated with the return type of wasi:io/streams write method.

I think the source of the problem is that the wit files defining wasi:io/streams are different across different versions and don't appear to match for the current head of cargo component (e57d1d1) and wasmtime-wasi (12.0.1).
When I look at the build of my component I see

$ wasm-tools print target/wasm32-wasi/debug/rand.wasm
(component
  (type (;0;)
    (instance
      (type (;0;) u32)
      (export (;1;) "input-stream" (type (eq 0)))
      (type (;2;) u32)
      (export (;3;) "output-stream" (type (eq 2)))
      (type (;4;) (enum "open" "ended"))
      (export (;5;) "stream-status" (type (eq 4)))
      (type (;6;) (func (param "this" 1)))
      (export (;0;) "drop-input-stream" (func (type 6)))
      (type (;7;) (list u8))
      (type (;8;) (tuple u64 5))
      (type (;9;) (result 8))
      (type (;10;) (func (param "this" 3) (param "buf" 7) (result 9)))
      (export (;1;) "write" (func (type 10)))
      (export (;2;) "blocking-write" (func (type 10)))
      (type (;11;) (func (param "this" 3)))
      (export (;3;) "drop-output-stream" (func (type 11)))
    )
  )
...

which indicates a write type of func(this: u32, buf: list<u8>, result<u64, stream-status>).
This matches here and here.

However, the wasmtime-wasi=11.01 and wasmtime-wasi=12.01 both differ from this definition!
According the files downloaded to my .cargo/registry:

wasmtime-wasi 11.01

write: func(
    this: output-stream,
    /// Data to write
    buf: list<u8>
) -> result<u64, stream-error>

wasmtime-wasi 12.01

write: func(
    this: output-stream,
    /// Data to write
    buf: list<u8>
) -> result<tuple<u64, stream-status>, stream-error>

How can I get my wasm32-wasi component building and running?

view this post on Zulip Alex Crichton (Sep 01 2023 at 03:02):

You'll want to pair the adapter and Wasmtime together at this time. WASI is evolving meaning that if any one piece of the toolchain/tooling/etc uses WASI then everything must agree on that. Can you use the adapter and Wasmtime both at version 12?

view this post on Zulip Nick (Sep 01 2023 at 03:05):

Gotcha. I'll give it a try and report back, thanks.

view this post on Zulip Nick (Sep 01 2023 at 03:39):

Yup, that worked; thanks!

view this post on Zulip Notification Bot (Sep 01 2023 at 03:39):

Nick has marked this topic as resolved.


Last updated: Nov 22 2024 at 16:03 UTC