You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am happily using bindgen to link Rust to a C++ library, and it works great... except when compiling for the MSVC target (that is i686-pc-windows-msvc or x86_64-pc-windows-msvc), that my program crashes badly with random exceptions.
I have reduced the faulty code to the code in this sample repo, ready to run:
There are two types, for reference, Ok works fine, Err fails. The only difference is the constructor, that IIUIC makes the type non-POD and changes the ABI.
The issue here is that in Rust there is no way to choose which one you want. When you write #[repr(C)] into a struct it will use the small or big ABI depending on the size of the type, not caring about the C++ pieces.
So a C++ struct with sizeof <= 8 and a constructor cannot be expressed as a FFI-to-MSVC type in current Rust.
I'm not sure what Bindgen should do here. The easiest solution would be just not to emit bindings for such a function. I've tried looking at the code, but came back empty handed...
I am happily using bindgen to link Rust to a C++ library, and it works great... except when compiling for the MSVC target (that is
i686-pc-windows-msvc
orx86_64-pc-windows-msvc
), that my program crashes badly with random exceptions.I have reduced the faulty code to the code in this sample repo, ready to run:
https://github.com/rodrigorc/testabi
Input C/C++ Header
There are two types, for reference,
Ok
works fine,Err
fails. The only difference is the constructor, that IIUIC makes the type non-POD and changes the ABI.Bindgen Invocation
It fails both with
clang
andmsvc
compilers.Actual Results
When running the program in windows, natively compiled, it prints garbage:
Or crashes with something like:
Or sometimes other less known exceptions. I reckon the stack is getting corrupted.
Expected Results
When cross compiling from Linux, or running natively on Linux, it prints the expected:
The text was updated successfully, but these errors were encountered: