Skip to content

--clang-macro-fallback interaction with -include #3069

New issue

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

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

Already on GitHub? # to your account

Closed
ojeda opened this issue Jan 8, 2025 · 2 comments · Fixed by #3072
Closed

--clang-macro-fallback interaction with -include #3069

ojeda opened this issue Jan 8, 2025 · 2 comments · Fixed by #3072
Labels
A-macros bug rust-for-linux Issues relevant to the Rust for Linux project

Comments

@ojeda
Copy link
Contributor

ojeda commented Jan 8, 2025

--clang-macro-fallback does not work if -include is passed as a C flag.

For instance, given a header that would benefit from --clang-macro-fallback, such as:

#define F(n) n
#define N F(4)

Then

bindgen x.h --clang-macro-fallback

generates the expected

pub const N: u32 = 4;

However, if we pass an -include flag, even with an empty C header, it does not anymore:

bindgen x.h --clang-macro-fallback -- -include empty.h

This was reduced from trying to use the --clang-macro-fallback feature in the Linux kernel (mailing list post including a kernel patch to test/debug the feature), where we use a couple -include flags.

A possible workaround is to #include manually the headers at the top of the input file, and remove the -include flags.

Cc @jbaublitz

@jbaublitz
Copy link
Contributor

I'll have to investigate this a little bit more. As I recall, merging CFLAGS and multiple input headers becomes very problematic. I've put up an initial PR to test and it appears it's failing so I have to do a little bit more investigation into this and refresh myself on what exactly the conditions are that will work with both CFLAGS and multiple input headers for the FallbackTranslationUnit.

@jbaublitz
Copy link
Contributor

@ojeda I've significantly reworked the code in #3072 that I think is a major improvement. It avoids having to write a temporary header file for the precompilation, and the updates I did to the CFLAG handling now allows users to pass in additional headers to include through environment variables.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-macros bug rust-for-linux Issues relevant to the Rust for Linux project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants