Skip to content

Commit

Permalink
Add Apple visionOS support
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinPerez committed Apr 16, 2024
1 parent 7bc7672 commit c7deeb4
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ untrusted = { version = "0.9" }
[target.'cfg(any(target_arch = "aarch64", target_arch = "arm", target_arch = "x86",target_arch = "x86_64"))'.dependencies]
spin = { version = "0.9.8", default-features = false, features = ["once"] }

[target.'cfg(all(any(target_os = "android", target_os = "linux", any(target_os = "ios", target_os = "macos", target_os = "tvos")), any(target_arch = "aarch64", target_arch = "arm")))'.dependencies]
[target.'cfg(all(any(target_os = "android", target_os = "linux", any(target_os = "ios", target_os = "visionos", target_os = "macos", target_os = "tvos")), any(target_arch = "aarch64", target_arch = "arm")))'.dependencies]
libc = { version = "0.2.148", default-features = false }

[target.'cfg(all(target_arch = "aarch64", target_os = "windows"))'.dependencies]
Expand All @@ -175,7 +175,7 @@ wasm-bindgen-test = { version = "0.3.37", default-features = false }
libc = { version = "0.2.148", default-features = false }

[build-dependencies]
cc = { version = "1.0.83", default-features = false }
cc = { version = "1.0.94", default-features = false }

[features]
# These features are documented in the top-level module's documentation.
Expand Down
7 changes: 6 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ const ASM_TARGETS: &[AsmTarget] = &[
arch: AARCH64,
perlasm_format: "ios64",
},
AsmTarget {
oss: MACOS_ABI,
arch: AARCH64,
perlasm_format: "visionos64",
},
AsmTarget {
oss: MACOS_ABI,
arch: X86_64,
Expand Down Expand Up @@ -257,7 +262,7 @@ const NASM: &str = "nasm";

/// Operating systems that have the same ABI as macOS on every architecture
/// mentioned in `ASM_TARGETS`.
const MACOS_ABI: &[&str] = &["ios", MACOS, "tvos"];
const MACOS_ABI: &[&str] = &["ios", MACOS, "tvos", "visionos"];

const MACOS: &str = "macos";
const WINDOWS: &str = "windows";
Expand Down
10 changes: 5 additions & 5 deletions crypto/perlasm/arm-xlate.pl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
else { ""; }
};
my $hidden = sub {
if ($flavour =~ /ios/) { ".private_extern\t".join(',',@_); }
if ($flavour =~ /ios|visionos/) { ".private_extern\t".join(',',@_); }
elsif ($flavour =~ /win64/) { ""; }
else { ".hidden\t".join(',',@_); }
};
Expand Down Expand Up @@ -58,7 +58,7 @@
my $ret;

SWITCH: for ($flavour) {
/ios/ && do { $name = "_$name";
/ios|visionos/ && do { $name = "_$name";
last;
};
}
Expand Down Expand Up @@ -109,7 +109,7 @@
{ ""; }
};
my $section = sub {
if ($flavour =~ /ios/) {
if ($flavour =~ /ios|visionos/) {
if ($_[0] eq ".rodata") {
return ".section\t__TEXT,__const";
}
Expand Down Expand Up @@ -163,7 +163,7 @@ sub expand_line {
# Although the flavour is specified as "linux", it is really used by all
# ELF platforms.
$target_defines = "defined(__ELF__)";
} elsif ($flavour =~ /ios/) {
} elsif ($flavour =~ /ios|visionos/) {
# Although the flavour is specified as "ios", it is really used by all Apple
# platforms.
$target_defines = "defined(__APPLE__)";
Expand Down Expand Up @@ -223,7 +223,7 @@ sub expand_line {
$opcode = eval("\$$mnemonic");
}

if ($flavour =~ /ios/) {
if ($flavour =~ /ios|visionos/) {
# Mach-O and ELF use different syntax for these relocations. Note
# that we require :pg_hi21: to be explicitly listed. It is normally
# optional with adrp instructions.
Expand Down
14 changes: 12 additions & 2 deletions src/cpu/arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,12 @@ fn detect_features() -> u32 {

#[cfg(all(
target_arch = "aarch64",
any(target_os = "ios", target_os = "macos", target_os = "tvos")
any(
target_os = "ios",
target_os = "visionos",
target_os = "macos",
target_os = "tvos"
)
))]
fn detect_features() -> u32 {
// TODO(MSRV 1.64): Use `name: &core::ffi::CStr`.
Expand Down Expand Up @@ -225,7 +230,12 @@ fn detect_features() -> u32 {
target_os = "fuchsia",
all(target_os = "linux", not(target_env = "uclibc")),
target_os = "windows",
any(target_os = "ios", target_os = "macos", target_os = "tvos"),
any(
target_os = "ios",
target_os = "visionos",
target_os = "macos",
target_os = "tvos"
),
))
))]
fn detect_features() -> u32 {
Expand Down
15 changes: 12 additions & 3 deletions src/ec/curve25519/x25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ fn x25519_public_from_private(
let private_key: &[u8; SCALAR_LEN] = private_key.bytes_less_safe().try_into()?;
let private_key = ops::MaskedScalar::from_bytes_masked(*private_key);

#[cfg(all(not(target_os = "ios"), target_arch = "arm"))]
#[cfg(all(
not(any(target_os = "ios", target_os = "visionos")),
target_arch = "arm"
))]
{
if cpu::arm::NEON.available(cpu_features) {
static MONTGOMERY_BASE_POINT: [u8; 32] = [
Expand Down Expand Up @@ -109,7 +112,10 @@ fn x25519_ecdh(
point: &ops::EncodedPoint,
#[allow(unused_variables)] cpu_features: cpu::Features,
) {
#[cfg(all(not(target_os = "ios"), target_arch = "arm"))]
#[cfg(all(
not(any(target_os = "ios", target_os = "visionos")),
target_arch = "arm"
))]
{
if cpu::arm::NEON.available(cpu_features) {
return x25519_neon(out, scalar, point);
Expand Down Expand Up @@ -158,7 +164,10 @@ fn x25519_ecdh(
Ok(())
}

#[cfg(all(not(target_os = "ios"), target_arch = "arm"))]
#[cfg(all(
not(any(target_os = "ios", target_os = "visionos")),
target_arch = "arm"
))]
fn x25519_neon(out: &mut ops::EncodedPoint, scalar: &ops::MaskedScalar, point: &ops::EncodedPoint) {
prefixed_extern! {
fn x25519_NEON(
Expand Down
1 change: 1 addition & 0 deletions src/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ impl crate::sealed::Sealed for SystemRandom {}
target_os = "hermit",
target_os = "illumos",
target_os = "ios",
target_os = "visionos",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
Expand Down

0 comments on commit c7deeb4

Please sign in to comment.