-
Notifications
You must be signed in to change notification settings - Fork 696
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
Attempt to correct wasm32 ABI in bindgen #1944
Comments
Consider: Rust:
C:
In this case, we need for the C/Rust ABI to match not just in what wasm-bindgen produces, but within native FFI calls from Rust to C (and vice versa?). I don't see how this can be done solely within wasm-bindgen. |
@briansmith as it says in the OP, bindgen would emit (or you would type) |
I see. I didn't realize that bindgen would rewrite the |
It was also pointed out that bindgen could emit something like this to "match" the c api better, though I'm personally not a fan. extern "C" {
#[link_name="foo_c"]
fn foo_c_inner(foo: &Foo);
}
extern "C" pub fn foo_c(foo: Foo) {
foo_c_inner(&foo)
} |
The main issue here is exposing different APIs to different targets being a bit annoying... The last comment "fixes" it, but not a fan either :) The OP could be made to work checking the type's layout quite easily, fwiw. We do have that information at that stage. |
By the way, shouldn't this more generally be considered a rustc bug? I'd expect |
Ah, I read through the rust PR now, sorry for the noise... So, I think I prefer to add an opt-in in bindgen to generate code like the one in #1944 (comment). I don't think it should be too invasive. |
@emilio are you available on something like discord or zulip for some implementation related questions? |
Sure, yeah. Zulip (either the rust-lang one or the servo one) or Element / Matrix ( |
So things that came up:
But the basic idea still stands, I think, which is generating a wrapper function that does the right thing. The right place to do this isn't the one in the OP ( A good place to put the hack is on the callers of So I'd expect
where
Then |
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:
The text was updated successfully, but these errors were encountered: