Skip to content

Commit 3707800

Browse files
authored
cpufeatures: add iOS support (static ARM64 capabilities only) (#435)
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
1 parent 63d62b9 commit 3707800

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

Diff for: cpufeatures/src/aarch64.rs

+24-1
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,31 @@ pub unsafe fn sysctlbyname(name: &[u8]) -> bool {
135135
value != 0
136136
}
137137

138+
// iOS `check!` macro.
139+
//
140+
// Unfortunately iOS does not provide access to the `sysctl(3)` API which means
141+
// we can only return static values for CPU features which can be assumed to
142+
// be present on all Apple ARM64 hardware.
143+
//
144+
// See discussion on this issue for more information:
145+
// <https://github.com/RustCrypto/utils/issues/378>
146+
#[cfg(target_os = "ios")]
147+
#[macro_export]
148+
#[doc(hidden)]
149+
macro_rules! check {
150+
("aes") => {
151+
true
152+
};
153+
("sha2") => {
154+
true
155+
};
156+
("sha3") => {
157+
false
158+
};
159+
}
160+
138161
// On other targets, runtime CPU feature detection is unavailable
139-
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
162+
#[cfg(not(any(target_os = "ios", target_os = "linux", target_os = "macos")))]
140163
#[macro_export]
141164
#[doc(hidden)]
142165
macro_rules! __detect_target_features {

0 commit comments

Comments
 (0)