rust-lang / rust-lang/rust-bindgen
How to avoid bindgen being out of sync with cc?
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 829
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 15
Description
My understanding is, that it is very common to wrap a C library in a Rust *-sys crate by using bindgen to automatically generate Rust bindings and cc to compile the C code.
As far as I understand it bindgen uses libclang to parse the C headers and cc uses whatever compiler the user provides.
This can lead to problems, because both toolchains don't need to agree on everything. While cross compiling for thumbv6m-none-eabi on Windows, bindgen generated u32 for enums and cc used u8 when possible (-fshort-enums).
This is quite unfortunate and hard to catch. Is there a common workaround for this?
PS: If there is a better place for this issue please tell me.
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
Review how bindgen uses libclang and how cc invokes the selected compiler during thumbv6m-none-eabi cross-compilation on Windows, focusing on enum widths and -fshort-enums. Done would be a documented, reproducible workaround or a project change that keeps generated Rust representations consistent with the compiled C ABI.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, rust
- Domain
- compilers, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100