Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions crates/component-macro/tests/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ macro_rules! gentest {
imports: { default: store },
});
}
mod with_anyhow {
wasmtime::component::bindgen!({
path: $path,
anyhow: true,
imports: { default: trappable },
});
}
}
};
}
Expand Down Expand Up @@ -785,3 +792,31 @@ mod import_async_interface {
});
}
}

mod anyhow_with_custom_error {
wasmtime::component::bindgen!({
inline: "
package foo:foo;

interface i {
enum error {
a,
b,
c
}
x: func() -> result<_, error>;
}

world foo {
import i;
}
",
anyhow: true,
imports: { default: trappable },
trappable_error_type: {
"foo:foo/i.error" => MyCustomError,
},
});

struct MyCustomError;
}
4 changes: 3 additions & 1 deletion crates/component-macro/tests/expanded/resources-export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ pub mod foo {
wasmtime::component::ResourceType::host::<Y>(),
move |mut store, rep| -> wasmtime::Result<()> {
let resource = wasmtime::component::Resource::new_own(rep);
HostY::drop(&mut host_getter(store.data_mut()), resource)
wasmtime::ToWasmtimeResult::to_wasmtime_result(
HostY::drop(&mut host_getter(store.data_mut()), resource),
)
},
)?;
Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,13 @@ pub mod foo {
wasmtime::component::ResourceType::host::<Y>(),
move |mut store, rep| {
wasmtime::component::__internal::Box::new(async move {
HostY::drop(
&mut host_getter(store.data_mut()),
wasmtime::component::Resource::new_own(rep),
)
.await
wasmtime::ToWasmtimeResult::to_wasmtime_result(
HostY::drop(
&mut host_getter(store.data_mut()),
wasmtime::component::Resource::new_own(rep),
)
.await,
)
})
},
)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,13 @@ pub mod foo {
move |caller: &wasmtime::component::Accessor<T>, rep| {
wasmtime::component::__internal::Box::pin(async move {
let accessor = &caller.with_getter(host_getter);
HostYWithStore::drop(
accessor,
wasmtime::component::Resource::new_own(rep),
)
.await
wasmtime::ToWasmtimeResult::to_wasmtime_result(
HostYWithStore::drop(
accessor,
wasmtime::component::Resource::new_own(rep),
)
.await,
)
})
},
)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,13 @@ pub mod foo {
wasmtime::component::ResourceType::host::<Y>(),
move |mut store, rep| {
wasmtime::component::__internal::Box::new(async move {
HostY::drop(
&mut host_getter(store.data_mut()),
wasmtime::component::Resource::new_own(rep),
)
.await
wasmtime::ToWasmtimeResult::to_wasmtime_result(
HostY::drop(
&mut host_getter(store.data_mut()),
wasmtime::component::Resource::new_own(rep),
)
.await,
)
})
},
)?;
Expand Down
27 changes: 20 additions & 7 deletions crates/component-macro/tests/expanded/resources-import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,11 @@ const _: () = {
wasmtime::component::ResourceType::host::<WorldResource>(),
move |mut store, rep| -> wasmtime::Result<()> {
let resource = wasmtime::component::Resource::new_own(rep);
HostWorldResource::drop(
&mut host_getter(store.data_mut()),
resource,
wasmtime::ToWasmtimeResult::to_wasmtime_result(
HostWorldResource::drop(
&mut host_getter(store.data_mut()),
resource,
),
)
},
)?;
Expand Down Expand Up @@ -678,15 +680,22 @@ pub mod foo {
wasmtime::component::ResourceType::host::<Bar>(),
move |mut store, rep| -> wasmtime::Result<()> {
let resource = wasmtime::component::Resource::new_own(rep);
HostBar::drop(&mut host_getter(store.data_mut()), resource)
wasmtime::ToWasmtimeResult::to_wasmtime_result(
HostBar::drop(&mut host_getter(store.data_mut()), resource),
)
},
)?;
inst.resource(
"fallible",
wasmtime::component::ResourceType::host::<Fallible>(),
move |mut store, rep| -> wasmtime::Result<()> {
let resource = wasmtime::component::Resource::new_own(rep);
HostFallible::drop(&mut host_getter(store.data_mut()), resource)
wasmtime::ToWasmtimeResult::to_wasmtime_result(
HostFallible::drop(
&mut host_getter(store.data_mut()),
resource,
),
)
},
)?;
inst.func_wrap(
Expand Down Expand Up @@ -976,7 +985,9 @@ pub mod foo {
wasmtime::component::ResourceType::host::<A>(),
move |mut store, rep| -> wasmtime::Result<()> {
let resource = wasmtime::component::Resource::new_own(rep);
HostA::drop(&mut host_getter(store.data_mut()), resource)
wasmtime::ToWasmtimeResult::to_wasmtime_result(
HostA::drop(&mut host_getter(store.data_mut()), resource),
)
},
)?;
Ok(())
Expand Down Expand Up @@ -1118,7 +1129,9 @@ pub mod foo {
wasmtime::component::ResourceType::host::<Foo>(),
move |mut store, rep| -> wasmtime::Result<()> {
let resource = wasmtime::component::Resource::new_own(rep);
HostFoo::drop(&mut host_getter(store.data_mut()), resource)
wasmtime::ToWasmtimeResult::to_wasmtime_result(
HostFoo::drop(&mut host_getter(store.data_mut()), resource),
)
},
)?;
Ok(())
Expand Down
60 changes: 35 additions & 25 deletions crates/component-macro/tests/expanded/resources-import_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,13 @@ const _: () = {
wasmtime::component::ResourceType::host::<WorldResource>(),
move |mut store, rep| {
wasmtime::component::__internal::Box::new(async move {
HostWorldResource::drop(
&mut host_getter(store.data_mut()),
wasmtime::component::Resource::new_own(rep),
)
.await
wasmtime::ToWasmtimeResult::to_wasmtime_result(
HostWorldResource::drop(
&mut host_getter(store.data_mut()),
wasmtime::component::Resource::new_own(rep),
)
.await,
)
})
},
)?;
Expand Down Expand Up @@ -789,11 +791,13 @@ pub mod foo {
wasmtime::component::ResourceType::host::<Bar>(),
move |mut store, rep| {
wasmtime::component::__internal::Box::new(async move {
HostBar::drop(
&mut host_getter(store.data_mut()),
wasmtime::component::Resource::new_own(rep),
)
.await
wasmtime::ToWasmtimeResult::to_wasmtime_result(
HostBar::drop(
&mut host_getter(store.data_mut()),
wasmtime::component::Resource::new_own(rep),
)
.await,
)
})
},
)?;
Expand All @@ -802,11 +806,13 @@ pub mod foo {
wasmtime::component::ResourceType::host::<Fallible>(),
move |mut store, rep| {
wasmtime::component::__internal::Box::new(async move {
HostFallible::drop(
&mut host_getter(store.data_mut()),
wasmtime::component::Resource::new_own(rep),
)
.await
wasmtime::ToWasmtimeResult::to_wasmtime_result(
HostFallible::drop(
&mut host_getter(store.data_mut()),
wasmtime::component::Resource::new_own(rep),
)
.await,
)
})
},
)?;
Expand Down Expand Up @@ -1143,11 +1149,13 @@ pub mod foo {
wasmtime::component::ResourceType::host::<A>(),
move |mut store, rep| {
wasmtime::component::__internal::Box::new(async move {
HostA::drop(
&mut host_getter(store.data_mut()),
wasmtime::component::Resource::new_own(rep),
)
.await
wasmtime::ToWasmtimeResult::to_wasmtime_result(
HostA::drop(
&mut host_getter(store.data_mut()),
wasmtime::component::Resource::new_own(rep),
)
.await,
)
})
},
)?;
Expand Down Expand Up @@ -1300,11 +1308,13 @@ pub mod foo {
wasmtime::component::ResourceType::host::<Foo>(),
move |mut store, rep| {
wasmtime::component::__internal::Box::new(async move {
HostFoo::drop(
&mut host_getter(store.data_mut()),
wasmtime::component::Resource::new_own(rep),
)
.await
wasmtime::ToWasmtimeResult::to_wasmtime_result(
HostFoo::drop(
&mut host_getter(store.data_mut()),
wasmtime::component::Resource::new_own(rep),
)
.await,
)
})
},
)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,13 @@ const _: () = {
move |caller: &wasmtime::component::Accessor<T>, rep| {
wasmtime::component::__internal::Box::pin(async move {
let accessor = &caller.with_getter(host_getter);
HostWorldResourceWithStore::drop(
accessor,
wasmtime::component::Resource::new_own(rep),
)
.await
wasmtime::ToWasmtimeResult::to_wasmtime_result(
HostWorldResourceWithStore::drop(
accessor,
wasmtime::component::Resource::new_own(rep),
)
.await,
)
})
},
)?;
Expand Down Expand Up @@ -586,11 +588,13 @@ pub mod foo {
move |caller: &wasmtime::component::Accessor<T>, rep| {
wasmtime::component::__internal::Box::pin(async move {
let accessor = &caller.with_getter(host_getter);
HostBarWithStore::drop(
accessor,
wasmtime::component::Resource::new_own(rep),
)
.await
wasmtime::ToWasmtimeResult::to_wasmtime_result(
HostBarWithStore::drop(
accessor,
wasmtime::component::Resource::new_own(rep),
)
.await,
)
})
},
)?;
Expand All @@ -600,11 +604,13 @@ pub mod foo {
move |caller: &wasmtime::component::Accessor<T>, rep| {
wasmtime::component::__internal::Box::pin(async move {
let accessor = &caller.with_getter(host_getter);
HostFallibleWithStore::drop(
accessor,
wasmtime::component::Resource::new_own(rep),
)
.await
wasmtime::ToWasmtimeResult::to_wasmtime_result(
HostFallibleWithStore::drop(
accessor,
wasmtime::component::Resource::new_own(rep),
)
.await,
)
})
},
)?;
Expand Down Expand Up @@ -947,11 +953,13 @@ pub mod foo {
move |caller: &wasmtime::component::Accessor<T>, rep| {
wasmtime::component::__internal::Box::pin(async move {
let accessor = &caller.with_getter(host_getter);
HostAWithStore::drop(
accessor,
wasmtime::component::Resource::new_own(rep),
)
.await
wasmtime::ToWasmtimeResult::to_wasmtime_result(
HostAWithStore::drop(
accessor,
wasmtime::component::Resource::new_own(rep),
)
.await,
)
})
},
)?;
Expand Down Expand Up @@ -1084,11 +1092,13 @@ pub mod foo {
move |caller: &wasmtime::component::Accessor<T>, rep| {
wasmtime::component::__internal::Box::pin(async move {
let accessor = &caller.with_getter(host_getter);
HostFooWithStore::drop(
accessor,
wasmtime::component::Resource::new_own(rep),
)
.await
wasmtime::ToWasmtimeResult::to_wasmtime_result(
HostFooWithStore::drop(
accessor,
wasmtime::component::Resource::new_own(rep),
)
.await,
)
})
},
)?;
Expand Down
Loading
Loading