Skip to content

rust: async function failed to compile with wit-bindgen 0.48.0 #1421

@crlcrl1

Description

@crlcrl1

Async functions fail to compile with wit-bindgen==0.48.0, but works fine with wit-bindgen==0.47.0. Here is a minimal reproduce:

Cargo.toml:

[package]
name = "wit-test"
version = "0.1.0"
edition = "2024"

[lib]
crate-type = ["cdylib"]

[dependencies]
wit-bindgen = "xxx" # change this to 0.47.0 or 0.48.0

wit/adder/world.wit:

package docs:adder@0.1.0;

interface add {
    add: async func(a: u32, b: u32) -> u32;
}

world adder {
    export add;
}

src/lib.rs

use crate::bindings::exports::docs::adder::add::Guest;

mod bindings {
    wit_bindgen::generate!({
        path: "wit/adder/world.wit",
    });

    use super::AdderComponent;
    export!(AdderComponent);
}

struct AdderComponent;

impl Guest for AdderComponent {
    async fn add(a: u32, b: u32) -> u32 {
        a + b
    }
}

I compile it with cargo build --target wasm32-wasip2. Here is the compiler output:

error: linking with `wasm-component-ld` failed: exit status: 1
  |
  = note:  "wasm-component-ld" "-flavor" "wasm" "--export" "[async-lift]docs:adder/[email protected]#add" "--export" "[callback][async-lift]docs:adder/[email protected]#add" "--export" "cabi_realloc" "-z" "stack-size=1048576" "--stack-first" "--allow-undefined" "--no-demangle" "<15 object files omitted>" "<sysroot>/lib/rustlib/wasm32-wasip2/lib/libpanic_abort-*.rlib" "/home/crl/code/rust/wit-test/target/wasm32-wasip2/debug/deps/{libwit_bindgen-918753b0b2fdee64,libbitflags-d3add546d7ca84d2}.rlib" "<sysroot>/lib/rustlib/wasm32-wasip2/lib/{libstd-*,libwasi-*,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" "/home/crl/code/rust/wit-test/target/wasm32-wasip2/debug/build/wit-bindgen-5be24b2b4ddface3/out" "-L" "<sysroot>/lib/rustlib/wasm32-wasip2/lib/self-contained" "-o" "/home/crl/code/rust/wit-test/target/wasm32-wasip2/debug/deps/wit_test.wasm" "--gc-sections" "--no-entry" "-O0"
  = 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.48.0:docs:[email protected]:adder:encoded world
              1: invalid leading byte (0x43) for component defined type (at offset 0x2f)

My rust version is 1.91.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions