Stream: wasmtime

Topic: Help: unnecessary interface requirement for using format!()?


view this post on Zulip mapleliang (Nov 20 2024 at 07:01):

Hi all! I am new to WASIp2 and running my experiments with it.

A seemingly trivial case trapped me for hours. I have a simple component written in Rust which uses only format!() in Rust std and a Rust host using wasmtime crate to run it. But the host gives me a lot of runtime errors saying something like

component imports instance wasi:cli/environment@0.2.0, but a matching implementation was not found in the linker.

This feels weird to me, why does format!() need to access the environment? To avoid these runtime errors, it turns out the following interfaces need to be linked to the linker:

Is it expected and why? Or, is it a bug?

My source code is here.

Contribute to ifsheldon/wit_interface_issue development by creating an account on GitHub.

view this post on Zulip bjorn3 (Nov 20 2024 at 07:04):

All of these are required by the rust standard library itself.

view this post on Zulip mapleliang (Nov 20 2024 at 07:11):

Thanks! From std point's of view, it's understandable. Do you know any documentation related to this? I was following the (very outdated) official documentations from bytecodealliance.org and wasmtime, nothing told me that. Their examples are just too trivial. Do you know any ways to work around this issue? Or, we just need to wait for std to better support the component model?

Welcome to the Bytecode Alliance

view this post on Zulip bjorn3 (Nov 20 2024 at 13:36):

The wasm32-wasip2 rust target needs the wasi-cli world to be present.

https://doc.rust-lang.org/rustc/platform-support/wasm32-wasip2.html#platform-requirements

Platform requirements

The WebAssembly runtime should support the wasi preview 2 API set.

view this post on Zulip Lann Martin (Nov 20 2024 at 14:31):

You might find the component model rust documentation useful: https://component-model.bytecodealliance.org/language-support/rust.html

view this post on Zulip mapleliang (Nov 21 2024 at 06:37):

bjorn3 发言道

The wasm32-wasip2 rust target needs the wasi-cli world to be present.

https://doc.rust-lang.org/rustc/platform-support/wasm32-wasip2.html#platform-requirements

Platform requirements

The WebAssembly runtime should support the wasi preview 2 API set.

I did look up this link before. I even filed a minor issue about the outdated tier information in this page, which got fixed yesterday.

The content there is

The WebAssembly runtime should support the wasi preview 2 API set. Runtimes also are required to support components since this target outputs a component as opposed to a core wasm module. As of the time of this writing Wasmtime 17 and above is able to run this target natively with no extra flags.

I don't think this means "The wasm32-wasip2 rust target needs the wasi-cli world to be present". I'm not questioning about your sentence and I believe this is true. I just thought it'd be better if this documentation could have included this information. Maybe you can make a PR to add this line to the documentation? since you know better this target than me.

view this post on Zulip mapleliang (Nov 21 2024 at 06:52):

Lann Martin 发言道

You might find the component model rust documentation useful: https://component-model.bytecodealliance.org/language-support/rust.html

Yeah, it's useful in explaining concepts and basic implementation and I did read it before. Thanks!

But I think this documentation does not include the information I need to solve this issue, i.e., how to run a component with wasmtime crate with what required interfaces.

I think the documentation about WASIp2 in general is very fragmented. Useful information may be quickly out of date and scattered everywhere.

There are runtimes, dev tools, concepts, old standards (WASM modules, WASIp1) and compilers (with specific flags, features and stds). Each has their own documentation, which may contain useful and sometimes outdated infor about WASIp2. Some doc, like wasmtime's, has useful but outdated info about how to run a component, some with conceptual explanation.

This seems like a long complaint, but I think we need to these documentation issues.

view this post on Zulip Pat Hickey (Nov 21 2024 at 15:43):

Please file issues anywhere you see outdated or less than useful information in bytecode alliance repositories, or elsewhere. We will do what we can.

view this post on Zulip Victor Adossi (Nov 21 2024 at 17:57):

Hey a bit late here but @mapleliang the code that the component book comes with does hopefully solve the following issues:

But I think this documentation does not include the information I need to solve this issue, i.e., how to run a component with wasmtime crate with what required interfaces.

Unfortunately it's a little bit hard to find -- but there is an example of running a component there!

Like Pat said, would absolutely appreciate filing issues on the component-docs repository (I help do some docs maintenance around there)

A great first issue might be just that there needs to be a more comprehensive map (possibly on the front page of the component book, since that should be our go-to piece of docs)

Documentation around creating and using WebAssembly Components - bytecodealliance/component-docs

view this post on Zulip mapleliang (Nov 22 2024 at 02:24):

Victor Adossi 发言道

Hey a bit late here but mapleliang the code that the component book comes with does hopefully solve the following issues:

But I think this documentation does not include the information I need to solve this issue, i.e., how to run a component with wasmtime crate with what required interfaces.

Unfortunately it's a little bit hard to find -- but there is an example of running a component there!

Like Pat said, would absolutely appreciate filing issues on the component-docs repository (I help do some docs maintenance around there)

