rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

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

Open roypat opened this issue 2 years ago • 2 comments

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

roypat avatar Aug 03 '23 15:08 roypat

I think https://github.com/rust-lang/rust-bindgen/pull/2561 doesn't strictly fix this but it is a step in that direction iiuc (cc @reitermarkus).

If that's the case maybe this is a good enough reason to do this change, what do you think @emilio?

pvdrz avatar Aug 08 '23 16:08 pvdrz

No, https://github.com/rust-lang/rust-bindgen/pull/2561 doesn't fix this, but https://github.com/rust-lang/rust-bindgen/pull/2369 which depends on https://github.com/rust-lang/rust-bindgen/pull/2561 will fix it.

reitermarkus avatar Aug 15 '23 16:08 reitermarkus