From 79eedef984cb0a4e703e6c2398319d4e818f41e9 Mon Sep 17 00:00:00 2001 From: BlackHoleFox Date: Sun, 23 Oct 2022 15:23:04 -0500 Subject: [PATCH 1/3] Fix x86_64-apple-ios target to use the correct target_abi --- compiler/rustc_target/src/spec/apple/tests.rs | 15 ++++++++++++++ .../rustc_target/src/spec/apple_sdk_base.rs | 20 +++++++++++++------ .../rustc_target/src/spec/x86_64_apple_ios.rs | 2 +- 3 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 compiler/rustc_target/src/spec/apple/tests.rs diff --git a/compiler/rustc_target/src/spec/apple/tests.rs b/compiler/rustc_target/src/spec/apple/tests.rs new file mode 100644 index 0000000000000..23bfb95c1985b --- /dev/null +++ b/compiler/rustc_target/src/spec/apple/tests.rs @@ -0,0 +1,15 @@ +use crate::spec::{aarch64_apple_ios_sim, aarch64_apple_watchos_sim, x86_64_apple_ios}; + +#[test] +fn simulator_targets_set_abi() { + let all_sim_targets = [ + x86_64_apple_ios::target(), + aarch64_apple_ios_sim::target(), + aarch64_apple_watchos_sim::target(), + // TODO: x86_64-apple-tvos and x86_64-apple-watchos-sim + ]; + + for target in all_sim_targets { + assert_eq!(target.abi, "sim") + } +} diff --git a/compiler/rustc_target/src/spec/apple_sdk_base.rs b/compiler/rustc_target/src/spec/apple_sdk_base.rs index 49e302676a7b1..f920ce8444f72 100644 --- a/compiler/rustc_target/src/spec/apple_sdk_base.rs +++ b/compiler/rustc_target/src/spec/apple_sdk_base.rs @@ -1,6 +1,10 @@ use crate::spec::{cvs, TargetOptions}; use std::borrow::Cow; +#[cfg(test)] +#[path = "apple/tests.rs"] +mod tests; + use Arch::*; #[allow(non_camel_case_types)] #[derive(Copy, Clone)] @@ -12,6 +16,7 @@ pub enum Arch { Arm64_32, I386, X86_64, + X86_64_sim, X86_64_macabi, Arm64_macabi, Arm64_sim, @@ -25,7 +30,7 @@ fn target_arch_name(arch: Arch) -> &'static str { Arm64 | Arm64_macabi | Arm64_sim => "arm64", Arm64_32 => "arm64_32", I386 => "i386", - X86_64 | X86_64_macabi => "x86_64", + X86_64 | X86_64_sim | X86_64_macabi => "x86_64", } } @@ -33,7 +38,9 @@ fn target_abi(arch: Arch) -> &'static str { match arch { Armv7 | Armv7k | Armv7s | Arm64 | Arm64_32 | I386 | X86_64 => "", X86_64_macabi | Arm64_macabi => "macabi", - Arm64_sim => "sim", + // x86_64-apple-ios is a simulator target, even though it isn't + // declared that way in the target like the other ones... + Arm64_sim | X86_64_sim => "sim", } } @@ -45,7 +52,7 @@ fn target_cpu(arch: Arch) -> &'static str { Arm64 => "apple-a7", Arm64_32 => "apple-s4", I386 => "yonah", - X86_64 => "core2", + X86_64 | X86_64_sim => "core2", X86_64_macabi => "core2", Arm64_macabi => "apple-a12", Arm64_sim => "apple-a12", @@ -54,7 +61,7 @@ fn target_cpu(arch: Arch) -> &'static str { fn link_env_remove(arch: Arch) -> Cow<'static, [Cow<'static, str>]> { match arch { - Armv7 | Armv7k | Armv7s | Arm64 | Arm64_32 | I386 | X86_64 | Arm64_sim => { + Armv7 | Armv7k | Armv7s | Arm64 | Arm64_32 | I386 | X86_64 | X86_64_sim | Arm64_sim => { cvs!["MACOSX_DEPLOYMENT_TARGET"] } X86_64_macabi | Arm64_macabi => cvs!["IPHONEOS_DEPLOYMENT_TARGET"], @@ -62,11 +69,12 @@ fn link_env_remove(arch: Arch) -> Cow<'static, [Cow<'static, str>]> { } pub fn opts(os: &'static str, arch: Arch) -> TargetOptions { + let abi = target_abi(arch); TargetOptions { - abi: target_abi(arch).into(), + abi: abi.into(), cpu: target_cpu(arch).into(), link_env_remove: link_env_remove(arch), has_thread_local: false, - ..super::apple_base::opts(os, target_arch_name(arch), target_abi(arch)) + ..super::apple_base::opts(os, target_arch_name(arch), abi) } } diff --git a/compiler/rustc_target/src/spec/x86_64_apple_ios.rs b/compiler/rustc_target/src/spec/x86_64_apple_ios.rs index e6143025d6d2c..db23f01c23326 100644 --- a/compiler/rustc_target/src/spec/x86_64_apple_ios.rs +++ b/compiler/rustc_target/src/spec/x86_64_apple_ios.rs @@ -2,7 +2,7 @@ use super::apple_sdk_base::{opts, Arch}; use crate::spec::{StackProbeType, Target, TargetOptions}; pub fn target() -> Target { - let base = opts("ios", Arch::X86_64); + let base = opts("ios", Arch::X86_64_sim); let llvm_target = super::apple_base::ios_sim_llvm_target("x86_64"); Target { From d2a37847809bc3df86afb4c65b5fe5f06d99ce20 Mon Sep 17 00:00:00 2001 From: BlackHoleFox Date: Sun, 23 Oct 2022 15:33:01 -0500 Subject: [PATCH 2/3] Fix x86_64-apple-tvos target to use the correct target_abi --- compiler/rustc_target/src/spec/apple/tests.rs | 8 ++++++-- compiler/rustc_target/src/spec/x86_64_apple_tvos.rs | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_target/src/spec/apple/tests.rs b/compiler/rustc_target/src/spec/apple/tests.rs index 23bfb95c1985b..b45e6e309c119 100644 --- a/compiler/rustc_target/src/spec/apple/tests.rs +++ b/compiler/rustc_target/src/spec/apple/tests.rs @@ -1,12 +1,16 @@ -use crate::spec::{aarch64_apple_ios_sim, aarch64_apple_watchos_sim, x86_64_apple_ios}; +use crate::spec::{ + aarch64_apple_ios_sim, aarch64_apple_watchos_sim, x86_64_apple_ios, x86_64_apple_tvos, +}; #[test] fn simulator_targets_set_abi() { let all_sim_targets = [ x86_64_apple_ios::target(), + x86_64_apple_tvos::target(), aarch64_apple_ios_sim::target(), + // Note: There is currently no ARM64 tvOS simulator target aarch64_apple_watchos_sim::target(), - // TODO: x86_64-apple-tvos and x86_64-apple-watchos-sim + // TODO: x86_64-apple-watchos-sim ]; for target in all_sim_targets { diff --git a/compiler/rustc_target/src/spec/x86_64_apple_tvos.rs b/compiler/rustc_target/src/spec/x86_64_apple_tvos.rs index 3d54da0867cf7..c1fd8e1c8b90a 100644 --- a/compiler/rustc_target/src/spec/x86_64_apple_tvos.rs +++ b/compiler/rustc_target/src/spec/x86_64_apple_tvos.rs @@ -2,7 +2,7 @@ use super::apple_sdk_base::{opts, Arch}; use crate::spec::{StackProbeType, Target, TargetOptions}; pub fn target() -> Target { - let base = opts("tvos", Arch::X86_64); + let base = opts("tvos", Arch::X86_64_sim); Target { llvm_target: "x86_64-apple-tvos".into(), pointer_width: 64, From ffccfa1eedd049c87b1ad828297ae4c4121b2e40 Mon Sep 17 00:00:00 2001 From: BlackHoleFox Date: Sun, 23 Oct 2022 15:41:07 -0500 Subject: [PATCH 3/3] Fix x86_64-apple-watchos-sim target to use the correct target_abi --- compiler/rustc_target/src/spec/apple/tests.rs | 3 ++- compiler/rustc_target/src/spec/apple_sdk_base.rs | 1 + compiler/rustc_target/src/spec/x86_64_apple_watchos_sim.rs | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_target/src/spec/apple/tests.rs b/compiler/rustc_target/src/spec/apple/tests.rs index b45e6e309c119..d062b36742d60 100644 --- a/compiler/rustc_target/src/spec/apple/tests.rs +++ b/compiler/rustc_target/src/spec/apple/tests.rs @@ -1,5 +1,6 @@ use crate::spec::{ aarch64_apple_ios_sim, aarch64_apple_watchos_sim, x86_64_apple_ios, x86_64_apple_tvos, + x86_64_apple_watchos_sim, }; #[test] @@ -7,10 +8,10 @@ fn simulator_targets_set_abi() { let all_sim_targets = [ x86_64_apple_ios::target(), x86_64_apple_tvos::target(), + x86_64_apple_watchos_sim::target(), aarch64_apple_ios_sim::target(), // Note: There is currently no ARM64 tvOS simulator target aarch64_apple_watchos_sim::target(), - // TODO: x86_64-apple-watchos-sim ]; for target in all_sim_targets { diff --git a/compiler/rustc_target/src/spec/apple_sdk_base.rs b/compiler/rustc_target/src/spec/apple_sdk_base.rs index f920ce8444f72..148031b156976 100644 --- a/compiler/rustc_target/src/spec/apple_sdk_base.rs +++ b/compiler/rustc_target/src/spec/apple_sdk_base.rs @@ -15,6 +15,7 @@ pub enum Arch { Arm64, Arm64_32, I386, + #[allow(dead_code)] // Some targets don't use this enum... X86_64, X86_64_sim, X86_64_macabi, diff --git a/compiler/rustc_target/src/spec/x86_64_apple_watchos_sim.rs b/compiler/rustc_target/src/spec/x86_64_apple_watchos_sim.rs index e499b1985e761..550566b2aa754 100644 --- a/compiler/rustc_target/src/spec/x86_64_apple_watchos_sim.rs +++ b/compiler/rustc_target/src/spec/x86_64_apple_watchos_sim.rs @@ -2,7 +2,7 @@ use super::apple_sdk_base::{opts, Arch}; use crate::spec::{StackProbeType, Target, TargetOptions}; pub fn target() -> Target { - let base = opts("watchos", Arch::X86_64); + let base = opts("watchos", Arch::X86_64_sim); let arch = "x86_64"; let llvm_target = super::apple_base::watchos_sim_llvm_target(arch);