From b1edbf90955cb9b057a323f761e2c19edb591e6f Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sat, 7 Sep 2024 14:13:02 +0200 Subject: [PATCH] Enable feature detection on all Apple/Darwin targets Tested in the simulator and on the device I had lying around, a 1st generation iPad Mini (which isn't Aarch64, but shows that the `sysctlbyname` calls still work even there, even if they return false). `sysctlbyname` _should_ be safe to use without causing rejections from the app store, as its usage is documented in: https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics Also, the standard library will use these soon anyhow, so this shouldn't affect the situation: https://github.com/rust-lang/rust/pull/129019 --- crates/std_detect/src/detect/mod.rs | 4 ++-- .../std_detect/src/detect/os/{macos => darwin}/aarch64.rs | 4 +++- crates/std_detect/tests/cpu-detection.rs | 4 ++-- crates/stdarch-test/src/disassembly.rs | 4 ++-- triagebot.toml | 6 +++--- 5 files changed, 12 insertions(+), 10 deletions(-) rename crates/std_detect/src/detect/os/{macos => darwin}/aarch64.rs (94%) diff --git a/crates/std_detect/src/detect/mod.rs b/crates/std_detect/src/detect/mod.rs index ae86ca987e..ab247a303e 100644 --- a/crates/std_detect/src/detect/mod.rs +++ b/crates/std_detect/src/detect/mod.rs @@ -66,8 +66,8 @@ cfg_if! { } else if #[cfg(all(target_os = "windows", any(target_arch = "aarch64", target_arch = "arm64ec")))] { #[path = "os/windows/aarch64.rs"] mod os; - } else if #[cfg(all(target_os = "macos", target_arch = "aarch64", feature = "libc"))] { - #[path = "os/macos/aarch64.rs"] + } else if #[cfg(all(target_vendor = "apple", target_arch = "aarch64", feature = "libc"))] { + #[path = "os/darwin/aarch64.rs"] mod os; } else { #[path = "os/other.rs"] diff --git a/crates/std_detect/src/detect/os/macos/aarch64.rs b/crates/std_detect/src/detect/os/darwin/aarch64.rs similarity index 94% rename from crates/std_detect/src/detect/os/macos/aarch64.rs rename to crates/std_detect/src/detect/os/darwin/aarch64.rs index a29968b5c3..3f292c1b1b 100644 --- a/crates/std_detect/src/detect/os/macos/aarch64.rs +++ b/crates/std_detect/src/detect/os/darwin/aarch64.rs @@ -1,4 +1,6 @@ -//! Run-time feature detection for aarch64 on macOS. +//! Run-time feature detection for aarch64 on Darwin (macOS/iOS/tvOS/watchOS/visionOS). +//! +//! use crate::detect::{cache, Feature}; diff --git a/crates/std_detect/tests/cpu-detection.rs b/crates/std_detect/tests/cpu-detection.rs index cecc53afa4..53fbf6d8c1 100644 --- a/crates/std_detect/tests/cpu-detection.rs +++ b/crates/std_detect/tests/cpu-detection.rs @@ -188,8 +188,8 @@ fn aarch64_bsd() { } #[test] -#[cfg(all(target_arch = "aarch64", target_os = "macos"))] -fn aarch64_macos() { +#[cfg(all(target_arch = "aarch64", target_vendor = "apple"))] +fn aarch64_darwin() { println!("asimd: {:?}", is_aarch64_feature_detected!("asimd")); println!("fp: {:?}", is_aarch64_feature_detected!("fp")); println!("fp16: {:?}", is_aarch64_feature_detected!("fp16")); diff --git a/crates/stdarch-test/src/disassembly.rs b/crates/stdarch-test/src/disassembly.rs index 206942a4b4..cb6c008a71 100644 --- a/crates/stdarch-test/src/disassembly.rs +++ b/crates/stdarch-test/src/disassembly.rs @@ -74,8 +74,8 @@ pub(crate) fn disassemble_myself() -> HashSet { let me = env::current_exe().expect("failed to get current exe"); let objdump = env::var("OBJDUMP").unwrap_or_else(|_| "objdump".to_string()); - let add_args = if cfg!(target_os = "macos") && cfg!(target_arch = "aarch64") { - // Target features need to be enabled for LLVM objdump on Macos ARM64 + let add_args = if cfg!(target_vendor = "apple") && cfg!(target_arch = "aarch64") { + // Target features need to be enabled for LLVM objdump on Darwin ARM64 vec!["--mattr=+v8.6a,+crypto,+tme"] } else if cfg!(target_arch = "riscv64") { vec!["--mattr=+zk,+zks,+zbc,+zbb"] diff --git a/triagebot.toml b/triagebot.toml index 81b8611405..082c8cf2c6 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -43,10 +43,10 @@ resolved/implemented on Fuchsia. Could one of you weigh in please? Thanks! """ -[ping.macos] +[ping.apple] +alias = ["macos", "ios", "tvos", "watchos", "visionos"] message = """\ -Hey MacOS Group! This issue or PR could use some MacOS-specific guidance. Could +Hey Apple Group! This issue or PR could use some Darwin-specific guidance. Could one of you weigh in please? Thanks! """ -