Skip to content

Commit d23e8e3

Browse files
committed
fix(bindgen): futures and stream are not Clone
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
1 parent 92f1829 commit d23e8e3

File tree

6 files changed

+362
-2
lines changed

6 files changed

+362
-2
lines changed

crates/component-macro/tests/codegen/records.wit

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ interface records {
5353
type int-typedef = s32;
5454
type tuple-typedef2 = tuple<int-typedef>;
5555
typedef-inout: func(e: tuple-typedef2) -> s32;
56+
57+
record futures-and-streams {
58+
a: future<u8>,
59+
b: stream<u8>,
60+
c: stream<future<stream>>,
61+
d: future<stream<future>>,
62+
}
5663
}
5764

5865
world the-world {

crates/component-macro/tests/expanded/records.rs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,48 @@ pub mod foo {
346346
4 == < TupleTypedef2 as wasmtime::component::ComponentType >::ALIGN32
347347
);
348348
};
349+
#[derive(wasmtime::component::ComponentType)]
350+
#[derive(wasmtime::component::Lift)]
351+
#[derive(wasmtime::component::Lower)]
352+
#[component(record)]
353+
pub struct FuturesAndStreams {
354+
#[component(name = "a")]
355+
pub a: wasmtime::component::FutureReader<u8>,
356+
#[component(name = "b")]
357+
pub b: wasmtime::component::StreamReader<u8>,
358+
#[component(name = "c")]
359+
pub c: wasmtime::component::StreamReader<
360+
wasmtime::component::FutureReader<
361+
wasmtime::component::StreamReader<()>,
362+
>,
363+
>,
364+
#[component(name = "d")]
365+
pub d: wasmtime::component::FutureReader<
366+
wasmtime::component::StreamReader<
367+
wasmtime::component::FutureReader<()>,
368+
>,
369+
>,
370+
}
371+
impl core::fmt::Debug for FuturesAndStreams {
372+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
373+
f.debug_struct("FuturesAndStreams")
374+
.field("a", &self.a)
375+
.field("b", &self.b)
376+
.field("c", &self.c)
377+
.field("d", &self.d)
378+
.finish()
379+
}
380+
}
381+
const _: () = {
382+
assert!(
383+
16 == < FuturesAndStreams as wasmtime::component::ComponentType
384+
>::SIZE32
385+
);
386+
assert!(
387+
4 == < FuturesAndStreams as wasmtime::component::ComponentType
388+
>::ALIGN32
389+
);
390+
};
349391
pub trait HostWithStore: wasmtime::component::HasData {}
350392
impl<_T: ?Sized> HostWithStore for _T
351393
where
@@ -711,6 +753,51 @@ pub mod exports {
711753
>::ALIGN32
712754
);
713755
};
756+
#[derive(wasmtime::component::ComponentType)]
757+
#[derive(wasmtime::component::Lift)]
758+
#[derive(wasmtime::component::Lower)]
759+
#[component(record)]
760+
pub struct FuturesAndStreams {
761+
#[component(name = "a")]
762+
pub a: wasmtime::component::FutureReader<u8>,
763+
#[component(name = "b")]
764+
pub b: wasmtime::component::StreamReader<u8>,
765+
#[component(name = "c")]
766+
pub c: wasmtime::component::StreamReader<
767+
wasmtime::component::FutureReader<
768+
wasmtime::component::StreamReader<()>,
769+
>,
770+
>,
771+
#[component(name = "d")]
772+
pub d: wasmtime::component::FutureReader<
773+
wasmtime::component::StreamReader<
774+
wasmtime::component::FutureReader<()>,
775+
>,
776+
>,
777+
}
778+
impl core::fmt::Debug for FuturesAndStreams {
779+
fn fmt(
780+
&self,
781+
f: &mut core::fmt::Formatter<'_>,
782+
) -> core::fmt::Result {
783+
f.debug_struct("FuturesAndStreams")
784+
.field("a", &self.a)
785+
.field("b", &self.b)
786+
.field("c", &self.c)
787+
.field("d", &self.d)
788+
.finish()
789+
}
790+
}
791+
const _: () = {
792+
assert!(
793+
16 == < FuturesAndStreams as wasmtime::component::ComponentType
794+
>::SIZE32
795+
);
796+
assert!(
797+
4 == < FuturesAndStreams as wasmtime::component::ComponentType
798+
>::ALIGN32
799+
);
800+
};
714801
#[derive(Clone)]
715802
pub struct Guest {
716803
tuple_arg: wasmtime::component::Func,

crates/component-macro/tests/expanded/records_async.rs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,48 @@ pub mod foo {
346346
4 == < TupleTypedef2 as wasmtime::component::ComponentType >::ALIGN32
347347
);
348348
};
349+
#[derive(wasmtime::component::ComponentType)]
350+
#[derive(wasmtime::component::Lift)]
351+
#[derive(wasmtime::component::Lower)]
352+
#[component(record)]
353+
pub struct FuturesAndStreams {
354+
#[component(name = "a")]
355+
pub a: wasmtime::component::FutureReader<u8>,
356+
#[component(name = "b")]
357+
pub b: wasmtime::component::StreamReader<u8>,
358+
#[component(name = "c")]
359+
pub c: wasmtime::component::StreamReader<
360+
wasmtime::component::FutureReader<
361+
wasmtime::component::StreamReader<()>,
362+
>,
363+
>,
364+
#[component(name = "d")]
365+
pub d: wasmtime::component::FutureReader<
366+
wasmtime::component::StreamReader<
367+
wasmtime::component::FutureReader<()>,
368+
>,
369+
>,
370+
}
371+
impl core::fmt::Debug for FuturesAndStreams {
372+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
373+
f.debug_struct("FuturesAndStreams")
374+
.field("a", &self.a)
375+
.field("b", &self.b)
376+
.field("c", &self.c)
377+
.field("d", &self.d)
378+
.finish()
379+
}
380+
}
381+
const _: () = {
382+
assert!(
383+
16 == < FuturesAndStreams as wasmtime::component::ComponentType
384+
>::SIZE32
385+
);
386+
assert!(
387+
4 == < FuturesAndStreams as wasmtime::component::ComponentType
388+
>::ALIGN32
389+
);
390+
};
349391
pub trait HostWithStore: wasmtime::component::HasData + Send {}
350392
impl<_T: ?Sized> HostWithStore for _T
351393
where
@@ -789,6 +831,51 @@ pub mod exports {
789831
>::ALIGN32
790832
);
791833
};
834+
#[derive(wasmtime::component::ComponentType)]
835+
#[derive(wasmtime::component::Lift)]
836+
#[derive(wasmtime::component::Lower)]
837+
#[component(record)]
838+
pub struct FuturesAndStreams {
839+
#[component(name = "a")]
840+
pub a: wasmtime::component::FutureReader<u8>,
841+
#[component(name = "b")]
842+
pub b: wasmtime::component::StreamReader<u8>,
843+
#[component(name = "c")]
844+
pub c: wasmtime::component::StreamReader<
845+
wasmtime::component::FutureReader<
846+
wasmtime::component::StreamReader<()>,
847+
>,
848+
>,
849+
#[component(name = "d")]
850+
pub d: wasmtime::component::FutureReader<
851+
wasmtime::component::StreamReader<
852+
wasmtime::component::FutureReader<()>,
853+
>,
854+
>,
855+
}
856+
impl core::fmt::Debug for FuturesAndStreams {
857+
fn fmt(
858+
&self,
859+
f: &mut core::fmt::Formatter<'_>,
860+
) -> core::fmt::Result {
861+
f.debug_struct("FuturesAndStreams")
862+
.field("a", &self.a)
863+
.field("b", &self.b)
864+
.field("c", &self.c)
865+
.field("d", &self.d)
866+
.finish()
867+
}
868+
}
869+
const _: () = {
870+
assert!(
871+
16 == < FuturesAndStreams as wasmtime::component::ComponentType
872+
>::SIZE32
873+
);
874+
assert!(
875+
4 == < FuturesAndStreams as wasmtime::component::ComponentType
876+
>::ALIGN32
877+
);
878+
};
792879
#[derive(Clone)]
793880
pub struct Guest {
794881
tuple_arg: wasmtime::component::Func,

crates/component-macro/tests/expanded/records_concurrent.rs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,48 @@ pub mod foo {
346346
4 == < TupleTypedef2 as wasmtime::component::ComponentType >::ALIGN32
347347
);
348348
};
349+
#[derive(wasmtime::component::ComponentType)]
350+
#[derive(wasmtime::component::Lift)]
351+
#[derive(wasmtime::component::Lower)]
352+
#[component(record)]
353+
pub struct FuturesAndStreams {
354+
#[component(name = "a")]
355+
pub a: wasmtime::component::FutureReader<u8>,
356+
#[component(name = "b")]
357+
pub b: wasmtime::component::StreamReader<u8>,
358+
#[component(name = "c")]
359+
pub c: wasmtime::component::StreamReader<
360+
wasmtime::component::FutureReader<
361+
wasmtime::component::StreamReader<()>,
362+
>,
363+
>,
364+
#[component(name = "d")]
365+
pub d: wasmtime::component::FutureReader<
366+
wasmtime::component::StreamReader<
367+
wasmtime::component::FutureReader<()>,
368+
>,
369+
>,
370+
}
371+
impl core::fmt::Debug for FuturesAndStreams {
372+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
373+
f.debug_struct("FuturesAndStreams")
374+
.field("a", &self.a)
375+
.field("b", &self.b)
376+
.field("c", &self.c)
377+
.field("d", &self.d)
378+
.finish()
379+
}
380+
}
381+
const _: () = {
382+
assert!(
383+
16 == < FuturesAndStreams as wasmtime::component::ComponentType
384+
>::SIZE32
385+
);
386+
assert!(
387+
4 == < FuturesAndStreams as wasmtime::component::ComponentType
388+
>::ALIGN32
389+
);
390+
};
349391
pub trait HostWithStore: wasmtime::component::HasData + Send {
350392
fn tuple_arg<T: Send>(
351393
accessor: &wasmtime::component::Accessor<T, Self>,
@@ -722,6 +764,51 @@ pub mod exports {
722764
>::ALIGN32
723765
);
724766
};
767+
#[derive(wasmtime::component::ComponentType)]
768+
#[derive(wasmtime::component::Lift)]
769+
#[derive(wasmtime::component::Lower)]
770+
#[component(record)]
771+
pub struct FuturesAndStreams {
772+
#[component(name = "a")]
773+
pub a: wasmtime::component::FutureReader<u8>,
774+
#[component(name = "b")]
775+
pub b: wasmtime::component::StreamReader<u8>,
776+
#[component(name = "c")]
777+
pub c: wasmtime::component::StreamReader<
778+
wasmtime::component::FutureReader<
779+
wasmtime::component::StreamReader<()>,
780+
>,
781+
>,
782+
#[component(name = "d")]
783+
pub d: wasmtime::component::FutureReader<
784+
wasmtime::component::StreamReader<
785+
wasmtime::component::FutureReader<()>,
786+
>,
787+
>,
788+
}
789+
impl core::fmt::Debug for FuturesAndStreams {
790+
fn fmt(
791+
&self,
792+
f: &mut core::fmt::Formatter<'_>,
793+
) -> core::fmt::Result {
794+
f.debug_struct("FuturesAndStreams")
795+
.field("a", &self.a)
796+
.field("b", &self.b)
797+
.field("c", &self.c)
798+
.field("d", &self.d)
799+
.finish()
800+
}
801+
}
802+
const _: () = {
803+
assert!(
804+
16 == < FuturesAndStreams as wasmtime::component::ComponentType
805+
>::SIZE32
806+
);
807+
assert!(
808+
4 == < FuturesAndStreams as wasmtime::component::ComponentType
809+
>::ALIGN32
810+
);
811+
};
725812
#[derive(Clone)]
726813
pub struct Guest {
727814
tuple_arg: wasmtime::component::Func,

0 commit comments

Comments
 (0)