From f10fbbbd534e459f98a3337d1f0bf2b23d607906 Mon Sep 17 00:00:00 2001 From: "Ricky (deg4uss3r)" Date: Thu, 4 Feb 2021 09:26:02 -0500 Subject: [PATCH 1/2] added aarch64_apple_ios_sim as a rustc target --- compiler/rustc_codegen_ssa/src/back/link.rs | 1 + .../src/spec/aarch64_apple_ios_sim.rs | 31 +++++++++++++++++++ .../rustc_target/src/spec/apple_sdk_base.rs | 6 +++- compiler/rustc_target/src/spec/mod.rs | 1 + src/doc/rustc/src/platform-support.md | 1 + 5 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 compiler/rustc_target/src/spec/aarch64_apple_ios_sim.rs diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 8bc4e64422370..b5339b455ac92 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -2187,6 +2187,7 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) { ("x86_64", "tvos") => "appletvsimulator", ("arm", "ios") => "iphoneos", ("aarch64", "ios") if llvm_target.contains("macabi") => "macosx", + ("aarch64", "ios") if llvm_target.contains("sim") => "iphonesimulator", ("aarch64", "ios") => "iphoneos", ("x86", "ios") => "iphonesimulator", ("x86_64", "ios") if llvm_target.contains("macabi") => "macosx", diff --git a/compiler/rustc_target/src/spec/aarch64_apple_ios_sim.rs b/compiler/rustc_target/src/spec/aarch64_apple_ios_sim.rs new file mode 100644 index 0000000000000..de4c6b44368da --- /dev/null +++ b/compiler/rustc_target/src/spec/aarch64_apple_ios_sim.rs @@ -0,0 +1,31 @@ +use super::apple_sdk_base::{opts, Arch}; +use crate::spec::{Target, TargetOptions}; + +pub fn target() -> Target { + let base = opts("ios", Arch::Arm64_sim); + Target { + llvm_target: "arm64-apple-ios-simulator".to_string(), + pointer_width: 64, + data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".to_string(), + arch: "aarch64".to_string(), + options: TargetOptions { + features: "+neon,+fp-armv8,+apple-a7".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.0-simulator\0\ + -emit-obj\0\ + -disable-llvm-passes\0\ + -target-abi\0\ + darwinpcs\0\ + -Os\0" + .to_string(), + ..base + }, + } +} diff --git a/compiler/rustc_target/src/spec/apple_sdk_base.rs b/compiler/rustc_target/src/spec/apple_sdk_base.rs index d894f7599377e..538c4ca86974f 100644 --- a/compiler/rustc_target/src/spec/apple_sdk_base.rs +++ b/compiler/rustc_target/src/spec/apple_sdk_base.rs @@ -11,6 +11,7 @@ pub enum Arch { X86_64, X86_64_macabi, Arm64_macabi, + Arm64_sim, } fn target_cpu(arch: Arch) -> String { @@ -22,13 +23,16 @@ fn target_cpu(arch: Arch) -> String { X86_64 => "core2", X86_64_macabi => "core2", Arm64_macabi => "apple-a12", + Arm64_sim => "apple-a12", } .to_string() } fn link_env_remove(arch: Arch) -> Vec { match arch { - Armv7 | Armv7s | Arm64 | I386 | X86_64 => vec!["MACOSX_DEPLOYMENT_TARGET".to_string()], + Armv7 | Armv7s | Arm64 | I386 | X86_64 | Arm64_sim => { + vec!["MACOSX_DEPLOYMENT_TARGET".to_string()] + } X86_64_macabi | Arm64_macabi => vec!["IPHONEOS_DEPLOYMENT_TARGET".to_string()], } } diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 7a93bac72ca07..962374a21b2c7 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -727,6 +727,7 @@ supported_targets! { ("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-ios-sim", aarch64_apple_ios_sim), ("aarch64-apple-tvos", aarch64_apple_tvos), ("x86_64-apple-tvos", x86_64_apple_tvos), diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index eb74041964701..641650b5b0942 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -153,6 +153,7 @@ not available. target | std | host | notes -------|-----|------|------- `aarch64-apple-ios-macabi` | ? | | Apple Catalyst on ARM64 +`aarch64-apple-ios-sim` | ? | | Apple iOS Simulator on ARM64 `aarch64-apple-tvos` | * | | ARM64 tvOS `aarch64-unknown-freebsd` | ✓ | ✓ | ARM64 FreeBSD `aarch64-unknown-hermit` | ? | | From 8d6ad11ab2490e95e6cf6daa18c2684e7382bb22 Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Sun, 14 Feb 2021 16:33:03 +0100 Subject: [PATCH 2/2] 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. --- .../src/spec/aarch64_apple_ios_sim.rs | 10 ++++++++- compiler/rustc_target/src/spec/apple_base.rs | 21 ++++++++++++++----- src/doc/rustc/src/platform-support.md | 2 +- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_target/src/spec/aarch64_apple_ios_sim.rs b/compiler/rustc_target/src/spec/aarch64_apple_ios_sim.rs index de4c6b44368da..e594ceec1b78c 100644 --- a/compiler/rustc_target/src/spec/aarch64_apple_ios_sim.rs +++ b/compiler/rustc_target/src/spec/aarch64_apple_ios_sim.rs @@ -3,8 +3,16 @@ use crate::spec::{Target, TargetOptions}; pub fn target() -> Target { let base = opts("ios", Arch::Arm64_sim); + + // Clang automatically chooses a more specific target based on + // IPHONEOS_DEPLOYMENT_TARGET. + // This is required for the simulator target to pick the right + // MACH-O commands, so we do too. + let arch = "arm64"; + let llvm_target = super::apple_base::ios_sim_llvm_target(arch); + Target { - llvm_target: "arm64-apple-ios-simulator".to_string(), + llvm_target: llvm_target, pointer_width: 64, data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".to_string(), arch: "aarch64".to_string(), diff --git a/compiler/rustc_target/src/spec/apple_base.rs b/compiler/rustc_target/src/spec/apple_base.rs index 3b458962b3d07..23f1357af163f 100644 --- a/compiler/rustc_target/src/spec/apple_base.rs +++ b/compiler/rustc_target/src/spec/apple_base.rs @@ -54,14 +54,16 @@ pub fn opts(os: &str) -> TargetOptions { } } -fn macos_deployment_target() -> (u32, u32) { - let deployment_target = env::var("MACOSX_DEPLOYMENT_TARGET").ok(); - let version = deployment_target +fn deployment_target(var_name: &str) -> Option<(u32, u32)> { + let deployment_target = env::var(var_name).ok(); + deployment_target .as_ref() .and_then(|s| s.split_once('.')) - .and_then(|(a, b)| a.parse::().and_then(|a| b.parse::().map(|b| (a, b))).ok()); + .and_then(|(a, b)| a.parse::().and_then(|a| b.parse::().map(|b| (a, b))).ok()) +} - version.unwrap_or((10, 7)) +fn macos_deployment_target() -> (u32, u32) { + deployment_target("MACOSX_DEPLOYMENT_TARGET").unwrap_or((10, 7)) } pub fn macos_llvm_target(arch: &str) -> String { @@ -84,3 +86,12 @@ pub fn macos_link_env_remove() -> Vec { env_remove.push("IPHONEOS_DEPLOYMENT_TARGET".to_string()); env_remove } + +fn ios_deployment_target() -> (u32, u32) { + deployment_target("IPHONEOS_DEPLOYMENT_TARGET").unwrap_or((7, 0)) +} + +pub fn ios_sim_llvm_target(arch: &str) -> String { + let (major, minor) = ios_deployment_target(); + format!("{}-apple-ios{}.{}.0-simulator", arch, major, minor) +} diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index 641650b5b0942..ef8fe480fc4bb 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -153,7 +153,7 @@ not available. target | std | host | notes -------|-----|------|------- `aarch64-apple-ios-macabi` | ? | | Apple Catalyst on ARM64 -`aarch64-apple-ios-sim` | ? | | Apple iOS Simulator on ARM64 +`aarch64-apple-ios-sim` | ? | | Apple iOS Simulator on ARM64 `aarch64-apple-tvos` | * | | ARM64 tvOS `aarch64-unknown-freebsd` | ✓ | ✓ | ARM64 FreeBSD `aarch64-unknown-hermit` | ? | |