Use custom macros for static assertions

This commit is contained in:
Brian Carroll 2022-02-09 17:04:28 +00:00
parent d8b76b317b
commit c61a18a200
8 changed files with 82 additions and 26 deletions

View file

@ -29,3 +29,39 @@ macro_rules! user_error {
std::process::exit(1);
})
}
/// Assert that a type has the expected size on ARM
#[macro_export]
macro_rules! assert_sizeof_aarch64 {
($t: ty, $expected_size: expr) => {
#[cfg(target_arch = "aarch64")]
static_assertions::assert_eq_size!($t, [u8; $expected_size]);
};
}
/// Assert that a type has the expected size in Wasm
#[macro_export]
macro_rules! assert_sizeof_wasm {
($t: ty, $expected_size: expr) => {
#[cfg(target_family = "wasm")]
static_assertions::assert_eq_size!($t, [u8; $expected_size]);
};
}
/// Assert that a type has the expected size on any target not covered above
/// In practice we use this for x86_64, and add specific macros for other platforms
#[macro_export]
macro_rules! assert_sizeof_default {
($t: ty, $expected_size: expr) => {
#[cfg(not(any(target_family = "wasm", target_arch = "aarch64")))]
static_assertions::assert_eq_size!($t, [u8; $expected_size]);
};
}
/// Assert that a type has the expected size on all targets
#[macro_export]
macro_rules! assert_sizeof_all {
($t: ty, $expected_size: expr) => {
static_assertions::assert_eq_size!($t, [u8; $expected_size]);
};
}