Skip to content

Commit 3a7c8a8

Browse files
committed
Auto merge of rust-lang#132476 - matthiaskrgr:rollup-f8444pn, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#131037 (Move versioned Apple LLVM targets from `rustc_target` to `rustc_codegen_ssa`) - rust-lang#132147 (Tweak E0277 output when a candidate is available) - rust-lang#132398 (Add a couple of intra-doc links to str) - rust-lang#132453 (Also treat `impl` definition parent as transparent regarding modules) - rust-lang#132457 (Remove needless #![feature(asm_experimental_arch)] from loongarch64 inline assembly test) - rust-lang#132465 (refactor(config): remove FIXME statement in comment of `omit-git-hash`) - rust-lang#132471 (Add a bunch of mailmap entries) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7c7bb7d + 978fca1 commit 3a7c8a8

File tree

96 files changed

+849
-394
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+849
-394
lines changed

.mailmap

+20-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Alexis Beingessner <[email protected]>
3131
Alfie John <[email protected]> Alfie John <[email protected]>
3232
Alona Enraght-Moony <[email protected]> <[email protected]>
3333
Alona Enraght-Moony <[email protected]> <[email protected]>
34+
Alona Enraght-Moony <[email protected]> <[email protected]>
3435
3536
3637
@@ -75,6 +76,7 @@ Benjamin Jackman <[email protected]>
7576
Benoît Cortier <[email protected]>
7677
Bheesham Persaud <[email protected]> Bheesham Persaud <[email protected]>
7778
79+
7880
7981
blake2-ppc <[email protected]> <blake2-ppc>
8082
blyxyas <[email protected]> Alejandra González <[email protected]>
@@ -172,6 +174,7 @@ Dzmitry Malyshau <[email protected]>
172174
173175
Ed Barnard <[email protected]>
174176
Eduard-Mihai Burtescu <[email protected]>
177+
Eduard-Mihai Burtescu <[email protected]> <[email protected]>
175178
Eduardo Bautista <[email protected]> <=>
176179
177180
Eduardo Broto <[email protected]>
@@ -186,6 +189,7 @@ Erick Tryzelaar <[email protected]> <[email protected]>
186189
Erik Desjardins <[email protected]>
187190
Erik Jensen <[email protected]>
188191
Erin Power <[email protected]>
192+
189193
190194
191195
Esteban Küber <[email protected]>
@@ -198,6 +202,7 @@ F001 <[email protected]>
198202
Fabian Kössel <[email protected]>
199203
Falco Hirschenberger <[email protected]> <[email protected]>
200204
Felix S. Klock II <[email protected]> Felix S Klock II <[email protected]>
205+
201206
Félix Saparelli <[email protected]>
202207
Flaper Fesp <[email protected]>
203208
Florian Berger <[email protected]>
@@ -245,7 +250,7 @@ Irina Popa <[email protected]>
245250
Ivan Ivaschenko <[email protected]>
246251
ivan tkachenko <[email protected]>
247252
J. J. Weber <[email protected]>
248-
Jack Huey <[email protected]>
253+
249254
250255
Jacob Greenfield <[email protected]>
251256
@@ -292,6 +297,7 @@ John Clements <[email protected]> <[email protected]>
292297
John Hodge <[email protected]> John Hodge <[email protected]>
293298
John Hörnvall <[email protected]>
294299
John Kåre Alsaker <[email protected]>
300+
John Kåre Alsaker <[email protected]> <[email protected]>
295301
John Talling <[email protected]>
296302
John Van Enk <[email protected]>
297303
Jonas Tepe <[email protected]>
@@ -368,6 +374,7 @@ Lukas Lueg <[email protected]>
368374
Luke Metz <[email protected]>
369375
370376
377+
371378
372379
Maik Klein <[email protected]>
373380
Malo Jaffré <[email protected]>
@@ -409,6 +416,7 @@ mental <[email protected]>
409416
410417
Michael Williams <[email protected]>
411418
Michael Woerister <michaelwoerister@posteo> <michaelwoerister@gmail>
419+
Michael Woerister <michaelwoerister@posteo> <[email protected]>
412420
Michael Woerister <michaelwoerister@posteo> <[email protected]>
413421
Michael Woerister <michaelwoerister@posteo> <[email protected]>
414422
Michael Zhang <[email protected]>
@@ -422,6 +430,7 @@ Ms2ger <[email protected]> <[email protected]>
422430
msizanoen1 <[email protected]>
423431
Mukilan Thiagarajan <[email protected]>
424432
Nadrieril Feneanar <[email protected]>
433+
Nadrieril Feneanar <[email protected]> <[email protected]>
425434
426435
427436
Nathan Ringo <[email protected]>
@@ -442,6 +451,8 @@ Niclas Schwarzlose <[email protected]>
442451
Nicolas Abram <[email protected]>
443452
Nicole Mazzuca <[email protected]>
444453
454+
455+
445456
446457
447458
@@ -460,6 +471,7 @@ Oliver Scherer <[email protected]> <[email protected]>
460471
461472
462473
474+
463475
Oliver Scherer <[email protected]>
464476
465477
Onur Özkan <[email protected]>
@@ -496,6 +508,7 @@ Raphaël Huchet <[email protected]>
496508
rChaser53 <[email protected]>
497509
Rémy Rakic <[email protected]>
498510
511+
499512
Renato Riccieri Santos Zannon <[email protected]>
500513
501514
Ricky Hosfelt <[email protected]>
@@ -525,6 +538,7 @@ Samuel Tardieu <[email protected]>
525538
Santiago Pastorino <[email protected]>
526539
Santiago Pastorino <[email protected]> <[email protected]>
527540
Scott McMurray <[email protected]>
541+
528542
Scott Olson <[email protected]> Scott Olson <[email protected]>
529543
Sean Gillespie <[email protected]> swgillespie <[email protected]>
530544
Seiichi Uchida <[email protected]>
@@ -536,6 +550,7 @@ Shyam Sundar B <[email protected]>
536550
Simon Barber-Dueck <[email protected]> Simon BD <simon@server>
537551
538552
Simonas Kazlauskas <[email protected]> Simonas Kazlauskas <[email protected]>
553+
Simonas Kazlauskas <[email protected]> <[email protected]>
539554
Siva Prasad <[email protected]>
540555
541556
Srinivas Reddy Thatiparthy <[email protected]>
@@ -556,6 +571,8 @@ Tatsuyuki Ishi <[email protected]>
556571
557572
Tero Hänninen <[email protected]> Tero Hänninen <[email protected]>
558573
574+
575+
559576
Theo Belaire <[email protected]> Theo Belaire <[email protected]>
560577
Theodore Luo Wang <[email protected]>
561578
Thiago Pontes <[email protected]> thiagopnts <[email protected]>
@@ -593,7 +610,8 @@ Waffle Lapkin <[email protected]>
593610
594611
whitequark <[email protected]>
595612
596-
Wim Looman <[email protected]>
613+
614+
597615
Without Boats <[email protected]>
598616
599617
Xinye Tao <[email protected]>

