Open ifsheldon opened 6 hours ago
I'm not a wasi/wasm expert by any means, but doesn't your example in the repo use wit_bindgen
which probably has non-trivial proc-macros? Is there a more minimal repro that only uses rustc
or cargo
but with only std
?
EDIT: Nevermind I read the zulip thread, so this is T-libs
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?
cc @alexcrichton, but my immediate feeling is that this is kinda working as intended?
Ah right we have a wasi ping group now @rustbot ping wasi
Hey WASI notification group! This issue or PR could use some WASI-specific guidance. Could one of you weigh in? Thanks <3
(In case it's useful, here are some instructions for tackling these sorts of issues).
cc @alexcrichton @burakemir @juntyr
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 https://github.com/rust-lang/wg-cargo-std-aware/issues/29 it might be something like cargo ... -Zbuild-std -Zbuild-std-features=panic_immediate_abort
(I haven't tried this)
Based on rust-lang/wg-cargo-std-aware#29 it might be something like
cargo ... -Zbuild-std -Zbuild-std-features=panic_immediate_abort
(I haven't tried this)
Those look correct - you might also need RUSTFLAGS=-C panic=abort
Alright, I changed my build command to RUSTFLAGS="-C panic=abort" cargo build --target wasm32-wasip2 --release -Zbuild-std -Zbuild-std-features=panic_immediate_abort
but I got this error
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.
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/environment@0.2.0, 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
: