Skip to content

Commit

Permalink
Rollup merge of rust-lang#77484 - terhechte:support-ios-catalyst-maca…
Browse files Browse the repository at this point in the history
…bi-arm64-target-triple, r=nikomatsakis

Add support for Arm64 Catalyst on ARM Macs

This is an iteration on rust-lang#63467 which was merged a while ago. In the aforementioned PR, I added support for the `X86_64-apple-ios-macabi` target triple, which is Catalyst, iOS apps running on macOS.

Very soon, Apple will launch ARM64 based Macs which will introduce `aarch64_apple_darwin.rs`, macOS apps using the Darwin ABI running on ARM. This PR adds support for Catalyst apps on ARM Macs: iOS apps compiled for the darwin ABI.

I don't have access to a Apple Developer Transition Kit (DTK), so I can't really test if the generated binaries work correctly. I'm vaguely hopeful that somebody with access to a DTK could give this a spin.
  • Loading branch information
Dylan-DPC committed Oct 17, 2020
2 parents 6b1083c + 80ac68e commit afefc69
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
3 changes: 2 additions & 1 deletion compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2094,9 +2094,10 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
("aarch64", "tvos") => "appletvos",
("x86_64", "tvos") => "appletvsimulator",
("arm", "ios") => "iphoneos",
("aarch64", "ios") if llvm_target.contains("macabi") => "macosx",
("aarch64", "ios") => "iphoneos",
("x86", "ios") => "iphonesimulator",
("x86_64", "ios") if llvm_target.contains("macabi") => "macosx10.15",
("x86_64", "ios") if llvm_target.contains("macabi") => "macosx",
("x86_64", "ios") => "iphonesimulator",
_ => {
sess.err(&format!("unsupported arch `{}` for os `{}`", arch, os));
Expand Down
35 changes: 35 additions & 0 deletions compiler/rustc_target/src/spec/aarch64_apple_ios_macabi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use super::apple_sdk_base::{opts, Arch};
use crate::spec::{LinkerFlavor, Target, TargetOptions};

pub fn target() -> Target {
let base = opts(Arch::Arm64_macabi);
Target {
llvm_target: "arm64-apple-ios14.2-macabi".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "64".to_string(),
target_c_int_width: "32".to_string(),
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".to_string(),
arch: "aarch64".to_string(),
target_os: "ios".to_string(),
target_env: String::new(),
target_vendor: "apple".to_string(),
linker_flavor: LinkerFlavor::Gcc,
options: TargetOptions {
features: "+neon,+fp-armv8,+apple-a12".to_string(),
eliminate_frame_pointer: false,
max_atomic_width: Some(128),
unsupported_abis: super::arm_base::unsupported_abis(),
forces_embed_bitcode: true,
// Taken from a clang build on Xcode 11.4.1.
// These arguments are not actually invoked - they just have
// to look right to pass App Store validation.
bitcode_llvm_cmdline: "-triple\0\
arm64-apple-ios14.2-macabi\0\
-emit-obj\0\
-disable-llvm-passes\0\
-Os\0"
.to_string(),
..base
},
}
}
4 changes: 3 additions & 1 deletion compiler/rustc_target/src/spec/apple_sdk_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub enum Arch {
I386,
X86_64,
X86_64_macabi,
Arm64_macabi,
}

fn target_cpu(arch: Arch) -> String {
Expand All @@ -20,14 +21,15 @@ fn target_cpu(arch: Arch) -> String {
I386 => "yonah",
X86_64 => "core2",
X86_64_macabi => "core2",
Arm64_macabi => "apple-a12",
}
.to_string()
}

fn link_env_remove(arch: Arch) -> Vec<String> {
match arch {
Armv7 | Armv7s | Arm64 | I386 | X86_64 => vec!["MACOSX_DEPLOYMENT_TARGET".to_string()],
X86_64_macabi => vec!["IPHONEOS_DEPLOYMENT_TARGET".to_string()],
X86_64_macabi | Arm64_macabi => vec!["IPHONEOS_DEPLOYMENT_TARGET".to_string()],
}
}

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ supported_targets! {
("armv7-apple-ios", armv7_apple_ios),
("armv7s-apple-ios", armv7s_apple_ios),
("x86_64-apple-ios-macabi", x86_64_apple_ios_macabi),
("aarch64-apple-ios-macabi", aarch64_apple_ios_macabi),
("aarch64-apple-tvos", aarch64_apple_tvos),
("x86_64-apple-tvos", x86_64_apple_tvos),

Expand Down
3 changes: 2 additions & 1 deletion src/doc/rustc/src/platform-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ not available.

target | std | host | notes
-------|-----|------|-------
`aarch64-apple-ios-macabi` | ? | | Apple Catalyst on ARM64
`aarch64-apple-tvos` | * | | ARM64 tvOS
`aarch64-unknown-cloudabi` | ✓ | | ARM64 CloudABI
`aarch64-unknown-freebsd` | ✓ | ✓ | ARM64 FreeBSD
Expand Down Expand Up @@ -203,7 +204,7 @@ target | std | host | notes
`thumbv7a-uwp-windows-msvc` | ✓ | |
`thumbv7neon-unknown-linux-musleabihf` | ? | | Thumb2-mode ARMv7a Linux with NEON, MUSL
`thumbv4t-none-eabi` | * | | ARMv4T T32
`x86_64-apple-ios-macabi` | ✓ | | Apple Catalyst
`x86_64-apple-ios-macabi` | ✓ | | Apple Catalyst on x86_64
`x86_64-apple-tvos` | * | | x86 64-bit tvOS
`x86_64-linux-kernel` | * | | Linux kernel modules
`x86_64-pc-solaris` | ? | |
Expand Down

0 comments on commit afefc69

Please sign in to comment.