Skip to content

Commit

Permalink
Add *-apple-{visionos,watchos} support; CI: build tvOS,visionOS,watchOS.
Browse files Browse the repository at this point in the history
Change visionOS and watchOS to use the assembly implementations like
iOS, macOS, and tvOS were already. The large tables for P-256 and
Curve25519 probably aren't appropriate for watchOS; that will be
addressed later, maybe by merging BoringSSL commit
20c9406.

Use the same C compiler options for all these targets.
  • Loading branch information
briansmith committed Jun 21, 2024
1 parent 481462e commit 1b8f998
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 16 deletions.
30 changes: 29 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,11 @@ jobs:
- # Default

target:
- aarch64-apple-ios
- aarch64-apple-darwin
- aarch64-apple-ios
# - aarch64-apple-tvos Tier 3; handled below
# - aarch64-apple-visionos Tier 3; handled below
# - aarch64-apple-watchos Tier 3; handled below
- aarch64-linux-android
- aarch64-pc-windows-msvc
- aarch64-unknown-linux-gnu
Expand Down Expand Up @@ -205,6 +208,28 @@ jobs:
# TODO: Run in the emulator.
cargo_options: --no-run

- target: aarch64-apple-tvos
host_os: macos-14
rust_channel: nightly
mode: --release
# TODO: Run in the emulator.
cargo_options: --no-run -Z build-std

- target: aarch64-apple-visionos
host_os: macos-14
rust_channel: nightly
mode: --release
xcode_version: 15.2
# TODO: Run in the emulator.
cargo_options: --no-run -Z build-std

- target: aarch64-apple-watchos
host_os: macos-14
rust_channel: nightly
mode: --release
# TODO: Run in the emulator.
cargo_options: --no-run -Z build-std

- target: aarch64-linux-android
host_os: ubuntu-22.04
# TODO: https://github.com/briansmith/ring/issues/486
Expand Down Expand Up @@ -316,6 +341,9 @@ jobs:
echo "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\Llvm\x64\bin" >> $GITHUB_PATH
shell: bash

- if: ${{ matrix.xcode_version != '' }}
run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode_version }}.app

- if: ${{ !contains(matrix.host_os, 'windows') }}
run: |
mk/cargo.sh +${{ matrix.rust_channel }} test -vv --target=${{ matrix.target }} ${{ matrix.cargo_options }} ${{ matrix.features }} ${{ matrix.mode }}
Expand Down
10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,12 @@ 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_arch = "aarch64", target_arch = "arm"), any(target_os = "android", target_os = "linux")))'.dependencies]
libc = { version = "0.2.148", default-features = false }

[target.'cfg(all(target_arch = "aarch64", target_vendor = "apple", any(target_os = "ios", target_os = "macos", target_os = "tvos", target_os = "visionos", target_os = "watchos")))'.dependencies]
libc = { version = "0.2.155", default-features = false }

[target.'cfg(all(target_arch = "aarch64", target_os = "windows"))'.dependencies]
windows-sys = { version = "0.52", features = ["Win32_Foundation", "Win32_System_Threading"] }

Expand All @@ -176,6 +179,11 @@ libc = { version = "0.2.148", default-features = false }
[build-dependencies]
cc = { version = "1.0.83", default-features = false }

# At least 1.0.93 is requried for visionOS, but some versions around that point
# have bugs that seem to have been fixed in 1.0.97 or so.
[target.'cfg(all(target_vendor = "apple", target_os = "visionos"))'.build-dependencies]
cc = { version = "1.0.97", default-features = false }

[features]
# These features are documented in the top-level module's documentation.
default = ["alloc", "dev_urandom_fallback"]
Expand Down
9 changes: 4 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,12 @@ const ASM_TARGETS: &[AsmTarget] = &[
perlasm_format: "elf",
},
AsmTarget {
oss: MACOS_ABI,
oss: APPLE_ABI,
arch: AARCH64,
perlasm_format: "ios64",
},
AsmTarget {
oss: MACOS_ABI,
oss: APPLE_ABI,
arch: X86_64,
perlasm_format: "macosx",
},
Expand Down Expand Up @@ -255,9 +255,8 @@ 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 APPLE_ABI: &[&str] = &["ios", "macos", "tvos", "visionos", "watchos"];

