Skip to content

Commit 8d6ad11

Browse files
badboyRicky (deg4uss3r)
authored and
Ricky (deg4uss3r)
committed
iOS simulator: pick the target based on the environment variable
LLVM picks the right things to put into the compiled object file based on the target deployment version. We need to communicate it through the target triple. Only with that LLVM will use the right commands in the file to make it look and behave like code compiled for the arm64 iOS simulator target.
1 parent f10fbbb commit 8d6ad11

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

compiler/rustc_target/src/spec/aarch64_apple_ios_sim.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@ use crate::spec::{Target, TargetOptions};
33

44
pub fn target() -> Target {
55
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+
614
Target {
7-
llvm_target: "arm64-apple-ios-simulator".to_string(),
15+
llvm_target: llvm_target,
816
pointer_width: 64,
917
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".to_string(),
1018
arch: "aarch64".to_string(),

compiler/rustc_target/src/spec/apple_base.rs

Lines changed: 16 additions & 5 deletions
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+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +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
156+
`aarch64-apple-ios-sim` | ? | | Apple iOS Simulator on ARM64
157157
`aarch64-apple-tvos` | * | | ARM64 tvOS
158158
`aarch64-unknown-freebsd` | ✓ | ✓ | ARM64 FreeBSD
159159
`aarch64-unknown-hermit` | ? | |

0 commit comments

Comments
 (0)