Skip to content

Constant generation for my project broken by PR #3288 #3303

@ivmaykov

Description

@ivmaykov

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 codegen: Support new-type-alias constants #3288
  • Post codegen: Support new-type-alias constants #3288, bindgen creates this: pub const FooBar: u32 = u32(0);
  • This fails to compile with the error: error[E0423]: expected function, found builtin type u32``
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-bogus-codegenbugnext-releaseThis issue/PR should be solved/merged before doing a new release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions