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...

Last updated: Nov 22 2024 at 16:03 UTC