Stream: git-wasmtime

Topic: wasmtime / PR #11761 Fix(wit_bindgen): use declared defau...


view this post on Zulip Wasmtime GitHub notifications bot (Sep 30 2025 at 11:06):

anlavandier opened PR #11761 from anlavandier:fix/bindgen-send to bytecodealliance:main:

<!--
Please make sure you include the following information:

Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.html

Please ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
Fixes #11752.

This change will ensure that bindgen! invocation with imports/exports: { default: async } will require generate T: Send bounds in WorldName::add_to_linker<T, D> even when the world doesn't import functions directly and only imports interfaces defined in another module.

An example of code that currently doesn't (but in my opinion) compile and will now compile is in the linked issue. It is reproduced below with minor touch-ups for convenience.

package example:example;

interface api {
    foo: func();
}

world bar {
    import api;
    export baz: func();
}

world api-impl {
    import api;
}
use wasmtime::component::bindgen;

bindgen!({
    world: "bar",
    path: "wit/example.wit",
    with: {
        "example:example/api": async_impl,
    },
    imports: {
        default: async
    }
});

pub mod async_impl {
    use wasmtime::component::bindgen;
    bindgen!({
        world: "api-impl",
        path: "wit/example.wit",
        imports: {
            default: async,
        }
    });

    pub struct MyHost;


    pub use example::example::api::{Host, HostWithStore, add_to_linker};

    impl Host for MyHost {
        async fn foo(&mut self) {
            let _ = 3 + 4;
        }
    }
}


fn main() {}

The compile error is the following:

error[E0277]: `T` cannot be sent between threads safely
  --> src/main.rs:3:1
   |
3  | / bindgen!({
4  | |     world: "bar",
5  | |     path: "wit/example.wit",
6  | |     with: {
...  |
12 | | });
   | |__^ `T` cannot be sent between threads safely
   |
note: required by a bound in `add_to_linker`
  --> src/main.rs:16:5
   |
16 | /     bindgen!({
17 | |         world: "api-impl",
18 | |         path: "wit/example.wit",
19 | |         imports: {
...  |
22 | |     });
   | |______^ required by this bound in `add_to_linker`
   = note: this error originates in the macro `bindgen` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting type parameter `T` with trait `Send`
   |
12 | }), T: std::marker::Send;
   |   ++++++++++++++++++++++

For more information about this error, try `rustc --explain E0277`.
error: could not compile `component-model-test` (bin "component-model-test") due to 1 previous error

view this post on Zulip Wasmtime GitHub notifications bot (Sep 30 2025 at 11:06):

anlavandier requested alexcrichton for a review on PR #11761.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 30 2025 at 11:06):

anlavandier requested wasmtime-core-reviewers for a review on PR #11761.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 30 2025 at 12:32):

anlavandier commented on PR #11761:

This PR makes the CI fail when comparing against previous expansions. If this contribution is deemed useful then changing the relevant files in crates/component-macro/tests/expanded/ is easy to do. I didn't do it at first because it would add a lot of changes that aren't related to the main point of this PR.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 30 2025 at 14:52):

anlavandier edited a comment on PR #11761:

This PR makes the CI fail when comparing against previous expansions. If this contribution is deemed useful then changing the relevant files in crates/component-macro/tests/expanded/ is easy to do. I didn't do it for now because it would add a lot of changes that aren't related to the main point of this PR.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 30 2025 at 19:44):

alexcrichton commented on PR #11761:

Seems reasonable enough to me, thanks! Would you be up for adding a test for this as well? (e.g. writing down your example in this PR in tests/codegen.rs). Then including the test updates in the expanded directory should be fine as well.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 01 2025 at 08:45):

anlavandier updated PR #11761.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 01 2025 at 08:46):

anlavandier commented on PR #11761:

Seems reasonable enough to me, thanks! Would you be up for adding a test for this as well? (e.g. writing down your example in this PR in tests/codegen.rs). Then including the test updates in the expanded directory should be fine as well.

@alexcrichton Done in the latest commits. If you have better ideas for names in the example added in codegen.rs I'm happy to oblige.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 01 2025 at 08:53):

anlavandier updated PR #11761.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 01 2025 at 08:55):

anlavandier updated PR #11761.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 01 2025 at 14:15):

alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 01 2025 at 14:39):

alexcrichton merged PR #11761.


Last updated: Dec 06 2025 at 07:03 UTC