Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(tests): enable prototyping tests #14

Merged
Merged
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
721 changes: 721 additions & 0 deletions .github/workflows/wasip3-prototyping.yml

Large diffs are not rendered by default.

124 changes: 36 additions & 88 deletions crates/component-macro/tests/expanded/char_concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<_T> TheWorldPre<_T> {
mut store: impl wasmtime::AsContextMut<Data = _T>,
) -> wasmtime::Result<TheWorld>
where
_T: Send + 'static,
_T: Send,
{
let mut store = store.as_context_mut();
let instance = self.instance_pre.instantiate_async(&mut store).await?;
Expand Down Expand Up @@ -157,7 +157,7 @@ const _: () = {
linker: &wasmtime::component::Linker<_T>,
) -> wasmtime::Result<TheWorld>
where
_T: Send + 'static,
_T: Send,
{
let pre = linker.instantiate_pre(component)?;
TheWorldPre::new(pre)?.instantiate_async(store).await
Expand Down Expand Up @@ -193,27 +193,20 @@ pub mod foo {
pub mod chars {
#[allow(unused_imports)]
use wasmtime::component::__internal::{anyhow, Box};
pub trait Host {
#[wasmtime::component::__internal::trait_variant_make(::core::marker::Send)]
pub trait Host: Send {
type Data;
/// A function that accepts a character
fn take_char(
store: wasmtime::StoreContextMut<'_, Self::Data>,
accessor: &mut wasmtime::component::Accessor<Self::Data>,
x: char,
) -> impl ::core::future::Future<
Output = impl FnOnce(
wasmtime::StoreContextMut<'_, Self::Data>,
) -> () + Send + Sync + 'static,
> + Send + Sync + 'static
) -> impl ::core::future::Future<Output = ()> + Send + Sync
where
Self: Sized;
/// A function that returns a character
fn return_char(
store: wasmtime::StoreContextMut<'_, Self::Data>,
) -> impl ::core::future::Future<
Output = impl FnOnce(
wasmtime::StoreContextMut<'_, Self::Data>,
) -> char + Send + Sync + 'static,
> + Send + Sync + 'static
accessor: &mut wasmtime::component::Accessor<Self::Data>,
) -> impl ::core::future::Future<Output = char> + Send + Sync
where
Self: Sized;
}
Expand Down Expand Up @@ -247,61 +240,30 @@ pub mod foo {
mut caller: wasmtime::StoreContextMut<'_, T>,
(arg0,): (char,)|
{
let host = caller;
let r = <G::Host as Host>::take_char(host, arg0);
Box::pin(async move {
let fun = r.await;
Box::new(move |mut caller: wasmtime::StoreContextMut<'_, T>| {
let r = fun(caller);
Ok(r)
})
as Box<
dyn FnOnce(
wasmtime::StoreContextMut<'_, T>,
) -> wasmtime::Result<()> + Send + Sync,
>
let mut accessor = unsafe {
wasmtime::component::Accessor::new(
caller.traitobj().as_ptr(),
)
};
wasmtime::component::__internal::Box::pin(async move {
let r = <G::Host as Host>::take_char(&mut accessor, arg0)
.await;
Ok(r)
})
as ::core::pin::Pin<
Box<
dyn ::core::future::Future<
Output = Box<
dyn FnOnce(
wasmtime::StoreContextMut<'_, T>,
) -> wasmtime::Result<()> + Send + Sync,
>,
> + Send + Sync + 'static,
>,
>
},
)?;
inst.func_wrap_concurrent(
"return-char",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
let host = caller;
let r = <G::Host as Host>::return_char(host);
Box::pin(async move {
let fun = r.await;
Box::new(move |mut caller: wasmtime::StoreContextMut<'_, T>| {
let r = fun(caller);
Ok((r,))
})
as Box<
dyn FnOnce(
wasmtime::StoreContextMut<'_, T>,
) -> wasmtime::Result<(char,)> + Send + Sync,
>
let mut accessor = unsafe {
wasmtime::component::Accessor::new(
caller.traitobj().as_ptr(),
)
};
wasmtime::component::__internal::Box::pin(async move {
let r = <G::Host as Host>::return_char(&mut accessor).await;
Ok((r,))
})
as ::core::pin::Pin<
Box<
dyn ::core::future::Future<
Output = Box<
dyn FnOnce(
wasmtime::StoreContextMut<'_, T>,
) -> wasmtime::Result<(char,)> + Send + Sync,
>,
> + Send + Sync + 'static,
>,
>
},
)?;
Ok(())
Expand All @@ -316,34 +278,20 @@ pub mod foo {
{
add_to_linker_get_host(linker, get)
}
impl<_T: Host> Host for &mut _T {
impl<_T: Host + Send> Host for &mut _T {
type Data = _T::Data;
/// A function that accepts a character
fn take_char(
store: wasmtime::StoreContextMut<'_, Self::Data>,
async fn take_char(
accessor: &mut wasmtime::component::Accessor<Self::Data>,
x: char,
) -> impl ::core::future::Future<
Output = impl FnOnce(
wasmtime::StoreContextMut<'_, Self::Data>,
) -> () + Send + Sync + 'static,
> + Send + Sync + 'static
where
Self: Sized,
{
<_T as Host>::take_char(store, x)
) -> () {
<_T as Host>::take_char(accessor, x).await
}
/// A function that returns a character
fn return_char(
store: wasmtime::StoreContextMut<'_, Self::Data>,
) -> impl ::core::future::Future<
Output = impl FnOnce(
wasmtime::StoreContextMut<'_, Self::Data>,
) -> char + Send + Sync + 'static,
> + Send + Sync + 'static
where
Self: Sized,
{
<_T as Host>::return_char(store)
async fn return_char(
accessor: &mut wasmtime::component::Accessor<Self::Data>,
) -> char {
<_T as Host>::return_char(accessor).await
}
}
}
Expand Down Expand Up @@ -453,7 +401,7 @@ pub mod exports {
arg0: char,
) -> wasmtime::Result<wasmtime::component::Promise<()>>
where
<S as wasmtime::AsContext>::Data: Send + 'static,
<S as wasmtime::AsContext>::Data: Send,
{
let callee = unsafe {
wasmtime::component::TypedFunc::<
Expand All @@ -472,7 +420,7 @@ pub mod exports {
mut store: S,
) -> wasmtime::Result<wasmtime::component::Promise<char>>
where
<S as wasmtime::AsContext>::Data: Send + 'static,
<S as wasmtime::AsContext>::Data: Send,
{
let callee = unsafe {
wasmtime::component::TypedFunc::<
Expand Down
Loading