Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
krukai opened this issue Jan 24, 2023 · 1 comment

Comments

@krukai
Copy link

krukai commented Jan 24, 2023

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;

@capickett
Copy link

capickett commented Sep 24, 2024

Another instance of this, although slightly different from the original report:

#ifndef FOO
#define FOO 456
#endif

Bindgen Invocation

$ bindgen input.h -- -DFOO=123

Actual

/* automatically generated by rust-bindgen 0.69.4 */


Expected

/* automatically generated by rust-bindgen 0.69.4 */

pub const FOO: u32 = 123;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants