rust-lang / rust-lang/rust-bindgen
`clang_macro_fallback()` silently skipped when using `header_contents()`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 829
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 15
Description
clang_macro_fallback() silently produces no output when headers are provided via header_contents() instead of header().
try_ensure_fallback_translation_unit() in bindgen/ir/context.rs only checks input_headers (populated by .header()). When the user uses .header_contents() instead, input_headers is empty, the slice pattern match fails, and the function returns None. No error, no warning — the fallback is silently skipped for every macro.
Additionally, Builder::generate() uses std::mem::take() on input_header_contents before passing options to Bindings::generate(), so even if the fallback code checked input_header_contents, it would find it empty.
Reproduction:
let bindings = bindgen::Builder::default()
.header_contents("wrapper.h", r#"
#define UINT32_C(c) c ## U
#define MY_CONST UINT32_C(42)
"#)
.clang_macro_fallback()
.generate()
.unwrap();
// MY_CONST is silently missing from the output
Impact: Common in build scripts that construct wrapper headers dynamically rather than writing them to disk. The user gets no constants from function-like macro invocations (e.g. UINT32_C, _IOR, _IOW) with no indication anything went wrong.
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 in bindgen/ir/context.rs at try_ensure_fallback_translation_unit(), then inspect Builder::generate() where input_header_contents is taken before options are passed to Bindings::generate(). Reproduce the header_contents() example and add or update a regression test; done means clang_macro_fallback() emits MY_CONST for dynamically supplied headers.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100