Description
So rust has this issue where it doesn't match the calling convention of clang when targeting wasm32. The only difference appears to be when passing large heterogeneous aggregate types, where clang will indirect the value but rustc will still pass it by value.
Hacking a fix together in rustc would be possible (see rust-lang/rust#79998), but it was proposed that as long as we are doing hacks, why not do the hack here in bindgen. In particular, when emitting fn foo(val: T)
, bindgen can instead emit &T
for the argument.
The relevant logic is present in rustc here (https://github.com/rust-lang/rust/blob/fa416394275d2468d104b8f72ac31b1ddf7ee52e/compiler/rustc_target/src/abi/call/wasm32.rs#L32-L41) but I'm not sure how I would port it to bindgen. I got this far at least to verify that the stragety works:
index 0d93c491..ee3c588d 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -3497,7 +3497,12 @@ impl TryToRustTy for Type {
{
Ok(ty)
} else {
- utils::build_path(item, ctx)
+ let path = utils::build_path(item, ctx)?;
+ if ctx.is_target_wasm32_not_emscripten() /* && check_size_here */ {
+ Ok(quote!(&#path))
+ } else {
+ Ok(path)
+ }
}
}
TypeKind::Comp(ref info) => {