When bindgen generates unions, it always(?) adds the _bindgen_union_align field. However, it also generates the #[repr(C)] annotation, which seems to guarantee the same size and alignment as a compatible C union.
If repr(C) should be enough, why is the alignment field added? Can it be removed from the generated bindings?
All kinds, really. Some unions have only basic data types (integers, chars, arrays), others have struct and union fields. All of the unions have the _bindgen_union_align, anyways.
I see, but I'm wondering what are the circumstances where it might be required.
I'm asking, because I do not want to invoke bindgen through a build script on every platform where my project is built (for a bunch of reasons). I want to have the bindings generated once, and used everywhere. Managing these _bindgen_union_align fields adds to the maintenance burden. I'm trying to understand the implications of dropping them altogether.
Also, issue 1560 sheds more light on this question.
So, if I understand it correctly, the idea behind adding the _bindgen_union_align field is to enforce proper alignment of the generated Rust unions in cases where the underlying C unions have explicit alignment attributes: __attribute__((aligned(16))). This made perfect sense before Rust 1.25, which introduced the #[repr(align(x))] attribute. Nowadays it seems to only be required for backward compatibility.