-
Notifications
You must be signed in to change notification settings - Fork 698
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
Tagged unions inside template fail to build. #2157
Comments
I'm still getting this error (exactly the same as above except for the line number), even with the latest bindgen ( let bindings = bindgen::Builder::default()
.rust_target(RustTarget::Stable_1_47)
.no_convert_floats()
.enable_cxx_namespaces()
.allowlist_type("YG.*")
.allowlist_function("YG.*")
.allowlist_var("YG.*")
.layout_tests(false)
.rustfmt_bindings(true)
.rustified_enum("YG.*")
.manually_drop_union(".*")
.default_non_copy_union_style(NonCopyUnionStyle::ManuallyDrop)
.header("src/wrapper.hpp")
.generate()
.expect("Unable to generate bindings"); https://github.com/nicoburns/yoga-rs/blob/8b0550e1f2615fa44d8f9af9891e0d4d26042080/build.rs Does anyone have any idea what could be causing this? It builds fine for me locally on macOS (aarch64), but it fails with this error on CI running on Ubuntu 20.04 (but with Rust 1.65 installed via Rustup). |
Ok, so I'm not quite sure why this happens, but the issue seems to be caused by linking against The offending generated code (which rustc won't compile) is: #[repr(C)]
pub union vector__Temporary_value__Storage<_Tp> {
pub _M_byte: ::std::os::raw::c_uchar,
pub _M_val: _Tp,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<_Tp>>,
} This is generated even with:
both set. Which looks like a bug to me (although I'm not knowledgable enough about bindgen to be sure). I have also included the full generated bindings (from the yoga-rs project) below in case they are helpful: Full generated bindings (click to expand)
|
I have the same issue on my It does indeed go away if I link against |
Yes, and I would add that there is an objective reason to want to do this, which is that the docs.rs build image doesn't include the |
Bummer, it does indeed. I just published an update to my crate and the docs are missing. Doh! |
Any update on this? On |
Hi. I made up small PR to avoid this issue, as we've been in trouble for boncheolgu/tflite-rs#58 I have no background regarding bindgen codebase at all, so the fix is very likely to go wrong way (any other side effect) as I just tracked problematic stacktrace and pinpointed this very specific problem. My purpose is to attract attention to fix this old irritating issue and create an entry point PR to fix ultimately, so any guidance would be appreciated, I'm happily following it. |
It's not an exact solution, but after trying several approaches, I added ManuallyDrop. However, I haven't been able to add <_Tp, _Alloc> yet. ./target/debug/bindgen \
input.hpp \
--manually-drop-union ".*" \
--no-derive-copy \ /* automatically generated by rust-bindgen 0.69.4 */
#[repr(C)]
#[derive(Debug)]
pub struct _Vector_base {
pub _address: u8,
}
#[repr(C)]
pub union _Vector_base__Storage<_Tp> {
pub _M_byte: ::std::mem::ManuallyDrop<::std::os::raw::c_uchar>,
pub _M_val: ::std::mem::ManuallyDrop<_Tp>,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<_Tp>>,
} The first block of code is a shell command that runs the The second block of code is Rust code that defines two data structures:
The code is automatically generated by the |
* fix: workaround bindgen bug (rust-lang/rust-bindgen#2157) * lint. * fix: `slice::from_raw_parts(null(), 0)` is UB. --------- Co-authored-by: Sanguk Park <[email protected]>
This is sort of a rustc limitation, but we could try to detect it better.
Input C/C++ Header
Bindgen Invocation
Actual Results
and/or
Expected Results
We should probably generate non-rust unions in this case, or add
ManuallyDrop
around all the types in a union or something like that.The text was updated successfully, but these errors were encountered: