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).
Last updated: Jan 24 2025 at 00:11 UTC