cbindgen
cbindgen copied to clipboard
support emitting a types-only subheader
Looking at the code this is actually probably pretty easy. We buffer up literally everything until the end, so we should in theory be able to emit just the types into another file. Ideally the "full" header would just include the types header in this mode.
Specifically you would want a version of write_to_file that takes two files and splits this general item-processing part across the two:
https://github.com/eqrion/cbindgen/blob/9b5dd80d84cc4b0e0b696383b3d9b314d752bcbd/src/bindgen/bindings.rs#L226-L235
And then invoke it here:
https://github.com/eqrion/cbindgen/blob/b8140911ee843af93e6314fee72be96e30df63a6/src/main.rs#L255-L267
context: a lot of code randomly traffics in webrender types, but doesn't care about the actual WR API. It would be nice if API changes didn't make us rebuild all those type-referencing files.
also it's fine that such a header would include auto-generated methods like ctors/dtors/operators. those presumably only change in lockstep with the type, so you need to rebuild the world anyway.
I'm confused. If you have something like #[repr(C)] struct WrId(usize);
, how could you avoid it in the header?
In the header that contains the function signatures, I mean.
You could potentially split out the stuff that is only used by reference / pointer or what not. Maybe. But then this is not so straight-forward anymore.
I think you have it backwards? The function signatures one would include the types header and be effectively the same as today's header. But it would be nice to have the types header split out for things that only need to pass those types around.
This would make it possible to mess around with the function signatures without needing to rebuild as much, as long as all the types stay the same.
Oh! Ok I was indeed thinking the other way around, that the "fast case" would be changing the structs and not the API.
While oxidizing speexdsp I stumbled upon this problem + the more generic one of having to produce 1 library and many headers.
Could be possible to add a way to tag the modules so for each tag a .h is produced?