I'm experimenting with components and I often find myself wondering where in the source code the cause for a certain resulting WASI import is located. For example, I just tried to create a very simple component from Rust code using wit-bindgen, but it ends up importing all kinds of interfaces (wasi:io/cli/sockets/random/...), none of which I would deem necessary, even when compiling to --release
. It is not scalable to search through all dependency sources to find the root cause for each of these. Is there some automated way of doing this? How do you usually deal with it?
This is generally a language specific thing, it depends on what the language tooling decides to make possible, but in general there should be a way to avoid including interfaces that aren't used (or aren't necessary).
It turns out this is reported fairly often for the Rust toolchain (cargo-component
), here are some related discussions:
So the in general, for Rust in particular you can build to wasm32-unknown-unknown
and remove the dependence on WASI. The normal inclusion of the WASI interfaces when building a rust component is because of the panic/unwind machinery, and there are rust-specific ways to remove that as well (that currently require nightly).
As an example of other toolchains, jco
offers a --disable
option which can be used to remove WASI deps (for example, since fetch()
works in JS anywhere, wasi:http/outgoing-handler
is included by default).
I understand that there are ways to avoid WASI imports in general, but once I need some WASI imports but would like to investigate others which turn up unexpectedly, I would still need a way to identify their source. Is there any general top-down approach (as in wasm-to-source, not source-to-wasm)?
Sure -- in those threads linked the way I found where the requirements were was by following the WAT of the component itself.
If you use wasm-tools print
on the component, you can see the WAT, and you can follow the function calls for the individual import your concerned with, and see mangled names of functions that use those imports
Using that method would lead you to the Rust unwind/panic machinery fairly quickly, and should work for other languages, though how easy it is to connect the mangled name to behavior in your language of choice can vary
Last updated: Apr 07 2025 at 23:03 UTC