Skip to content

Commit 017c9aa

Browse files
authored
Rollup merge of rust-lang#103929 - BlackHoleFox:apple-targets-cleanup, r=petrochenkov
Cleanup Apple-related code in rustc_target While working on rust-lang#103455, the consistency of the `rustc_target` code for Apple's platforms was "kind of bad." There were two "base" files (`apple_base.rs` and `apple_sdk_base.rs`) that the targets each pulled some parts out of, each and all of them were written slightly differently, and sometimes missed comments other implementations had. So to hopefully make future maintenance, like implementing rust-lang/compiler-team#556, easier, this makes all of them use similar patterns and the same target base logic everywhere instead of picking bits from both. This also has some other smaller upsides like less stringly-typed functions.
2 parents 3f11d39 + ae948c6 commit 017c9aa

20 files changed

+218
-221
lines changed

compiler/rustc_target/src/spec/aarch64_apple_darwin.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1+
use super::apple_base::{macos_link_env_remove, macos_llvm_target, opts, Arch};
12
use crate::spec::{FramePointer, SanitizerSet, Target, TargetOptions};
23

34
pub fn target() -> Target {
4-
let arch = "arm64";
5-
let mut base = super::apple_base::opts("macos", arch, "");
5+
let arch = Arch::Arm64;
6+
let mut base = opts("macos", arch);
67
base.cpu = "apple-a14".into();
78
base.max_atomic_width = Some(128);
89

910
// FIXME: The leak sanitizer currently fails the tests, see #88132.
1011
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::THREAD;
1112

12-
base.link_env_remove.to_mut().extend(super::apple_base::macos_link_env_remove());
13-
14-
// Clang automatically chooses a more specific target based on
15-
// MACOSX_DEPLOYMENT_TARGET. To enable cross-language LTO to work
16-
// correctly, we do too.
17-
let llvm_target = super::apple_base::macos_llvm_target(arch);
13+
base.link_env_remove.to_mut().extend(macos_link_env_remove());
1814

1915
Target {
20-
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(),
2120
pointer_width: 64,
2221
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
23-
arch: "aarch64".into(),
22+
arch: arch.target_arch(),
2423
options: TargetOptions {
2524
mcount: "\u{1}mcount".into(),
2625
frame_pointer: FramePointer::NonLeaf,
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
use super::apple_sdk_base::{opts, Arch};
1+
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.
9-
let arch = "arm64";
10-
let llvm_target = super::apple_base::ios_llvm_target(arch);
11-
5+
let arch = Arch::Arm64;
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),
@@ -30,7 +28,7 @@ pub fn target() -> Target {
3028
darwinpcs\0\
3129
-Os\0"
3230
.into(),
33-
..opts("ios", Arch::Arm64)
31+
..opts("ios", arch)
3432
},
3533
}
3634
}

compiler/rustc_target/src/spec/aarch64_apple_ios_macabi.rs

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

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),
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
use super::apple_sdk_base::{opts, Arch};
1+
use super::apple_base::{ios_sim_llvm_target, opts, Arch};
22
use crate::spec::{FramePointer, Target, TargetOptions};
33

44
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-
5+
let arch = Arch::Arm64_sim;
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
}
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
use super::apple_sdk_base::{opts, Arch};
1+
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
}
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
use super::apple_sdk_base::{opts, Arch};
1+
use super::apple_base::{opts, watchos_sim_llvm_target, Arch};
22
use crate::spec::{FramePointer, Target, TargetOptions};
33

44
pub fn target() -> Target {
5-
let base = opts("watchos", Arch::Arm64_sim);
6-
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-
let arch = "arm64";
12-
let llvm_target = super::apple_base::watchos_sim_llvm_target(arch);
13-
5+
let arch = Arch::Arm64_sim;
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
}

0 commit comments

Comments
 (0)