const MACOS: &str = "macos";
const WINDOWS: &str = "windows";

fn main() {
Expand Down Expand Up @@ -562,7 +561,7 @@ fn configure_cc(c: &mut cc::Build, target: &Target, c_root_dir: &Path, include_d
let _ = c.flag(f);
}

if target.os.as_str() == MACOS {
if APPLE_ABI.contains(&target.os.as_str()) {
// ``-gfull`` is required for Darwin's |-dead_strip|.
let _ = c.flag("-gfull");
} else if !compiler.is_like_msvc() {
Expand Down
13 changes: 11 additions & 2 deletions mk/install-build-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ case ${target-} in
esac

case ${target-} in
aarch64-apple-tvos | aarch64-apple-tvos-sim | \
aarch64-apple-visionos | aarch64-apple-visionos-sim | \
aarch64-apple-watchos | aarch64-apple-watchos-sim)
build_std=1
;;
aarch64-unknown-linux-gnu)
# Clang is needed for code coverage.
use_clang=1
Expand Down Expand Up @@ -214,8 +219,12 @@ esac

rustup toolchain install --no-self-update --profile=minimal ${toolchain}
if [ -n "${target-}" ]; then
rustup target add --toolchain=${toolchain} ${target}
if [ -n "${build_std-}" ]; then
rustup +${toolchain} component add rust-src
else
rustup +${toolchain} target add ${target}
fi
fi
if [ -n "${RING_COVERAGE-}" ]; then
rustup toolchain install --profile=minimal ${toolchain} --component llvm-tools-preview
rustup +${toolchain} component add llvm-tools-preview
fi
2 changes: 1 addition & 1 deletion src/cpu/arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ mod abi_assumptions {

cfg_if::cfg_if! {
if #[cfg(all(target_arch = "aarch64",
any(target_os = "ios", target_os = "macos", target_os = "tvos")))] {
any(target_os = "ios", target_os = "macos", target_os = "tvos", target_os = "visionos", target_os = "watchos")))] {
mod darwin;
use darwin as detect;
} else if #[cfg(all(target_arch = "aarch64", target_os = "fuchsia"))] {
Expand Down
6 changes: 3 additions & 3 deletions src/ec/curve25519/x25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ 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(target_vendor = "apple"), target_arch = "arm"))]
{
if cpu::arm::NEON.available(cpu_features) {
static MONTGOMERY_BASE_POINT: [u8; 32] = [
Expand Down Expand Up @@ -108,7 +108,7 @@ 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(target_vendor = "apple"), target_arch = "arm"))]
{
if cpu::arm::NEON.available(cpu_features) {
return x25519_neon(out, scalar, point);
Expand Down Expand Up @@ -157,7 +157,7 @@ fn x25519_ecdh(
Ok(())
}

#[cfg(all(not(target_os = "ios"), target_arch = "arm"))]
#[cfg(all(not(target_vendor = "apple"), target_arch = "arm"))]
fn x25519_neon(out: &mut ops::EncodedPoint, scalar: &ops::MaskedScalar, point: &ops::EncodedPoint) {
prefixed_extern! {
fn x25519_NEON(
Expand Down
11 changes: 11 additions & 0 deletions src/polyfill/cstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

#![cfg(all(
target_vendor = "apple",
any(
target_os = "ios",
target_os = "macos",
target_os = "tvos",
target_os = "visionos",
target_os = "watchos"
)
))]

//! Work around lack of `core::ffi::CStr` prior to Rust 1.64, and the lack of
//! `const fn` support for `CStr` in later versions.

Expand Down
13 changes: 10 additions & 3 deletions src/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,23 @@ impl crate::sealed::Sealed for SystemRandom {}
target_os = "hermit",
target_os = "hurd",
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 = "tvos",
target_os = "vita",
target_os = "windows",
all(
target_vendor = "apple",
any(
target_os = "ios",
target_os = "macos",
target_os = "tvos",
target_os = "visionos",
target_os = "watchos",
)
),
all(
target_arch = "wasm32",
any(
Expand Down

0 comments on commit 1b8f998

Please sign in to comment.