Skip to content

Commit c8b4006

Browse files
committed
fix(rs-bindgen): workaround the async Send compiler bug
fix rust-lang/rust#96865 in bindgen Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
1 parent 38be7d1 commit c8b4006

File tree

6 files changed

+46
-27
lines changed

6 files changed

+46
-27
lines changed

Diff for: Cargo.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ wasmtime = { version = "22", default-features = false }
128128
wasmtime-wasi = { version = "22", default-features = false }
129129
wit-bindgen = { version = "0.27", default-features = false }
130130
wit-bindgen-core = { version = "0.27", default-features = false }
131-
wit-bindgen-wrpc = { version = "0.4.2", default-features = false, path = "./crates/wit-bindgen" }
131+
wit-bindgen-wrpc = { version = "0.4.3", default-features = false, path = "./crates/wit-bindgen" }
132132
wit-bindgen-wrpc-go = { version = "0.2", default-features = false, path = "./crates/wit-bindgen-go" }
133-
wit-bindgen-wrpc-rust = { version = "0.4.2", default-features = false, path = "./crates/wit-bindgen-rust" }
134-
wit-bindgen-wrpc-rust-macro = { version = "0.4.2", default-features = false, path = "./crates/wit-bindgen-rust-macro" }
133+
wit-bindgen-wrpc-rust = { version = "0.4.3", default-features = false, path = "./crates/wit-bindgen-rust" }
134+
wit-bindgen-wrpc-rust-macro = { version = "0.4.3", default-features = false, path = "./crates/wit-bindgen-rust-macro" }
135135
wit-component = { version = "0.212", default-features = false }
136136
wit-parser = { version = "0.212", default-features = false }
137137
wrpc-cli = { version = "0.2", path = "./crates/cli", default-features = false }

Diff for: crates/wit-bindgen-rust-macro/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "wit-bindgen-wrpc-rust-macro"
3-
version = "0.4.2"
3+
version = "0.4.3"
44
description = """
55
Procedural macro paired with the `wit-bindgen-wrpc` crate.
66
"""

