rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

Support conditional derives / custom attributes

Open Crzyrndm opened this issue 2 years ago • 2 comments

As far as I can tell, #1089 was resolved by the ability to add custom derives. The support for more custom attributes beyond just listing derives wasn't part of the resolution.

I have a case where the derive needs to be conditional (cfg_attr(feature = "feat1", derive(MyDerive))) and the bindings are not being generated from the build script (in this case: to reduce build system dependencies). I have a workaround generating a set of bindings for each combination of conditions but this

  • is unwieldy / awkward
  • only works for derives and I have at least one case where I need to manually add an attribute currently

It would be appreciated if ParseCallbacks::add_derives could be extended to a more general ParseCallbacks::add_attributes

Crzyrndm avatar May 05 '23 06:05 Crzyrndm

This would also fix https://github.com/rust-lang/rust-bindgen/discussions/2513

pvdrz avatar May 05 '23 07:05 pvdrz

I have just opened https://github.com/rust-lang/rust-bindgen/pull/2866. :)

mkroening avatar Jul 08 '24 14:07 mkroening