rust-lang / rust-lang/rust-bindgen

Bindgen fails to generate constants if `#define`s are out of order

Open
#2,597 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

Input C/C++ Header
#define A B
#define B 1
Bindgen Invocation
bindgen input.h
Actual Results
/* automatically generated by rust-bindgen 0.66.1 */

pub const B: u32 = 1;
Expected Results

I expected

pub const A: u32 = 1;
pub const B: u32 = 1;

Both gcc and clang accept these kind of "out of order" definitions (as counter-intuitive as it is), and the linux kernel makes use of this in kvm.h, which is how we discovered this issue in https://github.com/rust-vmm/kvm-bindings/pull/89

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the reported bindgen input.h reproduction with the out-of-order #defines and trace how constants are generated. Done means the generated Rust output includes both A and B with the value 1, rather than omitting A.

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
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.