Skip to content

Failure to evaluate #define directives if they use values from defines passed through clang args #2394

Open
@krukai

Description

@krukai

It seems that while bindgen respects preprocessor defines passed through clang for evaluating ifdefs, it does not consider them for processing #define directives.

While the obvious workaround (or rather perhaps, the preferred way) is to put these defines in a wrapper.h header instead of passing them as arguments to clang, I stumbled over this after thinking that I do not need a wapper.

Regardless, it might be a good idea to mention this in Create a wrapper.h Header.

Input C/C++ Header

#define FOO_A 7
#ifdef FOO_FROM_CLANG
#define FOO_B 3
#endif
#define FOO_C (FOO_FROM_CLANG)
#define FOO_D (FOO_FROM_CLANG + 1)

Bindgen Invocation

$ bindgen input.h -- -DFOO_FROM_CLANG=3

Actual Results

/* automatically generated by rust-bindgen 0.63.0 */

pub const FOO_A: u32 = 7;
pub const FOO_B: u32 = 3;

Expected Results

All defines based off defines provided through clang show up in the generated bindings:

/* automatically generated by rust-bindgen 0.63.0 */

pub const FOO_A: u32 = 7;
pub const FOO_B: u32 = 3;
pub const FOO_C: u32 = 7;
pub const FOO_D: u32 = 8;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions