Stream: cargo-component

Topic: latest supported wasi wit definitions


view this post on Zulip Taylor Thomas (Sep 29 2023 at 19:37):

@Peter Huene Sorry for the lazy ask here, but how can I tell which versions of the wasi wit definitions are being used by cargo component? Trying to figure out an issue where one of my components (that has transitive dep on streams that is being included by cargo component build) seems to have a different version of streams than what is currently in https://github.com/WebAssembly/wasi-io/blob/main/wit/streams.wit

view this post on Zulip Peter Huene (Sep 29 2023 at 19:38):

cargo component --version will output the wasi adapter commit it's using, which corresponds to a commit in the wasmtime repo where the adapters are built out of

view this post on Zulip Peter Huene (Sep 29 2023 at 19:39):

there's also now a feature in cargo-component where you can point at the WASI adapter to use if you want to override the built-in

view this post on Zulip Peter Huene (Sep 29 2023 at 19:39):

by setting package.metadata.component.adapter in Cargo.toml to point at the adapter module

view this post on Zulip Peter Huene (Sep 29 2023 at 19:44):

The wits for the adapter are here: https://github.com/bytecodealliance/wasmtime/tree/main/crates/wasi/wit

view this post on Zulip Taylor Thomas (Sep 29 2023 at 20:05):

Oh that is a handy feature. Thank you

view this post on Zulip David Justice (Oct 05 2023 at 17:42):

@Taylor Thomas were you running into the following:

Caused by:
    0: import `wasi:io/streams` has the wrong type
    1: instance export `drop-input-stream` has the wrong type
    2: expected func found nothing

view this post on Zulip Taylor Thomas (Oct 05 2023 at 17:42):

I honestly can't remember

view this post on Zulip Taylor Thomas (Oct 05 2023 at 17:43):

I don't think that was it

view this post on Zulip Brian (Oct 05 2023 at 20:44):

@David Justice what's the output of cargo component -V?

view this post on Zulip David Justice (Oct 05 2023 at 21:05):

$ cargo component -V
cargo-component-component 0.1.0 (465baa9 2023-09-27 wasi:aec4b25)

view this post on Zulip Brian (Oct 05 2023 at 22:17):

I could be totally wrong here but the version of the adapter aec4b25 (from that output) i think is the commit in wasmtime you need to checkout

view this post on Zulip Brian (Oct 05 2023 at 22:17):

Worth a shot.

view this post on Zulip Brian (Oct 05 2023 at 22:19):

Alternatively cargo component (as peter mentions above) has an adapter field in the Cargo.toml that should allow you to set the version of the adapter to use i believe; I havent personally done this yet so im not 100% sure how to use it.

view this post on Zulip Brian (Oct 05 2023 at 22:41):

Yeah this seems to work:

> git checkout aec4b25
> cargo run --features component-model -- run --wasm-features component-model ../my-project/target/wasm32-wasi/debug/my-project.wasm

view this post on Zulip David Justice (Oct 06 2023 at 15:15):

I wasn't entirely clear how the adapter config was to be used. So I did the following:

[package.metadata.component]
adapter = "../../../wasi/wit/main.wit"   # points to the main.wit file in the wasmtime local repo I'm using to run the component

The component will compile, but fails after creating the component via:

error: decoding item in module

Caused by:
    magic header not detected: bad magic number (at offset 0x0)

view this post on Zulip Brian (Oct 06 2023 at 16:38):

@David Justice Here's the PR adding the adapter setting. TL;DR it takes a path to the WASI module adapter to use. So i suppose if you built the adapter yourself using wasmtime head you could pass that to cargo-component via the adapter setting to enable running your command on wasmtime head :shrug: . Have never done this myself as i usually use the prebuilt adapters from the wasmtime release page or the builtin one from cargo-component.

This PR adds a package.metadata.component.adapter field to Cargo.toml which is the path to the WASI module adapter to use. If present, the specified file is used to adapt WASI preview1 to preview2....

view this post on Zulip Peter Huene (Oct 06 2023 at 16:48):

I should definitely improve the error message, though. It is expecting a core module and not a wit file

view this post on Zulip Peter Huene (Oct 06 2023 at 16:49):

It's pretty easy to build the adapter module out of the Wasmtime repo

view this post on Zulip Peter Huene (Oct 06 2023 at 16:49):

Give me a sec to get to a computer and I'll paste the instructions

view this post on Zulip David Justice (Oct 06 2023 at 16:52):

I see! That makes so much more sense. I'll give it a go and post back. Thank you, @Peter Huene

view this post on Zulip Peter Huene (Oct 06 2023 at 16:55):

Here's the instructions for building the adapter out of the Wasmtime repo:

git checkout <rev>

cargo build -p wasi-preview1-component-adapter --target wasm32-unknown-unknown --release

cp wasm32-unknown-unknown/release/wasi_snapshot_preview1.wasm <path-to-component-project>

and then edit the component project’s Cargo.toml with adapter = "wasi_snapshot_preview1.wasm" under [package.metadata.component]

view this post on Zulip Peter Huene (Oct 06 2023 at 16:56):

(deleted)

view this post on Zulip Peter Huene (Oct 06 2023 at 17:36):

I'm going to update cargo-component's README to include this information

view this post on Zulip Peter Huene (Oct 06 2023 at 17:46):

the not so great error message "decoding item in module" is coming from wasm-tools, but at least i can adorn it with some additional context from cargo-component

view this post on Zulip Peter Huene (Oct 06 2023 at 17:58):

https://github.com/bytecodealliance/cargo-component/pull/151

This fixes two things: The error message when the adapter config setting point at something that is not a WebAssembly module. The README section about WASI support; it now includes information ...

Last updated: Nov 25 2024 at 19:03 UTC