From 12ca25079259c66574ca2966c6a2d62bcddb1f49 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sun, 30 Oct 2022 08:49:46 -0700 Subject: [PATCH] cpu: Expand dynamic detection to all supported OSs on AArch64. --- Cargo.toml | 2 +- src/cpu.rs | 33 +++++++++++++++++++++------------ src/cpu/arm.rs | 2 +- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e1509c794b..20eb73db4f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -167,7 +167,7 @@ name = "ring" getrandom = { version = "0.2.8" } untrusted = { version = "0.9" } -[target.'cfg(any(target_arch = "x86",target_arch = "x86_64", all(any(target_arch = "aarch64", target_arch = "arm"), any(target_os = "android", target_os = "fuchsia", target_os = "linux", target_os = "windows"))))'.dependencies] +[target.'cfg(any(target_arch = "x86",target_arch = "x86_64", all(target_arch = "aarch64", any(target_family = "unix", target_family = "windows")), all(target_arch = "arm", any(target_os = "android", target_os = "fuchsia", target_os = "linux", target_os = "windows"))))'.dependencies] spin = { version = "0.9.2", default-features = false, features = ["once"] } [target.'cfg(all(target_arch = "arm", any(target_os = "android", target_os = "linux")))'.dependencies] diff --git a/src/cpu.rs b/src/cpu.rs index 994d01e4c2..a7c7ae9e2e 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -24,13 +24,30 @@ pub(crate) struct Features(()); #[inline(always)] pub(crate) fn features() -> Features { - // We don't do runtime feature detection on aarch64-apple-* as all AAarch64 - // features we use are available on every device since the first devices. + // TODO: The list of operating systems for `aarch64` should really be + // "whatever has `std::arch::is_aarch64_feature_detected`". #[cfg(any( target_arch = "x86", target_arch = "x86_64", all( - any(target_arch = "aarch64", target_arch = "arm"), + target_arch = "aarch64", + any( + target_os = "android", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "illumos", + target_os = "ios", + target_os = "linux", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", + target_os = "solaris", + target_os = "windows", + ) + ), + all( + target_arch = "arm", any( target_os = "android", target_os = "fuchsia", @@ -52,15 +69,7 @@ pub(crate) fn features() -> Features { } } - #[cfg(all( - any(target_arch = "aarch64", target_arch = "arm"), - any( - target_os = "android", - target_os = "fuchsia", - target_os = "linux", - target_os = "windows" - ) - ))] + #[cfg(any(target_arch = "aarch64", target_arch = "arm"))] { arm::setup(); } diff --git a/src/cpu/arm.rs b/src/cpu/arm.rs index f004550df9..8087cc0672 100644 --- a/src/cpu/arm.rs +++ b/src/cpu/arm.rs @@ -67,7 +67,7 @@ macro_rules! features { }; )+ - #[cfg(target_arch = "aarch64")] + #[cfg(all(target_arch = "aarch64", any(target_family = "unix", target_family = "windows")))] pub fn setup() { extern crate std; use std::arch::is_aarch64_feature_detected;