Skip to content

Conversation

@Yarwin
Copy link
Contributor

@Yarwin Yarwin commented Nov 7, 2025

  • blocklist max_align_t from binding generation
  • update bindgen.

Bindgen can generate wrong size checks for types defined as __attribute__((aligned(__alignof__(struct {...})))), which is, for example, how clang defines max_align_t: https://clang.llvm.org/doxygen/____stddef__max__align__t_8h_source.html. Size checks seems to be fine on all the targets but wasm32-unknown-emscripten, disallowing web builds.

Outside the size check, the generated max_align_t seemed to be OK - llvm defines long double as 128 bits long (u128/f128) for wasm32.

We don't use max_align_t anywhere, so blacklisting it until upstream fixes the problem seems to be the most sane solution.

The max_align_t is being included because of #include <cstddef> in gdextension_interface.h: https://github.com/godotengine/godot/blob/master/core/extension/gdextension_interface.h#L44

Upstream issue: rust-lang/rust-bindgen#3295


Before 0.70 bindgen wasn't generating compile-time checks and relied on tests instead (which were never ran):

Generated binding to max_align_t with bindgen 0.69
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct max_align_t {
    pub __clang_max_align_nonce1: ::std::os::raw::c_longlong,
    pub __clang_max_align_nonce2: u128,
}
#[test]
fn bindgen_test_layout_max_align_t() {
    const UNINIT: ::std::mem::MaybeUninit<max_align_t> = ::std::mem::MaybeUninit::uninit();
    let ptr = UNINIT.as_ptr();
    assert_eq!(
        ::std::mem::size_of::<max_align_t>(),
        24usize,
        concat!("Size of: ", stringify!(max_align_t))
    );
    assert_eq!(
        ::std::mem::align_of::<max_align_t>(),
        8usize,
        concat!("Alignment of ", stringify!(max_align_t))
    );
    assert_eq!(
        unsafe { ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce1) as usize - ptr as usize },
        0usize,
        concat!(
            "Offset of field: ",
            stringify!(max_align_t),
            "::",
            stringify!(__clang_max_align_nonce1)
        )
    );
    assert_eq!(
        unsafe { ::std::ptr::addr_of!((*ptr).__clang_max_align_nonce2) as usize - ptr as usize },
        8usize,
        concat!(
            "Offset of field: ",
            stringify!(max_align_t),
            "::",
            stringify!(__clang_max_align_nonce2)
        )
    );
}
Same for bindgen >= 0.7
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct max_align_t {
    pub __clang_max_align_nonce1: ::std::os::raw::c_longlong,
    pub __clang_max_align_nonce2: u128,
}
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
    ["Size of max_align_t"][::std::mem::size_of::<max_align_t>() - 24usize];
    ["Alignment of max_align_t"][::std::mem::align_of::<max_align_t>() - 8usize];
    ["Offset of field: max_align_t::__clang_max_align_nonce1"]
        [::std::mem::offset_of!(max_align_t, __clang_max_align_nonce1) - 0usize];
    ["Offset of field: max_align_t::__clang_max_align_nonce2"]
        [::std::mem::offset_of!(max_align_t, __clang_max_align_nonce2) - 8usize];
};

I also updated bindgen – I was already poking their code, so I would (hopefully) notice any regression or change in their API.

- blocklist max_align_t from binding generation
- update bindgen.

----

Bindgen can generate wrong size checks for types defined as `__attribute__((aligned(__alignof__(struct {...}))))`, which is how clang defines max_align_t: https://clang.llvm.org/doxygen/____stddef__max__align__t_8h_source.html. Size checks seems to be fine on all the targets but `wasm32-unknown-emscripten`, disallowing web builds.
We don't use `max_align_t` anywhere, so blacklisting it until upstream fixes the problem seems to be the most sane solution.
(also why nothing supports git-notes?)
@Yarwin Yarwin added bug c: ffi Low-level components and interaction with GDExtension API c: wasm WebAssembly export target labels Nov 7, 2025
@GodotRust
Copy link

API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-1401

@Ughuuu
Copy link
Contributor

Ughuuu commented Nov 7, 2025

Tried this branch in my build here: appsinacup/godot-rapier-physics#432 And indeed god a fully passing build (for web)

Copy link
Member

@Bromeon Bromeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot to @Yarwin for investigating and fixing, and to @Ughuuu for reporting and testing! 💪

@Yarwin Yarwin added this pull request to the merge queue Nov 8, 2025
Merged via the queue into godot-rust:master with commit 582d900 Nov 8, 2025
20 checks passed
@Yarwin Yarwin deleted the blocklist_max_align_t_from_codegen branch November 8, 2025 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug c: ffi Low-level components and interaction with GDExtension API c: wasm WebAssembly export target

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants