Skip to content

Commit ae948c6

Browse files
committed
Cleanup Apple target specifications
1 parent de0ab1c commit ae948c6

17 files changed

+108
-109
lines changed

compiler/rustc_target/src/spec/aarch64_apple_darwin.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@ pub fn target() -> Target {
1212

1313
base.link_env_remove.to_mut().extend(macos_link_env_remove());
1414

15-
// Clang automatically chooses a more specific target based on
16-
// MACOSX_DEPLOYMENT_TARGET. To enable cross-language LTO to work
17-
// correctly, we do too.
18-
let llvm_target = macos_llvm_target(arch.target_name());
19-
2015
Target {
21-
llvm_target: llvm_target.into(),
16+
// Clang automatically chooses a more specific target based on
17+
// MACOSX_DEPLOYMENT_TARGET. To enable cross-language LTO to work
18+
// correctly, we do too.
19+
llvm_target: macos_llvm_target(arch).into(),
2220
pointer_width: 64,
2321
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
24-
arch: "aarch64".into(),
22+
arch: arch.target_arch(),
2523
options: TargetOptions {
2624
mcount: "\u{1}mcount".into(),
2725
frame_pointer: FramePointer::NonLeaf,

compiler/rustc_target/src/spec/aarch64_apple_ios.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@ use super::apple_base::{ios_llvm_target, opts, Arch};
22
use crate::spec::{FramePointer, Target, TargetOptions};
33

44
pub fn target() -> Target {
5-
// Clang automatically chooses a more specific target based on
6-
// IPHONEOS_DEPLOYMENT_TARGET.
7-
// This is required for the target to pick the right
8-
// MACH-O commands, so we do too.
95
let arch = Arch::Arm64;
10-
let llvm_target = ios_llvm_target(arch);
11-
126
Target {
13-
llvm_target: llvm_target.into(),
7+
// Clang automatically chooses a more specific target based on
8+
// IPHONEOS_DEPLOYMENT_TARGET.
9+
// This is required for the target to pick the right
10+
// MACH-O commands, so we do too.
11+
llvm_target: ios_llvm_target(arch).into(),
1412
pointer_width: 64,
1513
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
16-
arch: "aarch64".into(),
14+
arch: arch.target_arch(),
1715
options: TargetOptions {
1816
features: "+neon,+fp-armv8,+apple-a7".into(),
1917
max_atomic_width: Some(128),

compiler/rustc_target/src/spec/aarch64_apple_ios_macabi.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, Target, TargetOptions};
44
pub fn target() -> Target {
55
let llvm_target = "arm64-apple-ios14.0-macabi";
66

7-
let mut base = opts("ios", Arch::Arm64_macabi);
7+
let arch = Arch::Arm64_macabi;
8+
let mut base = opts("ios", arch);
89
base.add_pre_link_args(LinkerFlavor::Darwin(Cc::Yes, Lld::No), &["-target", llvm_target]);
910

1011
Target {
1112
llvm_target: llvm_target.into(),
1213
pointer_width: 64,
1314
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
14-
arch: "aarch64".into(),
15+
arch: arch.target_arch(),
1516
options: TargetOptions {
1617
features: "+neon,+fp-armv8,+apple-a12".into(),
1718
max_atomic_width: Some(128),

compiler/rustc_target/src/spec/aarch64_apple_ios_sim.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@ use crate::spec::{FramePointer, Target, TargetOptions};
33

44
pub fn target() -> Target {
55
let arch = Arch::Arm64_sim;
6-
let base = opts("ios", arch);
7-
8-
// Clang automatically chooses a more specific target based on
9-
// IPHONEOS_DEPLOYMENT_TARGET.
10-
// This is required for the simulator target to pick the right
11-
// MACH-O commands, so we do too.
12-
let llvm_target = ios_sim_llvm_target(arch);
13-
146
Target {
15-
llvm_target: llvm_target.into(),
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+
llvm_target: ios_sim_llvm_target(arch).into(),
1612
pointer_width: 64,
1713
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
18-
arch: "aarch64".into(),
14+
arch: arch.target_arch(),
1915
options: TargetOptions {
2016
features: "+neon,+fp-armv8,+apple-a7".into(),
2117
max_atomic_width: Some(128),
@@ -32,7 +28,7 @@ pub fn target() -> Target {
3228
darwinpcs\0\
3329
-Os\0"
3430
.into(),
35-
..base
31+
..opts("ios", arch)
3632
},
3733
}
3834
}

compiler/rustc_target/src/spec/aarch64_apple_tvos.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ use super::apple_base::{opts, Arch};
22
use crate::spec::{FramePointer, Target, TargetOptions};
33

44
pub fn target() -> Target {
5+
let arch = Arch::Arm64;
56
Target {
67
llvm_target: "arm64-apple-tvos".into(),
78
pointer_width: 64,
89
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
9-
arch: "aarch64".into(),
10+
arch: arch.target_arch(),
1011
options: TargetOptions {
1112
features: "+neon,+fp-armv8,+apple-a7".into(),
1213
max_atomic_width: Some(128),
1314
forces_embed_bitcode: true,
1415
frame_pointer: FramePointer::NonLeaf,
15-
..opts("tvos", Arch::Arm64)
16+
..opts("tvos", arch)
1617
},
1718
}
1819
}

compiler/rustc_target/src/spec/aarch64_apple_watchos_sim.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@ use crate::spec::{FramePointer, Target, TargetOptions};
33

44
pub fn target() -> Target {
55
let arch = Arch::Arm64_sim;
6-
let base = opts("watchos", arch);
7-
8-
// Clang automatically chooses a more specific target based on
9-
// WATCHOS_DEPLOYMENT_TARGET.
10-
// This is required for the simulator target to pick the right
11-
// MACH-O commands, so we do too.
12-
let llvm_target = watchos_sim_llvm_target(arch);
13-
146
Target {
15-
llvm_target: llvm_target.into(),
7+
// Clang automatically chooses a more specific target based on
8+
// WATCHOS_DEPLOYMENT_TARGET.
9+
// This is required for the simulator target to pick the right
10+
// MACH-O commands, so we do too.
11+
llvm_target: watchos_sim_llvm_target(arch).into(),
1612
pointer_width: 64,
1713
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
18-
arch: "aarch64".into(),
14+
arch: arch.target_arch(),
1915
options: TargetOptions {
2016
features: "+neon,+fp-armv8,+apple-a7".into(),
2117
max_atomic_width: Some(128),
@@ -32,7 +28,7 @@ pub fn target() -> Target {
3228
darwinpcs\0\
3329
-Os\0"
3430
.into(),
35-
..base
31+
..opts("watchos", arch)
3632
},
3733
}
3834
}

compiler/rustc_target/src/spec/apple_base.rs

+27-12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub enum Arch {
1717
Arm64,
1818
Arm64_32,
1919
I386,
20+
I686,
2021
X86_64,
2122
X86_64_sim,
2223
X86_64_macabi,
@@ -33,13 +34,23 @@ impl Arch {
3334
Arm64 | Arm64_macabi | Arm64_sim => "arm64",
3435
Arm64_32 => "arm64_32",
3536
I386 => "i386",
37+
I686 => "i686",
3638
X86_64 | X86_64_sim | X86_64_macabi => "x86_64",
3739
}
3840
}
3941

42+
pub fn target_arch(self) -> Cow<'static, str> {
43+
Cow::Borrowed(match self {
44+
Armv7 | Armv7k | Armv7s => "arm",
45+
Arm64 | Arm64_32 | Arm64_macabi | Arm64_sim => "aarch64",
46+
I386 | I686 => "x86",
47+
X86_64 | X86_64_sim | X86_64_macabi => "x86_64",
48+
})
49+
}
50+
4051
fn target_abi(self) -> &'static str {
4152
match self {
42-
Armv7 | Armv7k | Armv7s | Arm64 | Arm64_32 | I386 | X86_64 => "",
53+
Armv7 | Armv7k | Armv7s | Arm64 | Arm64_32 | I386 | I686 | X86_64 => "",
4354
X86_64_macabi | Arm64_macabi => "macabi",
4455
// x86_64-apple-ios is a simulator target, even though it isn't
4556
// declared that way in the target like the other ones...
@@ -54,7 +65,7 @@ impl Arch {
5465
Armv7s => "cortex-a9",
5566
Arm64 => "apple-a7",
5667
Arm64_32 => "apple-s4",
57-
I386 => "yonah",
68+
I386 | I686 => "yonah",
5869
X86_64 | X86_64_sim => "core2",
5970
X86_64_macabi => "core2",
6071
Arm64_macabi => "apple-a12",
@@ -64,15 +75,16 @@ impl Arch {
6475

6576
fn link_env_remove(self) -> StaticCow<[StaticCow<str>]> {
6677
match self {
67-
Armv7 | Armv7k | Armv7s | Arm64 | Arm64_32 | I386 | X86_64 | X86_64_sim | Arm64_sim => {
78+
Armv7 | Armv7k | Armv7s | Arm64 | Arm64_32 | I386 | I686 | X86_64 | X86_64_sim
79+
| Arm64_sim => {
6880
cvs!["MACOSX_DEPLOYMENT_TARGET"]
6981
}
7082
X86_64_macabi | Arm64_macabi => cvs!["IPHONEOS_DEPLOYMENT_TARGET"],
7183
}
7284
}
7385
}
7486

75-
fn pre_link_args(os: &'static str, arch: &'static str, abi: &'static str) -> LinkArgs {
87+
fn pre_link_args(os: &'static str, arch: Arch, abi: &'static str) -> LinkArgs {
7688
let platform_name: StaticCow<str> = match abi {
7789
"sim" => format!("{}-simulator", os).into(),
7890
"macabi" => "mac-catalyst".into(),
@@ -88,6 +100,8 @@ fn pre_link_args(os: &'static str, arch: &'static str, abi: &'static str) -> Lin
88100
}
89101
.into();
90102

103+
let arch = arch.target_name();
104+
91105
let mut args = TargetOptions::link_args(
92106
LinkerFlavor::Darwin(Cc::No, Lld::No),
93107
&["-arch", arch, "-platform_version"],
@@ -118,7 +132,7 @@ pub fn opts(os: &'static str, arch: Arch) -> TargetOptions {
118132
// TLS is flagged as enabled if it looks to be supported. The architecture
119133
// only matters for default deployment target which is 11.0 for ARM64 and
120134
// 10.7 for everything else.
121-
let has_thread_local = os == "macos" && macos_deployment_target("x86_64") >= (10, 7);
135+
let has_thread_local = os == "macos" && macos_deployment_target(Arch::X86_64) >= (10, 7);
122136

123137
let abi = arch.target_abi();
124138

@@ -132,7 +146,7 @@ pub fn opts(os: &'static str, arch: Arch) -> TargetOptions {
132146
// macOS has -dead_strip, which doesn't rely on function_sections
133147
function_sections: false,
134148
dynamic_linking: true,
135-
pre_link_args: pre_link_args(os, arch.target_name(), abi),
149+
pre_link_args: pre_link_args(os, arch, abi),
136150
families: cvs!["unix"],
137151
is_like_osx: true,
138152
default_dwarf_version: 2,
@@ -177,23 +191,24 @@ fn deployment_target(var_name: &str) -> Option<(u32, u32)> {
177191
.and_then(|(a, b)| a.parse::<u32>().and_then(|a| b.parse::<u32>().map(|b| (a, b))).ok())
178192
}
179193

180-
fn macos_default_deployment_target(arch: &str) -> (u32, u32) {
181-
if arch == "arm64" { (11, 0) } else { (10, 7) }
194+
fn macos_default_deployment_target(arch: Arch) -> (u32, u32) {
195+
// Note: Arm64_sim is not included since macOS has no simulator.
196+
if matches!(arch, Arm64 | Arm64_macabi) { (11, 0) } else { (10, 7) }
182197
}
183198

184-
fn macos_deployment_target(arch: &str) -> (u32, u32) {
199+
fn macos_deployment_target(arch: Arch) -> (u32, u32) {
185200
deployment_target("MACOSX_DEPLOYMENT_TARGET")
186201
.unwrap_or_else(|| macos_default_deployment_target(arch))
187202
}
188203

189-
fn macos_lld_platform_version(arch: &str) -> String {
204+
fn macos_lld_platform_version(arch: Arch) -> String {
190205
let (major, minor) = macos_deployment_target(arch);
191206
format!("{}.{}", major, minor)
192207
}
193208

194-
pub fn macos_llvm_target(arch: &str) -> String {
209+
pub fn macos_llvm_target(arch: Arch) -> String {
195210
let (major, minor) = macos_deployment_target(arch);
196-
format!("{}-apple-macosx{}.{}.0", arch, major, minor)
211+
format!("{}-apple-macosx{}.{}.0", arch.target_name(), major, minor)
197212
}
198213

199214
pub fn macos_link_env_remove() -> Vec<StaticCow<str>> {

compiler/rustc_target/src/spec/armv7_apple_ios.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
use super::apple_base::{opts, Arch};
1+
use super::apple_base::{ios_llvm_target, opts, Arch};
22
use crate::spec::{Target, TargetOptions};
33

44
pub fn target() -> Target {
55
let arch = Arch::Armv7;
6-
let llvm_target = super::apple_base::ios_llvm_target(arch);
7-
86
Target {
9-
llvm_target: llvm_target.into(),
7+
// Clang automatically chooses a more specific target based on
8+
// IPHONEOS_DEPLOYMENT_TARGET.
9+
// This is required for the target to pick the right
10+
// MACH-O commands, so we do too.
11+
llvm_target: ios_llvm_target(arch).into(),
1012
pointer_width: 32,
1113
data_layout: "e-m:o-p:32:32-Fi8-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32".into(),
12-
arch: "arm".into(),
14+
arch: arch.target_arch(),
1315
options: TargetOptions {
1416
features: "+v7,+vfp3,+neon".into(),
1517
max_atomic_width: Some(64),

compiler/rustc_target/src/spec/armv7k_apple_watchos.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ use super::apple_base::{opts, Arch};
22
use crate::spec::{Target, TargetOptions};
33

44
pub fn target() -> Target {
5-
let base = opts("watchos", Arch::Armv7k);
5+
let arch = Arch::Armv7k;
66
Target {
77
llvm_target: "armv7k-apple-watchos".into(),
88
pointer_width: 32,
99
data_layout: "e-m:o-p:32:32-Fi8-i64:64-a:0:32-n32-S128".into(),
10-
arch: "arm".into(),
10+
arch: arch.target_arch(),
1111
options: TargetOptions {
1212
features: "+v7,+vfp4,+neon".into(),
1313
max_atomic_width: Some(64),
@@ -22,7 +22,7 @@ pub fn target() -> Target {
2222
darwinpcs\0\
2323
-Os\0"
2424
.into(),
25-
..base
25+
..opts("watchos", arch)
2626
},
2727
}
2828
}

compiler/rustc_target/src/spec/armv7s_apple_ios.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ use super::apple_base::{opts, Arch};
22
use crate::spec::{Target, TargetOptions};
33

44
pub fn target() -> Target {
5+
let arch = Arch::Armv7s;
56
Target {
67
llvm_target: "armv7s-apple-ios".into(),
78
pointer_width: 32,
89
data_layout: "e-m:o-p:32:32-Fi8-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32".into(),
9-
arch: "arm".into(),
10+
arch: arch.target_arch(),
1011
options: TargetOptions {
1112
features: "+v7,+vfp4,+neon".into(),
1213
max_atomic_width: Some(64),
13-
..opts("ios", Arch::Armv7s)
14+
..opts("ios", arch)
1415
},
1516
}
1617
}
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
use super::apple_base::{opts, Arch};
1+
use super::apple_base::{ios_sim_llvm_target, opts, Arch};
22
use crate::spec::{StackProbeType, Target, TargetOptions};
33

44
pub fn target() -> Target {
55
let arch = Arch::I386;
6-
let base = opts("ios", arch);
7-
let llvm_target = super::apple_base::ios_sim_llvm_target(arch);
8-
96
Target {
10-
llvm_target: llvm_target.into(),
7+
// Clang automatically chooses a more specific target based on
8+
// IPHONEOS_DEPLOYMENT_TARGET.
9+
// This is required for the target to pick the right
10+
// MACH-O commands, so we do too.
11+
llvm_target: ios_sim_llvm_target(arch).into(),
1112
pointer_width: 32,
1213
data_layout: "e-m:o-p:32:32-p270:32:32-p271:32:32-p272:64:64-\
1314
f64:32:64-f80:128-n8:16:32-S128"
1415
.into(),
15-
arch: "x86".into(),
16+
arch: arch.target_arch(),
1617
options: TargetOptions {
1718
max_atomic_width: Some(64),
1819
stack_probes: StackProbeType::X86,
19-
..base
20+
..opts("ios", arch)
2021
},
2122
}
2223
}

0 commit comments

Comments
 (0)