Skip to content

Commit 882fd69

Browse files
authored
Rollup merge of #81966 - deg4uss3r:degausser/aarch64_apple_ios_sim, r=shepmaster
Add new `rustc` target for Arm64 machines that can target the iphonesimulator This PR lands a new target (`aarch64-apple-ios-sim`) that targets arm64 iphone simulator, previously unreachable from Apple Silicon machines. resolves #81632 r? `@shepmaster`
2 parents 4c1f195 + 8d6ad11 commit 882fd69

File tree

6 files changed

+63
-6
lines changed

6 files changed

+63
-6
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2193,6 +2193,7 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
21932193
("x86_64", "tvos") => "appletvsimulator",
21942194
("arm", "ios") => "iphoneos",
21952195
("aarch64", "ios") if llvm_target.contains("macabi") => "macosx",
2196+
("aarch64", "ios") if llvm_target.contains("sim") => "iphonesimulator",
21962197
("aarch64", "ios") => "iphoneos",
21972198
("x86", "ios") => "iphonesimulator",
21982199
("x86_64", "ios") if llvm_target.contains("macabi") => "macosx",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use super::apple_sdk_base::{opts, Arch};
2+
use crate::spec::{Target, TargetOptions};
3+
4+
pub fn target() -> Target {
5+
let base = opts("ios", Arch::Arm64_sim);
6+
7+
// Clang automatically chooses a more specific target based on
8+
// IPHONEOS_DEPLOYMENT_TARGET.
9+
// This is required for the simulator target to pick the right
10+
// MACH-O commands, so we do too.
11+
let arch = "arm64";
12+
let llvm_target = super::apple_base::ios_sim_llvm_target(arch);
13+
14+
Target {
15+
llvm_target: llvm_target,
16+
pointer_width: 64,
17+
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".to_string(),
18+
arch: "aarch64".to_string(),
19+
options: TargetOptions {
20+
features: "+neon,+fp-armv8,+apple-a7".to_string(),
21+
eliminate_frame_pointer: false,
22+
max_atomic_width: Some(128),
23+
unsupported_abis: super::arm_base::unsupported_abis(),
24+
forces_embed_bitcode: true,
25+
// Taken from a clang build on Xcode 11.4.1.
26+
// These arguments are not actually invoked - they just have
27+
// to look right to pass App Store validation.
28+
bitcode_llvm_cmdline: "-triple\0\
29+
arm64-apple-ios14.0-simulator\0\
30+
-emit-obj\0\
31+
-disable-llvm-passes\0\
32+
-target-abi\0\
33+
darwinpcs\0\
34+
-Os\0"
35+
.to_string(),
36+
..base
37+
},
38+
}
39+
}

compiler/rustc_target/src/spec/apple_base.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,16 @@ pub fn opts(os: &str) -> TargetOptions {
5454
}
5555
}
5656

57-
fn macos_deployment_target() -> (u32, u32) {
58-
let deployment_target = env::var("MACOSX_DEPLOYMENT_TARGET").ok();
59-
let version = deployment_target
57+
fn deployment_target(var_name: &str) -> Option<(u32, u32)> {
58+
let deployment_target = env::var(var_name).ok();
59+
deployment_target
6060
.as_ref()
6161
.and_then(|s| s.split_once('.'))
62-
.and_then(|(a, b)| a.parse::<u32>().and_then(|a| b.parse::<u32>().map(|b| (a, b))).ok());
62+
.and_then(|(a, b)| a.parse::<u32>().and_then(|a| b.parse::<u32>().map(|b| (a, b))).ok())
63+
}
6364

64-
version.unwrap_or((10, 7))
65+
fn macos_deployment_target() -> (u32, u32) {
66+
deployment_target("MACOSX_DEPLOYMENT_TARGET").unwrap_or((10, 7))
6567
}
6668

6769
pub fn macos_llvm_target(arch: &str) -> String {
@@ -84,3 +86,12 @@ pub fn macos_link_env_remove() -> Vec<String> {
8486
env_remove.push("IPHONEOS_DEPLOYMENT_TARGET".to_string());
8587
env_remove
8688
}
89+
90+
fn ios_deployment_target() -> (u32, u32) {
91+
deployment_target("IPHONEOS_DEPLOYMENT_TARGET").unwrap_or((7, 0))
92+
}
93+
94+
pub fn ios_sim_llvm_target(arch: &str) -> String {
95+
let (major, minor) = ios_deployment_target();
96+
format!("{}-apple-ios{}.{}.0-simulator", arch, major, minor)
97+
}

compiler/rustc_target/src/spec/apple_sdk_base.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub enum Arch {
1111
X86_64,
1212
X86_64_macabi,
1313
Arm64_macabi,
14+
Arm64_sim,
1415
}
1516

1617
fn target_cpu(arch: Arch) -> String {
@@ -22,13 +23,16 @@ fn target_cpu(arch: Arch) -> String {
2223
X86_64 => "core2",
2324
X86_64_macabi => "core2",
2425
Arm64_macabi => "apple-a12",
26+
Arm64_sim => "apple-a12",
2527
}
2628
.to_string()
2729
}
2830

2931
fn link_env_remove(arch: Arch) -> Vec<String> {
3032
match arch {
31-
Armv7 | Armv7s | Arm64 | I386 | X86_64 => vec!["MACOSX_DEPLOYMENT_TARGET".to_string()],
33+
Armv7 | Armv7s | Arm64 | I386 | X86_64 | Arm64_sim => {
34+
vec!["MACOSX_DEPLOYMENT_TARGET".to_string()]
35+
}
3236
X86_64_macabi | Arm64_macabi => vec!["IPHONEOS_DEPLOYMENT_TARGET".to_string()],
3337
}
3438
}

compiler/rustc_target/src/spec/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,7 @@ supported_targets! {
727727
("armv7s-apple-ios", armv7s_apple_ios),
728728
("x86_64-apple-ios-macabi", x86_64_apple_ios_macabi),
729729
("aarch64-apple-ios-macabi", aarch64_apple_ios_macabi),
730+
("aarch64-apple-ios-sim", aarch64_apple_ios_sim),
730731
("aarch64-apple-tvos", aarch64_apple_tvos),
731732
("x86_64-apple-tvos", x86_64_apple_tvos),
732733

src/doc/rustc/src/platform-support.md

+1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ not available.
153153
target | std | host | notes
154154
-------|-----|------|-------
155155
`aarch64-apple-ios-macabi` | ? | | Apple Catalyst on ARM64
156+
`aarch64-apple-ios-sim` | ? | | Apple iOS Simulator on ARM64
156157
`aarch64-apple-tvos` | * | | ARM64 tvOS
157158
`aarch64-unknown-freebsd` | ✓ | ✓ | ARM64 FreeBSD
158159
`aarch64-unknown-hermit` | ? | |

0 commit comments

Comments
 (0)