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

compile: Add minimal bindgen allowlist_function() support #20

Merged
merged 1 commit into from Jun 29, 2022

Conversation

MarijnS95
Copy link
Contributor

By default bindgen emits bindings for every item in the provided header, which are typically platform- and architecture-specific defines from stdint.h and stdbool.h. This is noisy and unnecessary as the function signatures typically don't use any of these.

By allowing the user to set a custom list of function names, bindgen only emits bindings for said functions and any type(s) they (recursively) reference.

Unfortunately bindgen::Builder cannot be cloned and is moved by every call, which doesn't allow us to call .generate() on it multiple times (and neatly add the header() without updating the underlying struct). In contrast, Config::compile() here borrows self and requires the builder struct to be reusable across possibly multiple calls on the same Config. For this reason a minimal struct has been added that currently only supports allowlist_function().

By default `bindgen` emits bindings for every item in the provided
header, which are typically platform- and architecture-specific defines
from `stdint.h` and `stdbool.h`.  This is noisy and unnecessary as the
function signatures typically don't use any of these.

By allowing the user to set a custom list of function names, bindgen
only emits bindings for said functions and any type(s) they
(recursively) reference.

Unfortunately `bindgen::Builder` cannot be cloned and is moved by every
call, which doesn't allow us to call `.generate()` on it multiple times
(and neatly add the `header()` without updating the underlying struct).
In contrast, `Config::compile()` here borrows `self` and requires the
builder struct to be reusable across possibly multiple calls on the same
`Config`.  For this reason a minimal struct has been added that
currently only supports `allowlist_function()`.
Copy link
Owner

@Twinklebear Twinklebear left a comment

Choose a reason for hiding this comment

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

Thanks @MarijnS95 , this looks great!

It'd be a bit nicer if the whole bindgen options could be cloned since then we wouldn't need to do any work to add support for specifying other ones, but this will work well to get around that limitation. We can add other bindgen options as needed for folks through this same route

I think CI should pass after I merge this to master since then it'll pick up your commit removing aligned_alloc

@Twinklebear Twinklebear merged commit eb4b4a9 into Twinklebear:master Jun 29, 2022
@MarijnS95 MarijnS95 deleted the bindgen-allowlist branch June 29, 2022 06:51
MarijnS95 added a commit to Traverse-Research/ispc-downsampler that referenced this pull request Jun 29, 2022
`ispc_compile` can now be configured to omit irrelevant bindings from
the bindings file and leave only the function(s) in place that are
relevant to interface with the ISPC kernel
(Twinklebear/ispc-rs#20).  This makes the file
less busy/noisy, and it won't change when regenerating across OS-es
anymore.
MarijnS95 added a commit to Traverse-Research/ispc-downsampler that referenced this pull request Jun 30, 2022
`ispc_compile` can now be configured to omit irrelevant bindings from
the bindings file and leave only the function(s) in place that are
relevant to interface with the ISPC kernel
(Twinklebear/ispc-rs#20).  This makes the file
less busy/noisy, and it won't change when regenerating across OS-es
anymore.
MarijnS95 added a commit to Traverse-Research/ispc-downsampler that referenced this pull request Jun 30, 2022
`ispc_compile` can now be configured to omit irrelevant bindings from
the bindings file and leave only the function(s) in place that are
relevant to interface with the ISPC kernel
(Twinklebear/ispc-rs#20).  This makes the file
less busy/noisy, and it won't change when regenerating across OS-es
anymore.
MarijnS95 added a commit to Traverse-Research/ispc-downsampler that referenced this pull request Jun 30, 2022
`ispc_compile` can now be configured to omit irrelevant bindings from
the bindings file and leave only the function(s) in place that are
relevant to interface with the ISPC kernel
(Twinklebear/ispc-rs#20).  This makes the file
less busy/noisy, and it won't change when regenerating across OS-es
anymore.
MarijnS95 added a commit to Traverse-Research/intel-tex-rs-2 that referenced this pull request Jun 30, 2022
`ispc_compile` can now be configured to omit irrelevant bindings from
the bindings file and leave only the function(s) in place that are
relevant to interface with the ISPC kernel
(Twinklebear/ispc-rs#20).  This makes the file
less busy/noisy, and it won't change when regenerating across OS-es
anymore.
MarijnS95 added a commit to Traverse-Research/ispc-downsampler that referenced this pull request Jun 30, 2022
`ispc_compile` can now be configured to omit irrelevant bindings from
the bindings file and leave only the function(s) in place that are
relevant to interface with the ISPC kernel
(Twinklebear/ispc-rs#20).  This makes the file
less busy/noisy, and it won't change when regenerating across OS-es
anymore.
MarijnS95 added a commit to Traverse-Research/intel-tex-rs-2 that referenced this pull request Jun 30, 2022
* Upgrade to `ispc 1.1.0` with cleaned up bindings file

`ispc_compile` can now be configured to omit irrelevant bindings from
the bindings file and leave only the function(s) in place that are
relevant to interface with the ISPC kernel
(Twinklebear/ispc-rs#20).  This makes the file
less busy/noisy, and it won't change when regenerating across OS-es
anymore.

* Edition 2018 cleanup
@MarijnS95
Copy link
Contributor Author

rust-lang/rust-bindgen#2302 looks like this just got implemented, so we might improve the situation soon when a newer bindgen is released!

MarijnS95 added a commit to MarijnS95/ispc-rs that referenced this pull request Oct 20, 2022
As announced earlier in Twinklebear#20 when introducing `BindgenOptions`, upstream
`bindgen` didn't yet allow cloning nor copying their `Builder` struct,
limiting it to generate a single binding per `Builder` object.  This
doesn't fit with ispc-rs's `Config` struct which explicitly allows
multiple libraries to be compiled using (partially) the same
base configuration (barring any side-effects from `fn compile(&mut self,
lib)` updating various fields depending on `lib`).

This issue has since been addressed upstream, and now allows us to move
and clone the `bindgen::Builder` around instead of implementing a very
limited subset of config fields and manually reconstructing the builder
every time.
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 this pull request may close these issues.

None yet

2 participants