compiler/rustc_codegen_cranelift/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use std::sync::Arc;
4040
use cranelift_codegen::isa::TargetIsa;
4141
use cranelift_codegen::settings::{self, Configurable};
4242
use rustc_codegen_ssa::CodegenResults;
43+
use rustc_codegen_ssa::back::versioned_llvm_target;
4344
use rustc_codegen_ssa::traits::CodegenBackend;
4445
use rustc_data_structures::profiling::SelfProfilerRef;
4546
use rustc_errors::ErrorGuaranteed;
@@ -260,7 +261,9 @@ impl CodegenBackend for CraneliftCodegenBackend {
260261
}
261262

262263
fn target_triple(sess: &Session) -> target_lexicon::Triple {
263-
match sess.target.llvm_target.parse() {
264+
// FIXME(madsmtm): Use `sess.target.llvm_target` once target-lexicon supports unversioned macOS.
265+
// See <https://github.com/bytecodealliance/target-lexicon/pull/113>
266+
match versioned_llvm_target(sess).parse() {
264267
Ok(triple) => triple,
265268
Err(err) => sess.dcx().fatal(format!("target not recognized: {}", err)),
266269
}

compiler/rustc_codegen_llvm/src/back/write.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use llvm::{
99
LLVMRustLLVMHasZlibCompressionForDebugSymbols, LLVMRustLLVMHasZstdCompressionForDebugSymbols,
1010
};
1111
use rustc_codegen_ssa::back::link::ensure_removed;
12+
use rustc_codegen_ssa::back::versioned_llvm_target;
1213
use rustc_codegen_ssa::back::write::{
1314
BitcodeSection, CodegenContext, EmitObj, ModuleConfig, TargetMachineFactoryConfig,
1415
TargetMachineFactoryFn,
@@ -211,7 +212,7 @@ pub(crate) fn target_machine_factory(
211212
singlethread = false;
212213
}
213214

214-
let triple = SmallCStr::new(&sess.target.llvm_target);
215+
let triple = SmallCStr::new(&versioned_llvm_target(sess));
215216
let cpu = SmallCStr::new(llvm_util::target_cpu(sess));
216217
let features = CString::new(target_features.join(",")).unwrap();
217218
let abi = SmallCStr::new(&sess.target.llvm_abiname);

compiler/rustc_codegen_llvm/src/context.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::cell::{Cell, RefCell};
33
use std::ffi::{CStr, c_uint};
44
use std::str;
55

6+
use rustc_codegen_ssa::back::versioned_llvm_target;
67
use rustc_codegen_ssa::base::{wants_msvc_seh, wants_wasm_eh};
78
use rustc_codegen_ssa::errors as ssa_errors;
89
use rustc_codegen_ssa::traits::*;
@@ -182,7 +183,7 @@ pub(crate) unsafe fn create_module<'ll>(
182183
llvm::LLVMSetDataLayout(llmod, data_layout.as_ptr());
183184
}
184185

185-
let llvm_target = SmallCStr::new(&sess.target.llvm_target);
186+
let llvm_target = SmallCStr::new(&versioned_llvm_target(sess));
186187
unsafe {
187188
llvm::LLVMRustSetNormalizedTarget(llmod, llvm_target.as_ptr());
188189
}

compiler/rustc_codegen_ssa/messages.ftl

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ codegen_ssa_L4Bender_exporting_symbols_unimplemented = exporting symbols not imp
22
33
codegen_ssa_add_native_library = failed to add native library {$library_path}: {$error}
44
5+
codegen_ssa_apple_deployment_target_invalid =
6+
failed to parse deployment target specified in {$env_var}: {$error}
7+
8+
codegen_ssa_apple_deployment_target_too_low =
9+
deployment target in {$env_var} was set to {$version}, but the minimum supported by `rustc` is {$os_min}
10+
511
codegen_ssa_apple_sdk_error_sdk_path = failed to get {$sdk_name} SDK path: {$error}
612
713
codegen_ssa_archive_build_failure = failed to build archive at `{$path}`: {$error}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
use std::env;
2+
use std::fmt::{Display, from_fn};
3+
use std::num::ParseIntError;
4+
5+
use rustc_session::Session;
6+
use rustc_target::spec::Target;
7+
8+
use crate::errors::AppleDeploymentTarget;
9+
10+
#[cfg(test)]
11+
mod tests;
12+
13+
pub(super) fn macho_platform(target: &Target) -> u32 {
14+
match (&*target.os, &*target.abi) {
15+
("macos", _) => object::macho::PLATFORM_MACOS,
16+
("ios", "macabi") => object::macho::PLATFORM_MACCATALYST,
17+
("ios", "sim") => object::macho::PLATFORM_IOSSIMULATOR,
18+
("ios", _) => object::macho::PLATFORM_IOS,
19+
("watchos", "sim") => object::macho::PLATFORM_WATCHOSSIMULATOR,
20+
("watchos", _) => object::macho::PLATFORM_WATCHOS,
21+
("tvos", "sim") => object::macho::PLATFORM_TVOSSIMULATOR,
22+
("tvos", _) => object::macho::PLATFORM_TVOS,
23+
("visionos", "sim") => object::macho::PLATFORM_XROSSIMULATOR,
24+
("visionos", _) => object::macho::PLATFORM_XROS,
25+
_ => unreachable!("tried to get Mach-O platform for non-Apple target"),
26+
}
27+
}
28+
29+
/// Deployment target or SDK version.
30+
///
31+
/// The size of the numbers in here are limited by Mach-O's `LC_BUILD_VERSION`.
32+
type OSVersion = (u16, u8, u8);
33+
34+
/// Parse an OS version triple (SDK version or deployment target).
35+
fn parse_version(version: &str) -> Result<OSVersion, ParseIntError> {
36+
if let Some((major, minor)) = version.split_once('.') {
37+
let major = major.parse()?;
38+
if let Some((minor, patch)) = minor.split_once('.') {
39+
Ok((major, minor.parse()?, patch.parse()?))
40+
} else {
41+
Ok((major, minor.parse()?, 0))
42+
}
43+
} else {
44+
Ok((version.parse()?, 0, 0))
45+
}
46+
}
47+
48+
pub fn pretty_version(version: OSVersion) -> impl Display {
49+
let (major, minor, patch) = version;
50+
from_fn(move |f| {
51+
write!(f, "{major}.{minor}")?;
52+
if patch != 0 {
53+
write!(f, ".{patch}")?;
54+
}
55+
Ok(())
56+
})
57+
}
58+
59+
/// Minimum operating system versions currently supported by `rustc`.
60+
fn os_minimum_deployment_target(os: &str) -> OSVersion {
61+
// When bumping a version in here, remember to update the platform-support docs too.
62+
//
63+
// NOTE: The defaults may change in future `rustc` versions, so if you are looking for the
64+
// default deployment target, prefer:
65+
// ```
66+
// $ rustc --print deployment-target
67+
// ```
68+
match os {
69+
"macos" => (10, 12, 0),
70+
"ios" => (10, 0, 0),
71+
"tvos" => (10, 0, 0),
72+
"watchos" => (5, 0, 0),
73+
"visionos" => (1, 0, 0),
74+
_ => unreachable!("tried to get deployment target for non-Apple platform"),
75+
}
76+
}
77+
78+
/// The deployment target for the given target.
79+
///
80+
/// This is similar to `os_minimum_deployment_target`, except that on certain targets it makes sense
81+
/// to raise the minimum OS version.
82+
///
83+
/// This matches what LLVM does, see in part:
84+
/// <https://github.com/llvm/llvm-project/blob/llvmorg-18.1.8/llvm/lib/TargetParser/Triple.cpp#L1900-L1932>
85+
fn minimum_deployment_target(target: &Target) -> OSVersion {
86+
match (&*target.os, &*target.arch, &*target.abi) {
87+
("macos", "aarch64", _) => (11, 0, 0),
88+
("ios", "aarch64", "macabi") => (14, 0, 0),
89+
("ios", "aarch64", "sim") => (14, 0, 0),
90+
("ios", _, _) if target.llvm_target.starts_with("arm64e") => (14, 0, 0),
91+
// Mac Catalyst defaults to 13.1 in Clang.
92+
("ios", _, "macabi") => (13, 1, 0),
93+
("tvos", "aarch64", "sim") => (14, 0, 0),
94+
("watchos", "aarch64", "sim") => (7, 0, 0),
95+
(os, _, _) => os_minimum_deployment_target(os),
96+
}
97+
}
98+
99+
/// Name of the environment variable used to fetch the deployment target on the given OS.
100+
fn deployment_target_env_var(os: &str) -> &'static str {
101+
match os {
102+
"macos" => "MACOSX_DEPLOYMENT_TARGET",
103+
"ios" => "IPHONEOS_DEPLOYMENT_TARGET",
104+
"watchos" => "WATCHOS_DEPLOYMENT_TARGET",
105+
"tvos" => "TVOS_DEPLOYMENT_TARGET",
106+
"visionos" => "XROS_DEPLOYMENT_TARGET",
107+
_ => unreachable!("tried to get deployment target env var for non-Apple platform"),
108+
}
109+
}
110+
111+
/// Get the deployment target based on the standard environment variables, or fall back to the
112+
/// minimum version supported by `rustc`.
113+
pub fn deployment_target(sess: &Session) -> OSVersion {
114+
let min = minimum_deployment_target(&sess.target);
115+
let env_var = deployment_target_env_var(&sess.target.os);
116+
117+
if let Ok(deployment_target) = env::var(env_var) {
118+
match parse_version(&deployment_target) {
119+
Ok(version) => {
120+
let os_min = os_minimum_deployment_target(&sess.target.os);
121+
// It is common that the deployment target is set a bit too low, for example on
122+
// macOS Aarch64 to also target older x86_64. So we only want to warn when variable
123+
// is lower than the minimum OS supported by rustc, not when the variable is lower
124+
// than the minimum for a specific target.
125+
if version < os_min {
126+
sess.dcx().emit_warn(AppleDeploymentTarget::TooLow {
127+
env_var,
128+
version: pretty_version(version).to_string(),
129+
os_min: pretty_version(os_min).to_string(),
130+
});
131+
}
132+
133+
// Raise the deployment target to the minimum supported.
134+
version.max(min)
135+
}
136+
Err(error) => {
137+
sess.dcx().emit_err(AppleDeploymentTarget::Invalid { env_var, error });
138+
min
139+
}
140+
}
141+
} else {
142+
// If no deployment target variable is set, default to the minimum found above.
143+
min
144+
}
145+
}
146+
147+
pub(super) fn add_version_to_llvm_target(
148+
llvm_target: &str,
149+
deployment_target: OSVersion,
150+
) -> String {
151+
let mut components = llvm_target.split("-");
152+
let arch = components.next().expect("apple target should have arch");
153+
let vendor = components.next().expect("apple target should have vendor");
154+
let os = components.next().expect("apple target should have os");
155+
let environment = components.next();
156+
assert_eq!(components.next(), None, "too many LLVM triple components");
157+
158+
let (major, minor, patch) = deployment_target;
159+
160+
assert!(
161+
!os.contains(|c: char| c.is_ascii_digit()),
162+
"LLVM target must not already be versioned"
163+
);
164+
165+
if let Some(env) = environment {
166+
// Insert version into OS, before environment
167+
format!("{arch}-{vendor}-{os}{major}.{minor}.{patch}-{env}")
168+
} else {
169+
format!("{arch}-{vendor}-{os}{major}.{minor}.{patch}")
170+
}
171+
}

0 commit comments

Comments
 (0)