A great first issue might be just that there needs to be a more comprehensive map (possibly on the front page of the component book, since that should be our go-to piece of docs)

I did find this example, but this example is too trivial to cause the problem. A simple adder component needs no extra interfaces, so I don't know how to attach extra interfaces that are implicitly required by rust std. And this example is super outdated. As the dependencies wasmtime and wasmtime_wasi is 18.0 while the latest ones are 27.0. So, I will file an issue and probably a PR to renovate these examples.

Another issue is cargo-component itself is a bit outdated, I mean out of sync with Rust's wasm32-wasip2 current status. For example, it still use wasm32-wasip1 to compile components and then adapt them afterwards, while wasm32-wasip2 has been promoted to Tier 2 support from Rust side. See my issue for more details.

And I totally agree with you about the comprehensive mind map. After I get my head around this issue (and its tracking issue on Rust repo), I will write up a blog that casually introduces a mind map. I will see how that translate into a proper PR for reading on the component book.

cargo-component/README.md Line 184 in 1e58afa When the Rust compiler supports a [_preview2_ version of the WASI target][1], Hi! I saw this today, but the referred issue has been closed as complete....
During my learning and experiments of wasip2, I tried this simple code and compiled it to a wasip2 component: wit_bindgen::generate!({ // the name of the world in the `*.wit` input file world: "for...

view this post on Zulip mapleliang (Nov 27 2024 at 09:22):

Pat Hickey 发言道

Please file issues anywhere you see outdated or less than useful information in bytecode alliance repositories, or elsewhere. We will do what we can.

Do you know who to ping for this issue? I see there are commits to the main branch everyday, but it seems many issues in cargo-component repo got ignored.

cargo-component/README.md Line 184 in 1e58afa When the Rust compiler supports a [_preview2_ version of the WASI target][1], Hi! I saw this today, but the referred issue has been closed as complete....
A Cargo subcommand for creating WebAssembly components based on the component model proposal. - bytecodealliance/cargo-component

view this post on Zulip Dan Gohman (Nov 27 2024 at 15:48):

In theory it would be cool to use Rust's wasm32-wasip2 in cargo-component, but in practice it's not a trivial change. cargo-component is set up to build the components itself, so it needs more changes to work with the wasm32-wasip2 target where the components are built automatically.

view this post on Zulip Pat Hickey (Nov 27 2024 at 16:57):

I don’t know who is working on that in cargo-component. At first glance it appears that it’s an enhancement, rather than a bug to fix - cargo-component predated the p2 target so this is more of the case of upstream rust getting some of the functionality pioneered in cargo-component. @Dan Gohman are you working on this topic? @Calvin Prewitt has also been contributing there, maybe he has an idea.

view this post on Zulip Dan Gohman (Nov 27 2024 at 17:01):

I did take a quick look at this recently. One tricky issue I found was that cargo component supports import name maps, which I don't see a way to do in the current wasm32-wasip2 target.

view this post on Zulip Calvin Prewitt (Nov 27 2024 at 17:08):

I have some thoughts on it. @Daniel Macovei and I did start looking at it. But need to dig into it a bit more.

view this post on Zulip Dan Gohman (Nov 27 2024 at 19:15):

I've also now posted this PR to update the README.md part quoted in that issue.

Update the documentation talking about Rust's wasm32-wasip2 feature. We do hope to make use of it in cargo component, though it's not a trivial change. This is inspired by #355.

view this post on Zulip mapleliang (Dec 08 2024 at 08:34):

@Dan Gohman Can you please also take a look at https://github.com/bytecodealliance/cargo-component/issues/360 ?

I am following https://component-model.bytecodealliance.org/language-support/rust.html#importing-an-interface-into-a-command-component to create a command component with cargo-component. My adder W...

view this post on Zulip Dan Gohman (Dec 09 2024 at 01:02):

I've now replied in the issue.

view this post on Zulip mapleliang (Dec 10 2024 at 16:44):

@Victor Adossi Do you know who maintains the documentation of wasmtime? I filed a couple of issues there and I can also make PRs about them.

https://github.com/bytecodealliance/wasmtime/issues/9776
https://github.com/bytecodealliance/wasmtime/issues/9777

Feature There are no examples about using bindgen! with async: true, imports and resources in Rust hosts. Please add examples to do that. A bit of background I have a string.wit and a guest compone...
Feature Please renovate the WASI example in the documentation and the code, as they are using old wasi_common and super outdated wasmtime_wasi . Benefit Updating the doc and example should allow ne...

view this post on Zulip Victor Adossi (Dec 10 2024 at 17:16):

Actually I don't -- I'm not sure there is a specific documentation maintainer for wasmtime, but I assume that would by default fall under the purview of SIG Documentation!

They also have a channel here #SIG Documentation -- you can get in touch with people that way

That said, I think they'd pop up in the PRs (and issue discussion) if you made them :)

Contribute to bytecodealliance/meetings development by creating an account on GitHub.

Last updated: Dec 23 2024 at 14:03 UTC