Repository navigation
Closed
Labels
gen-rustRelated to bindings for Rust-compiled-to-WebAssemblyRelated to bindings for Rust-compiled-to-WebAssembly
Description
I continue hacking on Brevity and ran into a case where wit-bindgen generates invalid Rust.
Here’s a little .wit declaration that uses a plain name.
package brevity:testing;
interface calculator {
multiply: func(a: s64, b: s64) -> s64;
}
world brevity-test {
export calculator;
export fast: calculator;
}Here’s Rust that implements the guest side:
mod bindings {
wit_bindgen::generate!({
path: "./wit/plain-name.wit",
});
use super::BrevityTesting;
export!(BrevityTesting);
}
struct BrevityTesting;
impl bindings::exports::ti85::Guest for BrevityTesting {
fn multiply(a: i64, b: i64) -> i64 {
a + b // TODO: integrate a real Texas Instruments TI-85
}
}
impl bindings::exports::brevity::testing::calculator::Guest for BrevityTesting {
fn multiply(a: i64, b: i64) -> i64 {
a * b
}
}Here’s the obvious cargo.toml:
[package]
name = "brevity-plain-name"
version = "0.1.0"
edition = "2024"
[dependencies]
wit-bindgen = "0.62.0"
[lib]
path = "src/plain_name.rs"
crate-type = ['cdylib']Expected
Program compiles
Actual
Compile fails.
$ cargo build --target=wasm32-wasip2 --release
Compiling brevity-plain-name v0.1.0 (/Volumes/Development/brevity/brevity-integration-tests/build/BrevityExecutionTester/primitives/rust)
error: linking with `wasm-component-ld` failed: exit status: 1
|
= note: "wasm-component-ld" "-flavor" "wasm" "--export" "brevity:testing/calculator#multiply" "--export" "ti85#multiply" "--export" "cabi_realloc" "-z" "stack-size=1048576" "--stack-first" "--allow-undefined" "--no-demangle" "<2 object files omitted>" "<sysroot>/lib/rustlib/wasm32-wasip2/lib/libpanic_abort-*.rlib" "/Volumes/Development/brevity/brevity-integration-tests/build/BrevityExecutionTester/primitives/rust/target/wasm32-wasip2/release/deps/{libwit_bindgen-a9a17699170366f4,libbitflags-cc700a69ed60199f}.rlib" "<sysroot>/lib/rustlib/wasm32-wasip2/lib/{libstd-*,libwasi-*,libwit_bindgen-*,libcfg_if-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,liblibc-*}.rlib" "-l" "c" "<sysroot>/lib/rustlib/wasm32-wasip2/lib/{librustc_std_workspace_core-*,liballoc-*,libcore-*,libcompiler_builtins-*}.rlib" "-L" "/Volumes/Development/brevity/brevity-integration-tests/build/BrevityExecutionTester/primitives/rust/target/wasm32-wasip2/release/build/wit-bindgen-f69cb0bf6d0bbc11/out" "-L" "<sysroot>/lib/rustlib/wasm32-wasip2/lib/self-contained" "-o" "/Volumes/Development/brevity/brevity-integration-tests/build/BrevityExecutionTester/primitives/rust/target/wasm32-wasip2/release/deps/brevity_plain_name.wasm" "--gc-sections" "--no-entry" "-O3" "--strip-debug"
= note: some arguments are omitted. use `--verbose` to show all linker arguments
= note: error: failed to parse core wasm for componentization
Caused by:
0: decoding custom section component-type:wit-bindgen:0.62.0:brevity:testing:brevity-test:encoded world
1: invalid leading byte (0x2) for export name (at offset 0x82)
error: could not compile `brevity-plain-name` (lib) due to 1 previous error
I think this snippet of the macro expansion might be relevant.
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 293] = *b"\
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xa2\x01\x01A\x02\x01\
A\x04\x01B\x02\x01@\x02\x01ax\x01bx\0x\x04\0\x08multiply\x01\0\x04\0\x1abrevity:\
testing/calculator\x05\0\x01B\x02\x01@\x02\x01ax\x01bx\0x\x04\0\x08multiply\x01\0\
\x04\x02\x04ti85\x01\0\x1abrevity:testing/calculator\x05\x01\x04\0\x1cbrevity:te\
sting/brevity-test\x04\0\x0b\x12\x01\0\x0cbrevity-test\x03\0\0\0G\x09producers\x01\
\x0cprocessed-by\x02\x0dwit-component\x070.259.0\x10wit-bindgen-rust\x060.62.0";
This isn’t blocking us. Thanks!
Metadata
Metadata
Assignees
Labels
gen-rustRelated to bindings for Rust-compiled-to-WebAssemblyRelated to bindings for Rust-compiled-to-WebAssembly
Activity
[-]wit-bindgen generates invalid Rust on plain names[/-][+]wit-bindgen generates invalid core wasm on plain names[/+]pchickey commentedon Oct 9, 2026
Wasm-tools first shipped support for implements component name support in version 249, wasm-component-ld first shipped with a compatible wasm-tools in 0.5.24, and the current rust stable (1.99.0) has wasm-component-ld at 0.5.27 which is based on wasm-tools 254. So, current stable shouldn't have this error, but maybe an older toolchain does - since you didn't provide toolchain version, can you check that this reproduces on rust 1.99 before we dig in further?
swankjesse commentedon Oct 11, 2026
I believe it’s still a problem on rust 1.99.
pchickey commentedon Oct 12, 2026
That's a different error - it looks like you used the identifer
ti85in your hand-written Rust source but the wit uses the import namefastswankjesse commentedon Oct 13, 2026
Ooof, that’s me being too cute with my minimal repro. I fixed that and the code builds properly.
That’s very nice to see. I’m closing this issue!