Stream: wit-bindgen

Topic: wit-bindgen cs and wasm tools


view this post on Zulip James Sturtevant (Sep 13 2023 at 22:49):

Hi, we are continuing the effort for cs-bind-gen that we started at componentize the world with @Dan Chiarlone (danbugs).

We are trying the demo from the component docs to test a simple example but getting the following error. We've build a csharp component for the Adder world but after generating the wasi component with --adapt we get an error.

wasm-tools component embed --world adder wit/calculator.wit Adder_CS/bin/Debug/net7.0/Adder_CS.wasm -o main.embed.wasm
wasm-tools component new main.embed.wasm --adapt wasi_snapshot_preview1.reactor.wasm -o main.component.wasm
wasm-tools validate main.component.wasm --features component-model
#success

wasm-tools compose calculator/target/wasm32-wasi/release/calculator.wasm -d main.component.wasm -o composed.wasm
wasm-tools compose command/target/wasm32-wasi/release/command.wasm -d composed.wasm -o command.wasm
**error: cannot import instance with name `wasi:io/streams` for an instantiation argument of component `composed` because it conflicts with an imported instantiation argument of component `$input`**

We determined this instantiation argument is coming after running wasm-tools component new main.embed.wasm --adapt wasi_snapshot_preview1.reactor.wasm. Any ideas what might be going wrong? We don't see this output when using the Rust Adder Component.

view this post on Zulip Alex Crichton (Sep 13 2023 at 22:55):

Without knowing many details here, is that perhaps the adapters and/or WASI APIs being out-of-sync? WASI is defined by the wasi_snapshot_preview1.reactor.wasm argument you're providing but the */target/wasm32-wasi/release/*.wasm files, which I'm assuming are created with cargo component, additionally have their own adapter inside of them. If they all disagree on how WASI is defined it may cause that error

view this post on Zulip Alex Crichton (Sep 13 2023 at 22:56):

you can test this out I think by using the adapters from cargo component rather than those downloaded from the dev release of Wasmtime (unless you're already doing this in which case ignore me)

view this post on Zulip James Sturtevant (Sep 13 2023 at 22:57):

we can try that, Is there any to see those versions in the components themselves?

view this post on Zulip Alex Crichton (Sep 13 2023 at 22:58):

oh there is! if you do wasm-tools print you can hunt for @producers which I think should have a git rev

view this post on Zulip Alex Crichton (Sep 13 2023 at 22:58):

nope I take that back, looks like I may be lying

view this post on Zulip Alex Crichton (Sep 13 2023 at 22:59):

I don't think there's an easy way to learn that, no, but that is a really good idea!

view this post on Zulip James Sturtevant (Sep 13 2023 at 23:00):

Might even add that to the compose, if those versions don't match then give warning or error?

view this post on Zulip James Sturtevant (Sep 13 2023 at 23:05):

Ok so using the cargo component wasi_snapshot_preview1.reactor.wasm got past that error but now we are getting

wasmtime run -W component-model command.wasm 1 2 add
Error: failed to run main module `command.wasm`

Caused by:
    0: import `wasi:io/streams` has the wrong type
    1: instance export `write` has the wrong type
    2: type mismatch with results
    3: expected 0-tuple, found 2-tuple

view this post on Zulip James Sturtevant (Sep 13 2023 at 23:08):

we are using the dev version of the wasmtime executable, should we be using the 12.0.1 release version?

view this post on Zulip Alex Crichton (Sep 13 2023 at 23:13):

ah ok yeah that's definitely mismatched WASI definitions

view this post on Zulip Alex Crichton (Sep 13 2023 at 23:14):

12.0.1 doesn't have component model support in the CLI

view this post on Zulip Alex Crichton (Sep 13 2023 at 23:14):

the 13.0.1 release should work though, but you'll still need to make sure all adapters are in sync

view this post on Zulip James Sturtevant (Sep 13 2023 at 23:16):

where do we get 13? We built from main and ended up with version 14. I don't see any tags for 13

view this post on Zulip James Sturtevant (Sep 13 2023 at 23:18):

oh I see a branch release-13.0.0

view this post on Zulip James Sturtevant (Sep 13 2023 at 23:29):

is there a commit that would be 13.0.1? we are still having issues after building from the release-13.0.0 branch

view this post on Zulip James Sturtevant (Sep 13 2023 at 23:37):

ok, we went to the commit https://github.com/bytecodealliance/wasmtime/commit/134dddc and we are now executing the wasm module

* riscv64: Use `Inst::load_u64_constant` when loading load offsets * riscv64: Load ISLE constants from pool * riscv64: Delete `offset32_imm` * riscv64: Delete `pack_float_rounding_mode` * riscv...

view this post on Zulip James Sturtevant (Sep 13 2023 at 23:37):

this matched to the cargo component version

view this post on Zulip Alex Crichton (Sep 13 2023 at 23:39):

Ah yeah that works as well, but 13 isn't released yet and the branch has what will become the release in a week on the 20th

view this post on Zulip James Sturtevant (Sep 13 2023 at 23:57):

thanks we can execute modules now, but our module has a bug in it. Going to look into that tomorrow, are there wasm debugging tools? we have a stack trace but its says things are mostly <unknown>

view this post on Zulip Alex Crichton (Sep 14 2023 at 00:10):

Currently stack traces are the main debugging, and it's up to your compiler to fill in the unknown

view this post on Zulip Alex Crichton (Sep 14 2023 at 00:10):

With C/C++ that's -g

view this post on Zulip Scott Waye (Sep 14 2023 at 11:21):

NativveAot-llvm will populate the stack trace.

view this post on Zulip James Sturtevant (Sep 18 2023 at 19:53):

Thanks for the help last week! We did get a prototype working https://github.com/danbugs/wit-bindgen-cs. There is a short video at the end of the readme.md that shows it in action

Contribute to danbugs/wit-bindgen-cs development by creating an account on GitHub.

Last updated: Nov 22 2024 at 16:03 UTC