Skip to content

Feature request: allow blocklisting by file #2096

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
daviddrysdale opened this issue Sep 6, 2021 · 1 comment · Fixed by #2097
Closed

Feature request: allow blocklisting by file #2096

daviddrysdale opened this issue Sep 6, 2021 · 1 comment · Fixed by #2097

Comments

@daviddrysdale
Copy link
Contributor

From #1200 (comment):

If the library you're binding against doesn't have any sort of type / function naming convention or what not, that can indeed be a problem. If you point me to an specific example we can try to figure out what's the best solution for that. Mind opening a new issue for it though?

One specific example of a library that doesn't have an easy library-wide naming convention is BoringSSL / OpenSSL.

We're looking at adding BoringSSL support to the openssl crate via bindgen, and we'd like to avoid including things from system headers in the generated code. I started trying to build an allowlist to just match things from BoringSSL, but I gave up when I reached 75 different prefixes (!).

So I wondered whether adding something like a --blocklist-file "/usr/include.*" option would be feasible?

@daviddrysdale
Copy link
Contributor Author

Implementation-wise, would adding a location: Option<clang:SourceLocation> field to the Item type be a possible way to go? Most of the places that build new Items have location information available that could be used to populate this, and then Item::is_blocklisted() could check this information against a new BindgenOptions::blocklisted_files option.

Happy to send over a draft PR for this if it sounds helpful/sensible.

(There's one special case that turned up when I was experimenting – some standard integer types from <stdint.h> seem get mapped to Rust integer types regardless of whether they're blocklisted, so there probably needs to be a corresponding special case in BindgenContext::blocklisted_trait_implements_type() to assume that the these integer types are Copy/Clone/Debug.)

daviddrysdale added a commit to daviddrysdale/rust-bindgen that referenced this issue Sep 8, 2021
Update Item to hold a `clang::SourceLocation` and use this to allow
blocklisting based on filename.

The existing code has a special case that always maps <stdint.h> integer
types to corresponding Rust integer types, even if the C types are
blocklisted.  To match this special case behaviour, also treat these
C <stdint.h> types as being eligible for derived Copy/Clone/Debug
traits.

Fixes rust-lang#2096
daviddrysdale added a commit to daviddrysdale/rust-bindgen that referenced this issue Sep 8, 2021
Update Item to hold a `clang::SourceLocation` and use this to allow
blocklisting based on filename.

The existing code has a special case that always maps <stdint.h> integer
types to corresponding Rust integer types, even if the C types are
blocklisted.  To match this special case behaviour, also treat these
C <stdint.h> types as being eligible for derived Copy/Clone/Debug
traits.

Fixes rust-lang#2096
daviddrysdale added a commit to daviddrysdale/rust-bindgen that referenced this issue Sep 27, 2021
Update Item to hold a `clang::SourceLocation` and use this to allow
blocklisting based on filename.

The existing code has a special case that always maps <stdint.h> integer
types to corresponding Rust integer types, even if the C types are
blocklisted.  To match this special case behaviour, also treat these
C <stdint.h> types as being eligible for derived Copy/Clone/Debug
traits.

Fixes rust-lang#2096
daviddrysdale added a commit to daviddrysdale/rust-bindgen that referenced this issue Oct 29, 2021
Update Item to hold a `clang::SourceLocation` and use this to allow
blocklisting based on filename.

The existing code has a special case that always maps <stdint.h> integer
types to corresponding Rust integer types, even if the C types are
blocklisted.  To match this special case behaviour, also treat these
C <stdint.h> types as being eligible for derived Copy/Clone/Debug
traits.

Fixes rust-lang#2096
emilio pushed a commit that referenced this issue Nov 26, 2021
Update Item to hold a `clang::SourceLocation` and use this to allow
blocklisting based on filename.

The existing code has a special case that always maps <stdint.h> integer
types to corresponding Rust integer types, even if the C types are
blocklisted.  To match this special case behaviour, also treat these
C <stdint.h> types as being eligible for derived Copy/Clone/Debug
traits.

Fixes #2096
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

Successfully merging a pull request may close this issue.

1 participant