From 559444cc66c787327c49e97b08ec88d96bdc9996 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 30 Mar 2026 09:57:08 -0700 Subject: [PATCH] Relax std::is_default_constructible_v requirement for C9Co Crubit ABIs Currently, `c9::internal::rust::EncodeResultInCrubitBuffer` requires the Crubit ABI type to be default constructible. This breaks for complex ABI types like `rs_std::DynCallable` which requires initialization arguments. This change delegates the ABI instantiation to the caller (either the Rust binding generator or the `CoCrubitAbi` fallback constructor). Because some ABI types are not "structural types" in C++20 and cannot be used as template arguments directly, we pass a closure type (`AbiFactory`) to `StartCoroutineFromRust` that constructs the ABI upon invocation. PiperOrigin-RevId: 891772056 --- rs_bindings_from_cc/generate_bindings/lib.rs | 23 +++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/rs_bindings_from_cc/generate_bindings/lib.rs b/rs_bindings_from_cc/generate_bindings/lib.rs index b6cbaa1c8..f3fd23c3c 100644 --- a/rs_bindings_from_cc/generate_bindings/lib.rs +++ b/rs_bindings_from_cc/generate_bindings/lib.rs @@ -1188,9 +1188,26 @@ fn crubit_abi_type(db: &BindingsGenerator, rs_type_kind: RsTypeKind) -> Result { + quote! { + &::c9::internal::rust::StartCoroutineFromRust + } + } + Some(result_type_crubit_abi_type) => { + let abi_expr_tokens = + CrubitAbiTypeToCppExprTokens(result_type_crubit_abi_type); + + quote! { + &::c9::internal::rust::StartCoroutineFromRust<[]() { return #abi_expr_tokens; }> + } + } + }; + quote! { + #cpp_type_tokens(#start_coroutine_fn_tokens) + } + }; Ok(CrubitAbiType::C9Co { rust_type_tokens,