I have a simple wit world with a single async function:
package component:df@0.1.0;
interface df-interface {
fromcsv: async func(path: string) -> s64;
}
world root {
export df-interface;
}
In Rust I am attempting to implement the interface with this
mod bindings {
wit_bindgen::generate!();
use super::Module;
export!(Module);
}
struct Module;
impl bindings::exports::component::df::df_interface::Guest for Module {
async fn fromcsv(path: String) -> i64 {
0 // Actual implementation doesn't matter
}
}
However when building the component with
cargo build --target=wasm32-wasip2
I get a linking error
error: failed to parse core wasm for componentization
Caused by:
0: decoding custom section component-type:wit-bindgen:0.49.0:component:df@0.1.0:root:encoded world
1: invalid leading byte (0x43) for component defined type (at offset 0x2f)
Reading the spec I can see the 0x43 is the marker for an async function. If I remove the async aspect of the function everything builds but naturally I am not able to call async code in the implementation.
Happy to file a bug report on the right repo wasn't sure if this was a wasm-component-ld issue or further upstream before linking.
You'll want to use the latest nightly toolchain or build the latest wasm-component-ld and pass -Clinker=path/to/wasm-component-ld to rustc (via RUSTFLAGS through Cargo) -- what you're seeing here is that the wasm-component-ld shipped with Rust stable doesn't understand the latest async stuff
Ok great, I am on latest stable, will try nightly thanks
@Nathaniel Cook This is a work around. You can use wasm-tools to get around this issue:
wasm32-wasip1 target.wasm-tools component new to convert the the resulting module to wasip3 component.- You will need to pass the appropriate adapter for WASI-P3 using the --adapt option (e.g. wasi_snapshot_preview1.reactor.wasi, etc.).
- Just be aware that adapter compatibility depends on the wasm-tools version you’re using.
Thanks
Last updated: Dec 06 2025 at 05:03 UTC