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:
sync::filesystem::types
sync::io::streams
cli::exit
cli::environment
cli::stdin
cli::stdout
cli::stderr
Is it expected and why? Or, is it a bug?
My source code is here.
All of these are required by the rust standard library itself.
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?
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.
You might find the component model rust documentation useful: https://component-model.bytecodealliance.org/language-support/rust.html
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.
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.
Please file issues anywhere you see outdated or less than useful information in bytecode alliance repositories, or elsewhere. We will do what we can.
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)
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.
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.
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.
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.
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.
I have some thoughts on it. @Daniel Macovei and I did start looking at it. But need to dig into it a bit more.
I've also now posted this PR to update the README.md part quoted in that issue.
@Dan Gohman Can you please also take a look at https://github.com/bytecodealliance/cargo-component/issues/360 ?
I've now replied in the issue.
@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
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 :)
Last updated: Dec 23 2024 at 14:03 UTC