Skip to content

Feature request: compile-time layout tests #2786

Closed
@GKFX

Description

@GKFX

Bindgen currently emits unit tests to check layout. However, these are quite difficult to run for a cross-compiled target as there may be no way to run code on the target as part of the build process. Targets not supporting std, i.e. embedded, are harder again to run the tests on.

With the stabilization of core::mem::offset_of it should now be possible to convert the layout tests into compile-time assertions like below. This would make it much easier for embedded users to run these tests.

const _LAYOUT_TEST_S: () = {
    assert!(::core::mem::size_of::<S>() == 4);
    assert!(::core::mem::align_of::<S>() == 4);
    assert!(::core::mem::offset_of!(S, field1) == 0);
    // etc.
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    rust-for-linuxIssues relevant to the Rust for Linux project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions