Skip to content

wit-bindgen generates invalid core wasm on plain names #1739

Closed

Description

@swankjesse

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!

Activity

  1. changed the title [-]wit-bindgen generates invalid Rust on plain names[/-] [+]wit-bindgen generates invalid core wasm on plain names[/+] on Oct 9, 2026
  2. added
    gen-rustRelated to bindings for Rust-compiled-to-WebAssembly
    on Oct 9, 2026
  3. pchickey commented on Oct 9, 2026

    @pchickey
    Contributor

    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?

  4. swankjesse commented on Oct 11, 2026

    @swankjesse
    Author

    I believe it’s still a problem on rust 1.99.

    $ cargo --version
    cargo 1.99.0 (5f94df478 2026-08-27)
    $ rustc --version
    rustc 1.99.0 (b940084d7 2026-09-28)
    $ cargo build --target=wasm32-wasip2 --release
       Compiling brevity-plain-name v0.1.0 (/Volumes/Development/brevity/brevity-integration-tests/build/BrevityExecutionTester/primitives/rust)
    error[E0433]: cannot find `ti85` in `exports`
      --> src/plain_name.rs:12:25
       |
    12 | impl bindings::exports::ti85::Guest for BrevityTesting {
       |                         ^^^^ could not find `ti85` in `exports`
    
    For more information about this error, try `rustc --explain E0433`.
    error: could not compile `brevity-plain-name` (lib) due to 1 previous error
    
  5. pchickey commented on Oct 12, 2026

    @pchickey
    Contributor

    That's a different error - it looks like you used the identifer ti85 in your hand-written Rust source but the wit uses the import name fast

  6. swankjesse commented on Oct 13, 2026

    @swankjesse
    Author

    Ooof, that’s me being too cute with my minimal repro. I fixed that and the code builds properly.

    $ cargo build --target=wasm32-wasip2 --release
       Compiling plain-name v0.1.0 (/Volumes/Development/brevity/brevity-integration-tests/build/BrevityExecutionTester/sizedLists/rust)
        Finished `release` profile [optimized] target(s) in 0.22s
    

    That’s very nice to see. I’m closing this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    gen-rustRelated to bindings for Rust-compiled-to-WebAssembly

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions