-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compiled wasm32-wasip2 component from simple code requires excessive WASI interfaces #133235
Comments
EDIT: Nevermind I read the zulip thread, so this is T-libs
|
This comment has been minimized.
This comment has been minimized.
Ah right we have a wasi ping group now |
Hey WASI notification group! This issue or PR could use some WASI-specific guidance. (In case it's useful, here are some instructions for tackling these sorts of |
My guess would be that format is pulling in the entire panic machinery which includes a lot more string formatting. You could try compiling the wasm binary and std with panic immediate abort (I don’t know the exact flags by heart) and see if that removes those extraneous environmental dependencies. |
Based on rust-lang/wg-cargo-std-aware#29 it might be something like |
Those look correct - you might also need |
Alright, I changed my build command to error[E0152]: duplicate lang item in crate `core`: `sized`
|
= note: the lang item is first defined in crate `core` (which `implementation` depends on)
= note: first definition in `core` loaded from /Users/zhiqiu/offline_code/opensource/wit_issue/implementation/target/wasm32-wasip2/release/deps/libcore-55d3ecbce88cf86e.rlib, /Users/zhiqiu/offline_code/opensource/wit_issue/implementation/target/wasm32-wasip2/release/deps/libcore-55d3ecbce88cf86e.rmeta
= note: second definition in `core` loaded from /Users/zhiqiu/.rustup/toolchains/nightly-2024-11-19-aarch64-apple-darwin/lib/rustlib/wasm32-wasip2/lib/libcore-65e53cbf30438bae.rlib
This is out of my mind and I don't know if it's another solvable issue or bug....... Kind of reminds me of the horrible building errors in C. I think you can reproduce this in this branch of my repo. |
Maybe using |
@bjorn3 Thanks, I tried this error[E0152]: duplicate lang item in crate `core`: `sized`
|
= note: the lang item is first defined in crate `core` (which `implementation` depends on)
= note: first definition in `core` loaded from /Users/zhiqiu/offline_code/opensource/wit_issue/implementation/target/wasm32-wasip2/release/deps/libcore-65b8a47a5d02d391.rlib, /Users/zhiqiu/offline_code/opensource/wit_issue/implementation/target/wasm32-wasip2/release/deps/libcore-65b8a47a5d02d391.rmeta
= note: second definition in `core` loaded from /Users/zhiqiu/.rustup/toolchains/nightly-2024-11-19-aarch64-apple-darwin/lib/rustlib/wasm32-wasip2/lib/libcore-65e53cbf30438bae.rlib
For more information about this error, try `rustc --explain E0152` And I don't quite understand the explanation given by |
I believe the command you want is:
Notably
which I believe is what you want |
@alexcrichton Wow! That works like a charm. Thanks a lot! As a Rust application developer and a WASI newbie, that long command has a lot to take in. I have a few questions (not trying to push anything but for discussion):
Do you guys think those questions are hard to answer? I might just write up a blog or actually try to solve these issues if they are not like rabbit-hole hard. |
Yes, if you use any libstd api that needs those interfaces, they will automatically be imported.
The standard library has what is effectively1 a call to: bindgen!({
path: "/path/to/wasip2/cli/imports.wat",
world: "wasi:cli/imports",
}); which causes all interfaces in the Footnotes
|
Thst's.......... a lot of information and clears out most of the mist in my mind. Thanks a lot! @bjorn3 I'd like to ask a few more questions, if you don't mind.
This partially explains why
Take Taking a step back, I think the information you provided is really valuable and useful for understanding how WASI generally works in Rust. Can you please put that in the rustc book? I could make a PR, but I think it's not appropriate for me to do that. |
During my learning and experiments of wasip2, I tried this simple code and compiled it to a wasip2 component:
and
The host code, which runs the component, is:
The block with a note binds many interfaces to avoid runtime errors that says something like
component imports instance wasi:cli/[email protected], but a matching implementation was not found in the linker.
Removing any one of the lines in the block will result in a runtime error.I expect this compiled component requires none of these WASI interfaces to run, since it has nothing to do with io, cli, etc. Binding these unnecessary interfaces may raise security concerns.
The full minimized code is here.
As a kind person pointed out on ByteAlliance Zulip, these interfaces are required by
std
.Probably there's a way to minimize or prune the interface requirements in the compilation? I think rustc has all the information of which effects are used by any one of functions/macros that is used by a user.
At the very lease, I think we should document these requirements somewhere, so there are no hidden/dark interface dependencies that are not specified and unknown in WIT files.
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: