Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Fix(wit_bindgen): use declared defaults to decide on `Send` Bounds in `Wastime::world_add_to_linker` (#11761)

anlavandier4dd4b89022ed
diff --git a/crates/component-macro/tests/codegen.rs b/crates/component-macro/tests/codegen.rs
index 9e6d5682a7..b128e3a346 100644
--- a/crates/component-macro/tests/codegen.rs
+++ b/crates/component-macro/tests/codegen.rs
@@ -729,3 +729,59 @@ mod paths {
});
}
}
+
+mod import_async_interface {
+ pub mod async_interface_implementation {
+ wasmtime::component::bindgen!({
+ world: "test:async-import/blah-impl",
+ inline: r#"
+ package test:async-import;
+
+ interface blah {
+ foo: func();
+ }
+
+ world blah-impl {
+ import blah;
+ }
+
+ world bar {
+ import blah;
+ }
+ "#,
+ imports: { default: async },
+ });
+
+ use test::async_import::blah::Host;
+ struct X;
+
+ impl Host for X {
+ async fn foo(&mut self) {}
+ }
+ }
+
+ mod require_t_send {
+ wasmtime::component::bindgen!({
+ world: "test:async-import/bar",
+ inline: r#"
+ package test:async-import;
+
+ interface blah {
+ foo: func();
+ }
+
+ world blah-impl {
+ import blah;
+ }
+
+ world bar {
+ import blah;
+ }
+ "#,
+ with: {
+ "test:async-import/blah": super::async_interface_implementation::test::async_import::blah,
+ },
+ imports: { default: async },
+ });
+ }
+}
diff --git a/crates/component-macro/tests/expanded/path1_async.rs b/crates/component-macro/tests/expanded/path1_async.rs
index 23b059eb7f..f985453a30 100644
--- a/crates/component-macro/tests/expanded/path1_async.rs
+++ b/crates/component-macro/tests/expanded/path1_async.rs
@@ -169,7 +169,7 @@ const _: () = {
where
D: paths::path1::test::HostWithStore,
for<'a> D::Data<'a>: paths::path1::test::Host,
- T: 'static,
+ T: 'static + Send,
{
paths::path1::test::add_to_linker::<T, D>(linker, host_getter)?;
Ok(())
diff --git a/crates/component-macro/tests/expanded/path1_concurrent.rs b/crates/component-macro/tests/expanded/path1_concurrent.rs
index 23b059eb7f..f985453a30 100644
--- a/crates/component-macro/tests/expanded/path1_concurrent.rs
+++ b/crates/component-macro/tests/expanded/path1_concurrent.rs
@@ -169,7 +169,7 @@ const _: () = {
where
D: paths::path1::test::HostWithStore,
for<'a> D::Data<'a>: paths::path1::test::Host,
- T: 'static,
+ T: 'static + Send,
{
paths::path1::test::add_to_linker::<T, D>(linker, host_getter)?;
Ok(())
diff --git a/crates/component-macro/tests/expanded/path1_tracing_async.rs b/crates/component-macro/tests/expanded/path1_tracing_async.rs
index 23b059eb7f..f985453a30 100644
--- a/crates/component-macro/tests/expanded/path1_tracing_async.rs
+++ b/crates/component-macro/tests/expanded/path1_tracing_async.rs
@@ -169,7 +169,7 @@ const _: () = {
where
D: paths::path1::test::HostWithStore,
for<'a> D::Data<'a>: paths::path1::test::Host,
- T: 'static,
+ T: 'static + Send,
{
paths::path1::test::add_to_linker::<T, D>(linker, host_getter)?;
Ok(())
diff --git a/crates/component-macro/tests/expanded/path2_async.rs b/crates/component-macro/tests/expanded/path2_async.rs
index 597c2d702e..5e456f30b1 100644
--- a/crates/component-macro/tests/expanded/path2_async.rs
+++ b/crates/component-macro/tests/expanded/path2_async.rs
@@ -169,7 +169,7 @@ const _: () = {
where
D: paths::path2::test::HostWithStore,
for<'a> D::Data<'a>: paths::path2::test::Host,
- T: 'static,
+ T: 'static + Send,
{
paths::path2::test::add_to_linker::<T, D>(linker, host_getter)?;
Ok(())
diff --git a/crates/component-macro/tests/expanded/path2_concurrent.rs b/crates/component-macro/tests/expanded/path2_concurrent.rs
index 597c2d702e..5e456f30b1 100644
--- a/crates/component-macro/tests/expanded/path2_concurrent.rs
+++ b/crates/component-macro/tests/expanded/path2_concurrent.rs
@@ -169,7 +169,7 @@ const _: () = {
where
D: paths::path2::test::HostWithStore,
for<'a> D::Data<'a>: paths::path2::test::Host,
- T: 'static,
+ T: 'static + Send,
{
paths::path2::test::add_to_linker::<T, D>(linker, host_getter)?;
Ok(())
diff --git a/crates/component-macro/tests/expanded/path2_tracing_async.rs b/crates/component-macro/tests/expanded/path2_tracing_async.rs
index 597c2d702e..5e456f30b1 100644
--- a/crates/component-macro/tests/expanded/path2_tracing_async.rs
+++ b/crates/component-macro/tests/expanded/path2_tracing_async.rs
@@ -169,7 +169,7 @@ const _: () = {
where
D: paths::path2::test::HostWithStore,
for<'a> D::Data<'a>: paths::path2::test::Host,
- T: 'static,
+ T: 'static + Send,
{
paths::path2::test::add_to_linker::<T, D>(linker, host_getter)?;
Ok(())
diff --git a/crates/component-macro/tests/expanded/worlds-with-types_async.rs b/crates/component-macro/tests/expanded/worlds-with-types_async.rs
index 43b074c640..b0a8916631 100644
--- a/crates/component-macro/tests/expanded/worlds-with-types_async.rs
+++ b/crates/component-macro/tests/expanded/worlds-with-types_async.rs
@@ -216,7 +216,7 @@ const _: () = {
where
D: foo::foo::i::HostWithStore,
for<'a> D::Data<'a>: foo::foo::i::Host,
- T: 'static,
+ T: 'static + Send,
{
foo::foo::i::add_to_linker::<T, D>(linker, host_getter)?;
Ok(())
diff --git a/crates/component-macro/tests/expanded/worlds-with-types_concurrent.rs b/crates/component-macro/tests/expanded/worlds-with-types_concurrent.rs
index a7df2c0915..29615ead42 100644
--- a/crates/component-macro/tests/expanded/worlds-with-types_concurrent.rs
+++ b/crates/component-macro/tests/expanded/worlds-with-types_concurrent.rs
@@ -216,7 +216,7 @@ const _: () = {
where
D: foo::foo::i::HostWithStore,
for<'a> D::Data<'a>: foo::foo::i::Host,
- T: 'static,
+ T: 'static + Send,
{
foo::foo::i::add_to_linker::<T, D>(linker, host_getter)?;
Ok(())
diff --git a/crates/component-macro/tests/expanded/worlds-with-types_tracing_async.rs b/crates/component-macro/tests/expanded/worlds-with-types_tracing_async.rs
index 91530ce5f8..074dd6c1d6 100644
--- a/crates/component-macro/tests/expanded/worlds-with-types_tracing_async.rs
+++ b/crates/component-macro/tests/expanded/worlds-with-types_tracing_async.rs
@@ -216,7 +216,7 @@ const _: () = {
where
D: foo::foo::i::HostWithStore,
for<'a> D::Data<'a>: foo::foo::i::Host,
- T: 'static,
+ T: 'static + Send,
{
foo::foo::i::add_to_linker::<T, D>(linker, host_getter)?;
Ok(())
diff --git a/crates/wit-bindgen/src/config.rs b/crates/wit-bindgen/src/config.rs
index 14d2745caf..dc5b966699 100644
--- a/crates/wit-bindgen/src/config.rs
+++ b/crates/wit-bindgen/src/config.rs
@@ -19,7 +19,7 @@ bitflags::bitflags! {
#[derive(Default, Debug, Clone)]
pub struct FunctionConfig {
rules: Vec<FunctionRule>,
- default: FunctionFlags,
+ pub(crate) default: FunctionFlags,
}
#[derive(Debug, Clone)]
diff --git a/crates/wit-bindgen/src/lib.rs b/crates/wit-bindgen/src/lib.rs
index 655db17971..3ec5e6cc14 100644
--- a/crates/wit-bindgen/src/lib.rs
+++ b/crates/wit-bindgen/src/lib.rs
@@ -1395,6 +1395,9 @@ impl Wasmtime {
all_func_flags |= i.all_func_flags;
}
+ all_func_flags |= self.opts.imports.default;
+ all_func_flags |= self.opts.exports.default;
+
let opt_t_send_bound =
if all_func_flags.contains(FunctionFlags::ASYNC) || self.opts.require_store_data_send {
"+ Send"