Skip to content

Commit

Permalink
cpufeatures: add iOS support (static ARM64 capabilities only) (#435)
Browse files Browse the repository at this point in the history
All Apple ARM64 hardware has the same baseline set of statically known
capabilities which can be assumed on all iOS (and macOS) platforms.

This commit adds support for those statically known capabilities on iOS.

Unfortunately it does not appear to be possible to access the
`sysctl(3)` namespace on iOS in order to determine the availability of
other CPU features which aren't part of this baseline set the same way
we can on macOS, so a static capability set is the best we can do.

See this issue for more information:

#378
  • Loading branch information
tarcieri authored May 26, 2021
1 parent 63d62b9 commit 3707800
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion cpufeatures/src/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,31 @@ pub unsafe fn sysctlbyname(name: &[u8]) -> bool {
value != 0
}

// iOS `check!` macro.
//
// Unfortunately iOS does not provide access to the `sysctl(3)` API which means
// we can only return static values for CPU features which can be assumed to
// be present on all Apple ARM64 hardware.
//
// See discussion on this issue for more information:
// <https://github.com/RustCrypto/utils/issues/378>
#[cfg(target_os = "ios")]
#[macro_export]
#[doc(hidden)]
macro_rules! check {
("aes") => {
true
};
("sha2") => {
true
};
("sha3") => {
false
};
}

// On other targets, runtime CPU feature detection is unavailable
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
#[cfg(not(any(target_os = "ios", target_os = "linux", target_os = "macos")))]
#[macro_export]
#[doc(hidden)]
macro_rules! __detect_target_features {
Expand Down

0 comments on commit 3707800

Please sign in to comment.