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

Switch to single precompiled header in macro fallback #2823

Merged
merged 1 commit into from May 2, 2024

Conversation

jbaublitz
Copy link
Contributor

Fix for issue reported here.

@SeleDreams Could you also confirm that this resolves your problem?

@SeleDreams
Copy link

Fix for issue reported here.

@SeleDreams Could you also confirm that this resolves your problem?

I tested, seems like it still doesn't generate the IRQ defines when I have other headers included

@jbaublitz
Copy link
Contributor Author

@SeleDreams Can you provide me with a minimal reproducer to reproduce your problem with the headers you're using? I'm no longer able to reproduce the problem with this PR in the setup that originally helped me confirm that there was a bug.

Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks reasonable but I guess we should sort out why it's still not working for @SeleDreams? Or do you want this merged now?

A test for this would also be amazing, but if it's too hard to set up lmk.

bindgen/ir/context.rs Outdated Show resolved Hide resolved
@SeleDreams
Copy link

SeleDreams commented Apr 30, 2024 via email

@jbaublitz
Copy link
Contributor Author

This looks reasonable but I guess we should sort out why it's still not working for @SeleDreams? Or do you want this merged now?

I would like to figure out what's going on with @SeleDreams before we merge this as they reported the problem originally so I'd like to make sure it works in their use case too. If it's a setup problem, I'll help debug and if there are two bugs, I'll fix the second one. :)

A test for this would also be amazing, but if it's too hard to set up lmk.

How would you generally suggest I go about testing multiple headers? Is there infrastructure for that?

@jbaublitz
Copy link
Contributor Author

I'll try to do a reproduction case as soon as possible. Right now with my great luck I have an X server issue on the linux machine I work on so I can't do it right now Le lun. 29 avr. 2024 à 20:02, John Baublitz @.> a écrit :

@SeleDreams https://github.com/SeleDreams Can you provide me with a minimal reproducer to reproduce your problem with the headers you're using? I'm no longer able to reproduce the problem with this PR in the setup that originally helped me confirm that there was a bug. — Reply to this email directly, view it on GitHub <#2823 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD4UF4PB56GDOHDE2TOYJHDY72DNHAVCNFSM6AAAAABG6PCDBSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOBTGM2DANJRGE . You are receiving this because you were mentioned.Message ID: @.
>

Okay sounds good! Just let me know when you can provide the reproducer, and I'll take a look. Basically I just want to rule out a setup problem because since bindgen doesn't have a lot of error reporting infrastructure yet (I think it's planned), setup problems will look exactly the same as a bug: bindings for the constants are just not generated. If it's a bug, I'll fix it. If not, I'll try to point you to exactly what's going on.

@SeleDreams
Copy link

@jbaublitz So, I was able to make a reproduction project, however, for some weird reason, it seems to delete the wrapper.h as well everytime I build the project which in itself could be another bug
https://github.com/SeleDreams/reproduction_test

@jbaublitz
Copy link
Contributor Author

@SeleDreams Thanks so much for the report and taking the time to craft a reproducer! It appears there were two bugs. One was that Clang only supports one precompiled header at a time which I resolved, but the other is that -I flags were not getting passed from .clang_arg() calls to the header precompilation. The reason I didn't bump into this is that I was testing on headers in system folders, but for headers that are in nonstandard places (like in your case) these were not being picked up.

The resolution I've come to is forwarding all -I and -isystem flags. @emilio Let me know if you think other flags should be forwarded too.

@jbaublitz jbaublitz force-pushed the bindgen-fallback-fix branch 3 times, most recently from 4f6af27 to 23237c5 Compare April 30, 2024 20:35
@jbaublitz
Copy link
Contributor Author

I've added a test that tests both multiple headers and also the -I parameters being forwarded.

Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any good reason not to forward all flags? Think of a macro that desugars to something like sizeof(int), if you don't pass the right flags (like --target and so) you might end up with the wrong constant value, right? Same with sizeof(enum foo) if you don't pass -fshort-enums or what not... Probably countless examples too.

@jbaublitz
Copy link
Contributor Author

Is there any good reason not to forward all flags? Think of a macro that desugars to something like sizeof(int), if you don't pass the right flags (like --target and so) you might end up with the wrong constant value, right? Same with sizeof(enum foo) if you don't pass -fshort-enums or what not... Probably countless examples too.

The reason I didn't forward all flags is that generally there's a header provided at the end of the clang args in my tests which causes the precompilation to fail. If you'd prefer, I can just remove the last argument instead of exclusively passing the include directives.

@emilio
Copy link
Contributor

emilio commented May 1, 2024

Yes. Excluding what we don't need seems like a better approach imho

@jbaublitz
Copy link
Contributor Author

@emilio I've taken the approach of filtering out any argument that matches the elements in input_headers or -include based on how bindgen generates c_args for the main translation unit. Let me know if you have any issues with this approach.

@SeleDreams Once the code review is done, do you mind testing your actual setup and confirming the problem is resolved?

It appears that Clang only supports a single precompiled header at a
time. Because the macro fallback depends on the ability to provide
multiple precompiled headers at once, this commit changes the code to
include all provided headers into a single header to precompile and then
pass to the TranslationUnit. This should resolve the issue where the
macro fallback would not function as intended when multiple headers were
provided as input. This commit also resolves an issue where clang args
passed to the builder were not forwarded to the precompilation
translation unit, resulting in headers not in standard system
directories not being found.
@emilio emilio added this pull request to the merge queue May 2, 2024
Merged via the queue into rust-lang:main with commit e847ef1 May 2, 2024
33 checks passed
@ojeda ojeda added the rust-for-linux Issues relevant to the Rust for Linux project label May 2, 2024
@jbaublitz
Copy link
Contributor Author

@SeleDreams I'm assuming this resolved your issue? If not, please let me know.

@SeleDreams
Copy link

that seems to have worked

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

Successfully merging this pull request may close these issues.

None yet

4 participants