Stream: general

Topic: Issue compiling Rust component with async function


view this post on Zulip Nathaniel Cook (Dec 04 2025 at 22:07):

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.

view this post on Zulip Alex Crichton (Dec 04 2025 at 22:16):

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

view this post on Zulip Nathaniel Cook (Dec 04 2025 at 22:16):

Ok great, I am on latest stable, will try nightly thanks

view this post on Zulip ktz_alias (Dec 05 2025 at 04:16):

@Nathaniel Cook This is a work around. You can use wasm-tools to get around this issue:

  1. Compiling your code with thewasm32-wasip1 target.
  2. Run 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.

view this post on Zulip Nathaniel Cook (Dec 05 2025 at 04:42):

Thanks


Last updated: Dec 06 2025 at 05:03 UTC