Skip to content

Commit

Permalink
detect: Make sys_const! macro rustfmt-compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Oct 19, 2024
1 parent 3fa76ad commit 667ecb1
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/imp/detect/aarch64_aa64reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ mod imp {
pub(super) mod ffi {
pub(crate) use super::super::c_types::{c_int, c_size_t, c_uint, c_void};

sys_const! {
sys_const!({
// Defined in sys/sysctl.h.
// https://github.com/openbsd/src/blob/ed8f5e8d82ace15e4cefca2c82941b15cb1a7830/sys/sys/sysctl.h#L82
pub(crate) const CTL_MACHDEP: c_int = 7;
Expand All @@ -246,7 +246,7 @@ mod imp {
// However, on OpenBSD 7.3-7.5, querying CPU_ID_AA64MMFR2 always returns 0.
// https://github.com/openbsd/src/commit/e8331b74e5c20302d4bd948c9db722af688ccfc1
pub(crate) const CPU_ID_AA64MMFR2: c_int = 7;
}
});

extern "C" {
// Defined in sys/sysctl.h.
Expand Down
4 changes: 2 additions & 2 deletions src/imp/detect/aarch64_fuchsia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ mod ffi {
// https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/zircon/system/public/zircon/types.h
pub(crate) type zx_status_t = i32;

sys_const! {
sys_const!({
// https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/zircon/system/public/zircon/errors.h
pub(crate) const ZX_OK: zx_status_t = 0;

// https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/zircon/system/public/zircon/features.h
pub(crate) const ZX_FEATURE_KIND_CPU: u32 = 0;
pub(crate) const ZX_ARM64_FEATURE_ISA_ATOMICS: u32 = 1 << 8;
}
});

#[link(name = "zircon")]
extern "C" {
Expand Down
4 changes: 2 additions & 2 deletions src/imp/detect/aarch64_illumos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ include!("common.rs");
mod ffi {
pub(crate) use super::c_types::c_uint;

sys_const! {
sys_const!({
// Defined in sys/auxv_aarch64.h.
// https://github.com/richlowe/illumos-gate/blob/arm64-gate/usr/src/uts/common/sys/auxv_aarch64.h
pub(crate) const AV_AARCH64_LSE: u32 = 1 << 15;
pub(crate) const AV_AARCH64_2_LSE2: u32 = 1 << 2;
}
});

extern "C" {
// Defined in sys/auxv.h.
Expand Down
16 changes: 8 additions & 8 deletions src/imp/detect/auxv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ mod os {
#[cfg(all(target_arch = "aarch64", target_os = "android"))]
pub(crate) use super::super::c_types::{c_char, c_int};

sys_const! {
sys_const!({
// https://github.com/torvalds/linux/blob/v6.11/include/uapi/linux/auxvec.h
#[cfg(any(test, target_arch = "aarch64"))]
pub(crate) const AT_HWCAP: c_ulong = 16;
Expand All @@ -135,7 +135,7 @@ mod os {
// https://github.com/aosp-mirror/platform_bionic/blob/d3ebc2f7c49a9893b114124d4a6b315f3a328764/libc/include/sys/system_properties.h
#[cfg(all(target_arch = "aarch64", target_os = "android"))]
pub(crate) const PROP_VALUE_MAX: c_int = 92;
}
});

extern "C" {
// Defined in sys/auxv.h.
Expand Down Expand Up @@ -189,7 +189,7 @@ mod os {
pub(super) mod ffi {
pub(crate) use super::super::c_types::{c_int, c_ulong, c_void};

sys_const! {
sys_const!({
// FreeBSD
// Defined in sys/elf_common.h.
// https://github.com/freebsd/freebsd-src/blob/release/14.1.0/sys/sys/elf_common.h
Expand All @@ -200,7 +200,7 @@ mod os {
pub(crate) const AT_HWCAP: c_int = 25;
#[cfg(any(test, target_arch = "powerpc64"))]
pub(crate) const AT_HWCAP2: c_int = 26;
}
});

extern "C" {
// FreeBSD
Expand Down Expand Up @@ -243,7 +243,7 @@ use arch::_detect;
mod arch {
use super::{ffi, os, CpuInfo};

sys_const! {
sys_const!({
// Linux
// https://github.com/torvalds/linux/blob/v6.11/arch/arm64/include/uapi/asm/hwcap.h
// https://github.com/torvalds/linux/blob/v6.11/Documentation/arch/arm64/elf_hwcaps.rst
Expand Down Expand Up @@ -279,7 +279,7 @@ mod arch {
#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(target_pointer_width = "64")]
pub(super) const HWCAP2_LSE128: ffi::c_ulong = 1 << 47;
}
});

#[cold]
pub(super) fn _detect(info: &mut CpuInfo) {
Expand Down Expand Up @@ -309,7 +309,7 @@ mod arch {
mod arch {
use super::{ffi, os, CpuInfo};

sys_const! {
sys_const!({
// Linux
// https://github.com/torvalds/linux/blob/v6.11/arch/powerpc/include/uapi/asm/cputable.h
// https://github.com/torvalds/linux/blob/v6.11/Documentation/arch/powerpc/elf_hwcaps.rst
Expand Down Expand Up @@ -339,7 +339,7 @@ mod arch {
// https://github.com/freebsd/freebsd-src/commit/1e434da3b065ef96b389e5e0b604ae05a51e794e
#[cfg(not(target_os = "openbsd"))]
pub(super) const PPC_FEATURE2_ARCH_3_1: ffi::c_ulong = 0x00040000;
}
});

#[cold]
pub(super) fn _detect(info: &mut CpuInfo) {
Expand Down
6 changes: 4 additions & 2 deletions src/imp/detect/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,13 @@ flags! {
#[allow(dead_code, unused_macros, non_camel_case_types)]
#[macro_use]
mod c_types {
// Note: This macro is sys_const!({ }), not sys_const! { }.
// An extra brace is used in input to make contents rustfmt-able:.
macro_rules! sys_const {
($(
({$(
$(#[$attr:meta])*
$vis:vis const $name:ident: $ty:ty = $val:expr;
)*) => {
)*}) => {
$(
$(#[$attr])*
$vis const $name: $ty = $val;
Expand Down
4 changes: 2 additions & 2 deletions src/imp/detect/riscv_linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ mod ffi {
pub(crate) value: u64,
}

sys_const! {
sys_const!({
pub(crate) const __NR_riscv_hwprobe: c_long = 258;

// https://github.com/torvalds/linux/blob/v6.11/arch/riscv/include/uapi/asm/hwprobe.h
pub(crate) const RISCV_HWPROBE_KEY_IMA_EXT_0: i64 = 4;
// Linux 6.8+
// https://github.com/torvalds/linux/commit/154a3706122978eeb34d8223d49285ed4f3c61fa
pub(crate) const RISCV_HWPROBE_EXT_ZACAS: u64 = 1 << 34;
}
});

#[cfg(not(all(
target_os = "linux",
Expand Down

0 comments on commit 667ecb1

Please sign in to comment.