Diff for: crates/wit-bindgen-rust/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "wit-bindgen-wrpc-rust"
3-
version = "0.4.2"
3+
version = "0.4.3"
44
description = """
55
Rust bindings generator for wRPC, typically used through
66
the `wit-bindgen-wrpc` crate's `generate!` macro.

Diff for: crates/wit-bindgen-rust/src/interface.rs

+37-18
Original file line numberDiff line numberDiff line change
@@ -536,10 +536,16 @@ pub async fn serve_interface<T: {wrpc_transport}::Serve, U>(
536536
let params = self.print_docs_and_params(func, &sig);
537537
match func.results.iter_types().collect::<Vec<_>>().as_slice() {
538538
[] => {
539-
uwrite!(self.src, " -> {anyhow}::Result<()>",);
539+
uwrite!(
540+
self.src,
541+
" -> impl ::core::future::Future<Output = {anyhow}::Result<()>> + Send + 'a"
542+
);
540543
}
541544
[ty] => {
542-
uwrite!(self.src, " -> {anyhow}::Result<",);
545+
uwrite!(
546+
self.src,
547+
" -> impl ::core::future::Future<Output = {anyhow}::Result<"
548+
);
543549
if async_params || !paths.is_empty() {
544550
self.push_str("(");
545551
}
@@ -551,10 +557,13 @@ pub async fn serve_interface<T: {wrpc_transport}::Serve, U>(
551557
wrpc_transport = self.gen.wrpc_transport_path(),
552558
);
553559
}
554-
uwrite!(self.src, ">");
560+
uwrite!(self.src, ">> + Send + 'a");
555561
}
556562
types => {
557-
uwrite!(self.src, " -> {anyhow}::Result<(",);
563+
uwrite!(
564+
self.src,
565+
" -> impl ::core::future::Future<Output = {anyhow}::Result<(",
566+
);
558567
for ty in types {
559568
self.print_ty(ty, true, false);
560569
self.push_str(", ");
@@ -566,17 +575,23 @@ pub async fn serve_interface<T: {wrpc_transport}::Serve, U>(
566575
wrpc_transport = self.gen.wrpc_transport_path(),
567576
);
568577
}
569-
uwrite!(self.src, ")>");
578+
uwrite!(self.src, ")>> + Send + 'a");
570579
}
571580
};
572-
self.src.push_str("{\n");
581+
self.push_str(
582+
r"
583+
{
584+
async move {",
585+
);
573586

574587
if func.results.len() == 0 || (!async_params && paths.is_empty()) {
575588
uwrite!(
576589
self.src,
577-
r#"let wrpc__ = {anyhow}::Context::context(
578-
wrpc__.invoke_values_blocking(cx__, "{instance}", "{}", ({params}), "#,
590+
r#"
591+
let wrpc__ = {anyhow}::Context::context(
592+
{wrpc_transport}::SendFuture::send(wrpc__.invoke_values_blocking(cx__, "{instance}", "{}", ({params}), "#,
579593
rpc_func_name(func),
594+
wrpc_transport = self.gen.wrpc_transport_path(),
580595
params = {
581596
let s = params.join(", ");
582597
if params.len() == 1 {
@@ -595,11 +610,11 @@ pub async fn serve_interface<T: {wrpc_transport}::Serve, U>(
595610
self.src.push_str(".as_slice(), ");
596611
}
597612
}
598-
self.src.push_str("]).await,\n");
613+
self.src.push_str("])).await,\n");
599614
uwriteln!(
600615
self.src,
601616
r#"
602-
"failed to invoke `{instance}.{}`")?;"#,
617+
"failed to invoke `{instance}.{}`")?;"#,
603618
func.name,
604619
);
605620
if func.results.len() == 1 {
@@ -609,9 +624,11 @@ pub async fn serve_interface<T: {wrpc_transport}::Serve, U>(
609624
} else {
610625
uwrite!(
611626
self.src,
612-
r#"let (wrpc__, io__) = {anyhow}::Context::context(
613-
wrpc__.invoke_values(cx__, "{instance}", "{}", ({params}), "#,
627+
r#"
628+
let (wrpc__, io__) = {anyhow}::Context::context(
629+
{wrpc_transport}::SendFuture::send(wrpc__.invoke_values(cx__, "{instance}", "{}", ({params}), "#,
614630
rpc_func_name(func),
631+
wrpc_transport = self.gen.wrpc_transport_path(),
615632
params = {
616633
let s = params.join(", ");
617634
if params.len() == 1 {
@@ -630,11 +647,11 @@ pub async fn serve_interface<T: {wrpc_transport}::Serve, U>(
630647
self.src.push_str(".as_slice(), ");
631648
}
632649
}
633-
self.src.push_str("]).await,\n");
650+
self.src.push_str("])).await,\n");
634651
uwriteln!(
635652
self.src,
636653
r#"
637-
"failed to invoke `{instance}.{}`")?;"#,
654+
"failed to invoke `{instance}.{}`")?;"#,
638655
func.name,
639656
);
640657
if func.results.len() == 1 {
@@ -653,7 +670,12 @@ pub async fn serve_interface<T: {wrpc_transport}::Serve, U>(
653670
self.push_str("io__))\n");
654671
}
655672
}
656-
self.push_str("}\n");
673+
uwriteln!(
674+
self.src,
675+
r"
676+
}}
677+
}}"
678+
);
657679

658680
match func.kind {
659681
FunctionKind::Freestanding => {}
@@ -723,9 +745,6 @@ pub async fn serve_interface<T: {wrpc_transport}::Serve, U>(
723745
if !sig.private {
724746
self.push_str("pub ");
725747
}
726-
if self.in_import {
727-
self.push_str("async ");
728-
}
729748
self.push_str("fn ");
730749
if sig.use_item_name {
731750
if let FunctionKind::Constructor(_) = &func.kind {

Diff for: crates/wit-bindgen/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "wit-bindgen-wrpc"
3-
version = "0.4.2"
3+
version = "0.4.3"
44
description = """
55
Rust bindings generator for wRPC.
66
"""

0 commit comments

Comments
 (0)