rust-lang / rust-lang/rust-bindgen
Opaque structs not generating with right size
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 829
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 15
Description
Hello bindgen team! I am having some issues with bindings generated from Windows USB headers defined in ucxusbdevice.h. Here is a link to a minimal repro I've been able to generate: https://github.com/leon-xd/rust-repros/tree/main/crates/bindgen-size-overflow. I copied relevant definitions and made a new header file that is able to reproduce the issue.
There are four structs that are not generated with the right definition. It seems like they are generated as opaque, but do not have the correct size. In switching from bindgen 0.69.* to 0.71.0 we were able to detect this issue with the introduction of compile time error checking.
A (preferably reduced) C/C++ header file that reproduces the issue
The bindgen flags used to reproduce the issue with the header file
Builder::default()is used here: https://github.com/leon-xd/rust-repros/blob/main/crates/bindgen-size-overflow/build.rs
The expected bindgen output
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _USBDEVICE_ABORTIO {
pub _address: _USBDEVICE_MGMT_HEADER,
}
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
["Size of _USBDEVICE_ABORTIO"][::std::mem::size_of::<_USBDEVICE_ABORTIO>() - 24usize];
["Alignment of _USBDEVICE_ABORTIO"][::std::mem::align_of::<_USBDEVICE_ABORTIO>() - 8usize];
};
The actual bindgen output
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _USBDEVICE_ABORTIO {
pub _address: u8,
}
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
["Size of _USBDEVICE_ABORTIO"][::std::mem::size_of::<_USBDEVICE_ABORTIO>() - 24usize];
["Alignment of _USBDEVICE_ABORTIO"][::std::mem::align_of::<_USBDEVICE_ABORTIO>() - 8usize];
};
The debugging logs generated when running bindgen on this testcase
- The output of cargo build -vvv is here: logs.txt
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal reproduction's src/header.h and build.rs, then run the documented bindgen debug command using cargo build -vvv and inspect logs.txt. Compare the generated definitions for the four opaque structs with the expected size and alignment; done means the generated bindings compile with the expected layout checks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, cpp, rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100