mozilla / cbindgen

A project for generating C bindings from Rust code
Mozilla Public License 2.0
2.27k stars 294 forks source link

Implement whitelist in ExportConfig #978

Open AnthonyYoManz opened 1 week ago

AnthonyYoManz commented 1 week ago

Adds a field whitelist to ExportConfig, allowing users to specify an exclusive list of items they wish to include in the generated header file. If the field is left empty it is ignored.

If excludes or includes are specified, they override the whitelist. For example in the case where we have functions foo, bar, and baz and our whitelist specifies foo and bar, then only foo and bar will be included in the output header file. If they add an include baz, all three functions will be included in the output. If they then add an exclude foo, only bar and baz will be included in the output.

Closes https://github.com/mozilla/cbindgen/issues/484

AnthonyYoManz commented 1 week ago

Maybe I've missed it but I could not find where tests for other ExportConfig fields are, so I took the path of least resistance and simply wrote none for this - although I did test 'manually' by writing a separate crate and making sure behaviour was as described in my PR description. With some guidance on where exactly to put such a test I am happy to write it myself, although it might be a little awkward as I am on Windows and the entire test-suite very much does not function on this platform.