I get a linking error when the WIT file contains a partial WASI interface, feels like a bug somewhere. Here are the steps to reproduce the error:
cargo new hellocargo build --target=wasm32-wasip2wasm-tools component wit hello.wasm --out-dir witwit-bindgen-cli rust wit --generate-all --stubscargo build --target=wasm32-wasip2, and get the following error:error: linking with `wasm-component-ld` failed: exit status: 1
|
= note: "wasm-component-ld" "-flavor" "wasm" "--export" "wasi:cli/run@0.2.3#run" "--export" "cabi_realloc" "-z" "stack-size=1048576" "--stack-first" "--allow-undefined" "--no-demangle" "<15 object files omitted>" "/private/tmp/tt/target/wasm32-wasip2/debug/deps/{libwit_bindgen_rt-4a4c516dfc37d215.rlib}.rlib" "<sysroot>/lib/rustlib/wasm32-wasip2/lib/{libstd-*,libpanic_abort-*,libwasi-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,libcfg_if-*,liblibc-*}.rlib" "-l" "c" "<sysroot>/lib/rustlib/wasm32-wasip2/lib/{liballoc-*,librustc_std_workspace_core-*,libcore-*,libcompiler_builtins-*}.rlib" "-L" "/private/tmp/tt/target/wasm32-wasip2/debug/build/wit-bindgen-rt-0de5cf11dd12c7f4/out" "-L" "<sysroot>/lib/rustlib/wasm32-wasip2/lib/self-contained" "-o" "/private/tmp/tt/target/wasm32-wasip2/debug/deps/tt.wasm" "--gc-sections" "--no-entry" "-O0"
= note: some arguments are omitted. use `--verbose` to show all linker arguments
= note: error: failed to inject adapter
Caused by:
0: failed to merge WIT packages of adapter `wasi_snapshot_preview1` into main packages
1: failed to merge WIT package sets together
2: failed to merge package `wasi:io@0.2.3` into existing copy
3: failed to merge interface `error`
4: expected function `[method]error.to-debug-string` to be present
The generated io.wit from wasm-tools doesn't contain the to-debug-string method. I guess it's because it's not used by the code and gets removed? But it feels like this round-trip should just work..
The same bindgen file can be compiled with wasm32-unknown-unknown, but it doesn't produce a valid component.
The root of this problem is a relatively obscure issue -- https://github.com/bytecodealliance/wasm-tools/issues/1897 -- but I believe that's what's happening here
hmm, non-commutative looks fine to me. If we are following subtyping, merging is not commutative by definition. Commutative holds only when the two packages are disjoint. In cargo build, can we merge the main package into WASI, instead of the other way around? That seems to always work?
the lack of commutativity is what's the problem here, you shouldn't have to order the merges since everything has the same source of truth as WASI with the original WITs, and in theory it shouldn't require doing things in the other order to get things to work. If you can arrange that though "do things in the other order" can get things to temporarily work
Last updated: Dec 06 2025 at 07:03 UTC