rust-bindgen
rust-bindgen copied to clipboard
Constant generation for my project broken by PR #3288
Constant generation for my project got broken by PR #3288. I can't copy-paste a repro directly because of closed source blah blah blah, will try to get a minimal repro and post it here in the next week or so. But the general pattern looks like this:
- We have some proprietary C headers and we're running bindgen to generate rust bindings to them
- Headers have constants like
#define FooBar 0x00000000 - Expectation: bindgen should create a constant like
pub const FooBar: u32 = 0;. Bindgen actually does that prior to #3288 - Post #3288, bindgen creates this:
pub const FooBar: u32 = u32(0); - This fails to compile with the error:
error[E0423]: expected function, found builtin typeu32`` - We're using bindgen as a library, calling it from
build.rs
Here is the essence of our bindgen config (I tried to remove non-relevant stuff):
let mut builder = bindgen::Builder::default()
.derive_default(true)
.prepend_enum_name(false)
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.default_enum_style(bindgen::EnumVariation::NewType {
is_bitfield: false,
is_global: false,
})
.default_alias_style(bindgen::AliasVariation::NewType)
.generate_cstr(true)
.no_copy("xxx") // in reality a bunch of regexes
.type_alias("yyy") // in reality a bunch of regexes
.merge_extern_blocks(true)
.derive_debug(false)
.impl_debug(false)
.parse_callbacks(Box::new(AddDerivesCallbacks::new())); // these callbacks just add some traits to certain types based on regexes
cc @maurer, seems like a bad interaction between default_alias_style and default_enum_style.
A minimal repro would be awesome if you can pull it off, I suspect it's not all that complicated given the OP