Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: compile-time layout tests #2786

Closed
GKFX opened this issue Mar 23, 2024 · 0 comments · Fixed by #2787
Closed

Feature request: compile-time layout tests #2786

GKFX opened this issue Mar 23, 2024 · 0 comments · Fixed by #2787
Labels
rust-for-linux Issues relevant to the Rust for Linux project

Comments

@GKFX
Copy link
Contributor

GKFX commented Mar 23, 2024

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.
};
@ojeda ojeda added the rust-for-linux Issues relevant to the Rust for Linux project label Mar 23, 2024
plaes added a commit to plaes/nrf-sdc that referenced this issue Oct 22, 2024
Biggest change change introduced in 0.70 is the compile-time
layout tests to to check and validate layouts. Previously these
tests were implemented as unit tests which made it somewhat
difficult to run on cross-compiled targets.

More info:
* rust-lang/rust-bindgen#2786
* rust-lang/rust-bindgen#2787
plaes added a commit to plaes/nrf-sdc that referenced this issue Oct 22, 2024
Biggest change change introduced in bindgen 0.70 is the compile-time
layout tests to to check and validate layouts. Previously these
tests were implemented as unit tests which made it somewhat
difficult to run on cross-compiled targets.

Also, drop `rustfmt_bindings()` call had been enabled by default for
a while and was removed/deprecated in bindgen 0.65.x releases.

More info:
* rust-lang/rust-bindgen#2786
* rust-lang/rust-bindgen#2787
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rust-for-linux Issues relevant to the Rust for Linux project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants