Skip to content

repr(C,packed(4)) type generated that transitively contains repr(align(4)), causing a build error #1556

@Lokathor

Description

@Lokathor

So I've got some sdl2 bindings of my own that currently binds only SDL.h, and I tried to add the SDL_syswm.h file to the bindings. However, when I did the following rust ended up being generated:

#[repr(C, packed(4))]
#[derive(Copy, Clone)]
pub struct _IMAGE_TLS_DIRECTORY64 {
  pub StartAddressOfRawData: ULONGLONG,
  pub EndAddressOfRawData: ULONGLONG,
  pub AddressOfIndex: ULONGLONG,
  pub AddressOfCallBacks: ULONGLONG,
  pub SizeOfZeroFill: DWORD,
  pub __bindgen_anon_1: _IMAGE_TLS_DIRECTORY64__bindgen_ty_1,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub union _IMAGE_TLS_DIRECTORY64__bindgen_ty_1 {
  pub Characteristics: DWORD,
  pub __bindgen_anon_1: _IMAGE_TLS_DIRECTORY64__bindgen_ty_1__bindgen_ty_1,
  _bindgen_union_align: u32,
}
#[repr(C)]
#[repr(align(4))]
#[derive(Debug, Default, Copy, Clone, PartialEq)]
pub struct _IMAGE_TLS_DIRECTORY64__bindgen_ty_1__bindgen_ty_1 {
  pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize], u32>,
}

Unfortunately this is actually an illegal setup

D:\dev\fermium>cargo build
   Compiling fermium v0.0.7 (D:\dev\fermium)
error[E0588]: packed type cannot transitively contain a `[repr(align)]` type
     --> D:\dev\fermium\target\debug\build\fermium-3d250ea95a1b04df\out/bindings.rs:62015:1
      |
62015 | / pub struct _IMAGE_TLS_DIRECTORY64 {
62016 | |   pub StartAddressOfRawData: ULONGLONG,
62017 | |   pub EndAddressOfRawData: ULONGLONG,
62018 | |   pub AddressOfIndex: ULONGLONG,
...     |
62021 | |   pub __bindgen_anon_1: _IMAGE_TLS_DIRECTORY64__bindgen_ty_1,
62022 | | }
      | |_^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0588`.
error: Could not compile `fermium`.

And so I come here, and I'm not sure how to move forward.

Is this a bug in bindgen not computing the alignment setup properly? Should I just blacklist the type from being generated? Something else?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions