Skip to content

Same include in multiple headers #1715

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

Closed
elichai opened this issue Jan 26, 2020 · 3 comments
Closed

Same include in multiple headers #1715

elichai opened this issue Jan 26, 2020 · 3 comments

Comments

@elichai
Copy link
Contributor

elichai commented Jan 26, 2020

Hi,
Sometimes I want to generate rust code for a whole project with a bunch of headers.
and then I have the following problem:

  1. run bindgen on a big header (first.h).
  2. run bindgen on a second header that defines some more stuff and #include "first.h".
  3. this might happen again and again

Now you have the same types in 2 modules.
will it somehow be possible to just replace the includes with pub use first::*?

Thanks.

@elichai elichai changed the title same include in multiple headers Same include in multiple headers Jan 26, 2020
@emilio
Copy link
Contributor

emilio commented Jan 26, 2020

I'm pretty sure we have similar requests (to do blacklisting / whitelisting based on headers, basically) but can't find them r/n.

This is not always trivial because there are built-in types, etc, and definitely deciding where a type comes from is not always feasible.

For example, it is legal to have the same typedef multiple times in different headers, which one do you choose as the "canonical" one, and how do you decide in a way that doesn't depend on include order? Multiple typedefs are not legal in Rust.

That being said, if you ignore that, we may be able to do something that is good enough for most other things.

We could record, if this flag / config option is set, something like the location of a given cursor for a declaration or definition (you can get to the file name with cursor.location().location().0.name(), and store it in the IR.

Then when we generate types, we'd skip everything if the location doesn't match, for example.

So I think such an option cannot be always 100% sound (per the above), but it should be easy to hack up something and see if it works for you. If it does I'd be happy to land it behind some kind of opt-in flag.

@emilio
Copy link
Contributor

emilio commented Jan 26, 2020

Ah, I recall what issue I was thinking about: #303

@pvdrz
Copy link
Contributor

pvdrz commented Apr 19, 2023

I think this is achieved now by blocklisting first.h on the second bindgen invocation and adding a raw line using use first::*;

As Emilio said this is not a general solution but it should work for most cases.

@pvdrz pvdrz closed this as completed Apr 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants