forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#132476 - matthiaskrgr:rollup-f8444pn, r=matth…
…iaskrgr 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
- Loading branch information
Showing
96 changed files
with
849 additions
and
394 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ Alexis Beingessner <[email protected]> | |
Alfie John <[email protected]> Alfie John <[email protected]> | ||
Alona Enraght-Moony <[email protected]> <[email protected]> | ||
Alona Enraght-Moony <[email protected]> <[email protected]> | ||
Alona Enraght-Moony <[email protected]> <[email protected]> | ||
Amanda Stjerna <[email protected]> <[email protected]> | ||
Amanda Stjerna <[email protected]> <[email protected]> | ||
Amos Onn <[email protected]> | ||
|
@@ -75,6 +76,7 @@ Benjamin Jackman <[email protected]> | |
Benoît Cortier <[email protected]> | ||
Bheesham Persaud <[email protected]> Bheesham Persaud <[email protected]> | ||
bjorn3 <[email protected]> <[email protected]> | ||
bjorn3 <[email protected]> <[email protected]> | ||
Björn Steinbrink <[email protected]> <[email protected]> | ||
blake2-ppc <[email protected]> <blake2-ppc> | ||
blyxyas <[email protected]> Alejandra González <[email protected]> | ||
|
@@ -172,6 +174,7 @@ Dzmitry Malyshau <[email protected]> | |
E. Dunham <[email protected]> edunham <[email protected]> | ||
Ed Barnard <[email protected]> | ||
Eduard-Mihai Burtescu <[email protected]> | ||
Eduard-Mihai Burtescu <[email protected]> <[email protected]> | ||
Eduardo Bautista <[email protected]> <=> | ||
Eduardo Bautista <[email protected]> <[email protected]> | ||
Eduardo Broto <[email protected]> | ||
|
@@ -186,6 +189,7 @@ Erick Tryzelaar <[email protected]> <[email protected]> | |
Erik Desjardins <[email protected]> | ||
Erik Jensen <[email protected]> | ||
Erin Power <[email protected]> | ||
Erin Power <[email protected]> <[email protected]> | ||
Erin Power <[email protected]> <[email protected]> | ||
Erin Power <[email protected]> <[email protected]> | ||
Esteban Küber <[email protected]> | ||
|
@@ -198,6 +202,7 @@ F001 <[email protected]> | |
Fabian Kössel <[email protected]> | ||
Falco Hirschenberger <[email protected]> <[email protected]> | ||
Felix S. Klock II <[email protected]> Felix S Klock II <[email protected]> | ||
Felix S. Klock II <[email protected]> <[email protected]> | ||
Félix Saparelli <[email protected]> | ||
Flaper Fesp <[email protected]> | ||
Florian Berger <[email protected]> | ||
|
@@ -245,7 +250,7 @@ Irina Popa <[email protected]> | |
Ivan Ivaschenko <[email protected]> | ||
ivan tkachenko <[email protected]> | ||
J. J. Weber <[email protected]> | ||
Jack Huey <[email protected]> | ||
Jack Huey <[email protected]> <[email protected]> | ||
Jacob <[email protected]> | ||
Jacob Greenfield <[email protected]> | ||
Jacob Pratt <[email protected]> <[email protected]> | ||
|
@@ -292,6 +297,7 @@ John Clements <[email protected]> <[email protected]> | |
John Hodge <[email protected]> John Hodge <[email protected]> | ||
John Hörnvall <[email protected]> | ||
John Kåre Alsaker <[email protected]> | ||
John Kåre Alsaker <[email protected]> <[email protected]> | ||
John Talling <[email protected]> | ||
John Van Enk <[email protected]> | ||
Jonas Tepe <[email protected]> | ||
|
@@ -368,6 +374,7 @@ Lukas Lueg <[email protected]> | |
Luke Metz <[email protected]> | ||
Luqman Aden <[email protected]> <[email protected]> | ||
Luqman Aden <[email protected]> <[email protected]> | ||
Luqman Aden <[email protected]> <[email protected]> | ||
Lzu Tao <[email protected]> | ||
Maik Klein <[email protected]> | ||
Malo Jaffré <[email protected]> | ||
|
@@ -409,6 +416,7 @@ mental <[email protected]> | |
mibac138 <[email protected]> | ||
Michael Williams <[email protected]> | ||
Michael Woerister <michaelwoerister@posteo> <michaelwoerister@gmail> | ||
Michael Woerister <michaelwoerister@posteo> <[email protected]> | ||
Michael Woerister <michaelwoerister@posteo> <[email protected]> | ||
Michael Woerister <michaelwoerister@posteo> <[email protected]> | ||
Michael Zhang <[email protected]> | ||
|
@@ -422,6 +430,7 @@ Ms2ger <[email protected]> <[email protected]> | |
msizanoen1 <[email protected]> | ||
Mukilan Thiagarajan <[email protected]> | ||
Nadrieril Feneanar <[email protected]> | ||
Nadrieril Feneanar <[email protected]> <[email protected]> | ||
NAKASHIMA, Makoto <[email protected]> <[email protected]> | ||
NAKASHIMA, Makoto <[email protected]> <[email protected]> | ||
Nathan Ringo <[email protected]> | ||
|
@@ -442,6 +451,8 @@ Niclas Schwarzlose <[email protected]> | |
Nicolas Abram <[email protected]> | ||
Nicole Mazzuca <[email protected]> | ||
Noratrieb <[email protected]> <[email protected]> | ||
Noratrieb <[email protected]> <[email protected]> | ||
Noratrieb <[email protected]> <[email protected]> | ||
Nif Ward <[email protected]> | ||
Nika Layzell <[email protected]> <[email protected]> | ||
NODA Kai <[email protected]> | ||
|
@@ -460,6 +471,7 @@ Oliver Scherer <[email protected]> <[email protected]> | |
Oliver Scherer <[email protected]> <[email protected]> | ||
Oliver Scherer <[email protected]> <[email protected]> | ||
Oliver Scherer <[email protected]> <[email protected]> | ||
Oliver Scherer <[email protected]> <[email protected]> | ||
Oliver Scherer <[email protected]> | ||
Onur Özkan <[email protected]> <[email protected]> | ||
Onur Özkan <[email protected]> | ||
|
@@ -496,6 +508,7 @@ Raphaël Huchet <[email protected]> | |
rChaser53 <[email protected]> | ||
Rémy Rakic <[email protected]> | ||
Rémy Rakic <[email protected]> <[email protected]> | ||
Rémy Rakic <[email protected]> <[email protected]> | ||
Renato Riccieri Santos Zannon <[email protected]> | ||
Richard Diamond <[email protected]> <[email protected]> | ||
Ricky Hosfelt <[email protected]> | ||
|
@@ -525,6 +538,7 @@ Samuel Tardieu <[email protected]> | |
Santiago Pastorino <[email protected]> | ||
Santiago Pastorino <[email protected]> <[email protected]> | ||
Scott McMurray <[email protected]> | ||
Scott McMurray <[email protected]> <[email protected]> | ||
Scott Olson <[email protected]> Scott Olson <[email protected]> | ||
Sean Gillespie <[email protected]> swgillespie <[email protected]> | ||
Seiichi Uchida <[email protected]> | ||
|
@@ -536,6 +550,7 @@ Shyam Sundar B <[email protected]> | |
Simon Barber-Dueck <[email protected]> Simon BD <simon@server> | ||
Simon Sapin <[email protected]> <[email protected]> | ||
Simonas Kazlauskas <[email protected]> Simonas Kazlauskas <[email protected]> | ||
Simonas Kazlauskas <[email protected]> <[email protected]> | ||
Siva Prasad <[email protected]> | ||
Smittyvb <[email protected]> | ||
Srinivas Reddy Thatiparthy <[email protected]> | ||
|
@@ -556,6 +571,8 @@ Tatsuyuki Ishi <[email protected]> | |
Tau Gärtli <[email protected]> <[email protected]> | ||
Tero Hänninen <[email protected]> Tero Hänninen <[email protected]> | ||
The8472 <[email protected]> | ||
The8472 <[email protected]> <[email protected]> | ||
The8472 <[email protected]> <[email protected]> | ||
Theo Belaire <[email protected]> Theo Belaire <[email protected]> | ||
Theodore Luo Wang <[email protected]> | ||
Thiago Pontes <[email protected]> thiagopnts <[email protected]> | ||
|
@@ -593,7 +610,8 @@ Waffle Lapkin <[email protected]> | |
Wesley Wiser <[email protected]> <[email protected]> | ||
whitequark <[email protected]> | ||
William Ting <[email protected]> <[email protected]> | ||
Wim Looman <[email protected]> | ||
Wim Looman <[email protected]> <[email protected]> | ||
Wim Looman <[email protected]> <[email protected]> | ||
Without Boats <[email protected]> | ||
Without Boats <[email protected]> <[email protected]> | ||
Xinye Tao <[email protected]> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
use std::env; | ||
use std::fmt::{Display, from_fn}; | ||
use std::num::ParseIntError; | ||
|
||
use rustc_session::Session; | ||
use rustc_target::spec::Target; | ||
|
||
use crate::errors::AppleDeploymentTarget; | ||
|
||
#[cfg(test)] | ||
mod tests; | ||
|
||
pub(super) fn macho_platform(target: &Target) -> u32 { | ||
match (&*target.os, &*target.abi) { | ||
("macos", _) => object::macho::PLATFORM_MACOS, | ||
("ios", "macabi") => object::macho::PLATFORM_MACCATALYST, | ||
("ios", "sim") => object::macho::PLATFORM_IOSSIMULATOR, | ||
("ios", _) => object::macho::PLATFORM_IOS, | ||
("watchos", "sim") => object::macho::PLATFORM_WATCHOSSIMULATOR, | ||
("watchos", _) => object::macho::PLATFORM_WATCHOS, | ||
("tvos", "sim") => object::macho::PLATFORM_TVOSSIMULATOR, | ||
("tvos", _) => object::macho::PLATFORM_TVOS, | ||
("visionos", "sim") => object::macho::PLATFORM_XROSSIMULATOR, | ||
("visionos", _) => object::macho::PLATFORM_XROS, | ||
_ => unreachable!("tried to get Mach-O platform for non-Apple target"), | ||
} | ||
} | ||
|
||
/// Deployment target or SDK version. | ||
/// | ||
/// The size of the numbers in here are limited by Mach-O's `LC_BUILD_VERSION`. | ||
type OSVersion = (u16, u8, u8); | ||
|
||
/// Parse an OS version triple (SDK version or deployment target). | ||
fn parse_version(version: &str) -> Result<OSVersion, ParseIntError> { | ||
if let Some((major, minor)) = version.split_once('.') { | ||
let major = major.parse()?; | ||
if let Some((minor, patch)) = minor.split_once('.') { | ||
Ok((major, minor.parse()?, patch.parse()?)) | ||
} else { | ||
Ok((major, minor.parse()?, 0)) | ||
} | ||
} else { | ||
Ok((version.parse()?, 0, 0)) | ||
} | ||
} | ||
|
||
pub fn pretty_version(version: OSVersion) -> impl Display { | ||
let (major, minor, patch) = version; | ||
from_fn(move |f| { | ||
write!(f, "{major}.{minor}")?; | ||
if patch != 0 { | ||
write!(f, ".{patch}")?; | ||
} | ||
Ok(()) | ||
}) | ||
} | ||
|
||
/// Minimum operating system versions currently supported by `rustc`. | ||
fn os_minimum_deployment_target(os: &str) -> OSVersion { | ||
// When bumping a version in here, remember to update the platform-support docs too. | ||
// | ||
// NOTE: The defaults may change in future `rustc` versions, so if you are looking for the | ||
// default deployment target, prefer: | ||
// ``` | ||
// $ rustc --print deployment-target | ||
// ``` | ||
match os { | ||
"macos" => (10, 12, 0), | ||
"ios" => (10, 0, 0), | ||
"tvos" => (10, 0, 0), | ||
"watchos" => (5, 0, 0), | ||
"visionos" => (1, 0, 0), | ||
_ => unreachable!("tried to get deployment target for non-Apple platform"), | ||
} | ||
} | ||
|
||
/// The deployment target for the given target. | ||
/// | ||
/// This is similar to `os_minimum_deployment_target`, except that on certain targets it makes sense | ||
/// to raise the minimum OS version. | ||
/// | ||
/// This matches what LLVM does, see in part: | ||
/// <https://github.com/llvm/llvm-project/blob/llvmorg-18.1.8/llvm/lib/TargetParser/Triple.cpp#L1900-L1932> | ||
fn minimum_deployment_target(target: &Target) -> OSVersion { | ||
match (&*target.os, &*target.arch, &*target.abi) { | ||
("macos", "aarch64", _) => (11, 0, 0), | ||
("ios", "aarch64", "macabi") => (14, 0, 0), | ||
("ios", "aarch64", "sim") => (14, 0, 0), | ||
("ios", _, _) if target.llvm_target.starts_with("arm64e") => (14, 0, 0), | ||
// Mac Catalyst defaults to 13.1 in Clang. | ||
("ios", _, "macabi") => (13, 1, 0), | ||
("tvos", "aarch64", "sim") => (14, 0, 0), | ||
("watchos", "aarch64", "sim") => (7, 0, 0), | ||
(os, _, _) => os_minimum_deployment_target(os), | ||
} | ||
} | ||
|
||
/// Name of the environment variable used to fetch the deployment target on the given OS. | ||
fn deployment_target_env_var(os: &str) -> &'static str { | ||
match os { | ||
"macos" => "MACOSX_DEPLOYMENT_TARGET", | ||
"ios" => "IPHONEOS_DEPLOYMENT_TARGET", | ||
"watchos" => "WATCHOS_DEPLOYMENT_TARGET", | ||
"tvos" => "TVOS_DEPLOYMENT_TARGET", | ||
"visionos" => "XROS_DEPLOYMENT_TARGET", | ||
_ => unreachable!("tried to get deployment target env var for non-Apple platform"), | ||
} | ||
} | ||
|
||
/// Get the deployment target based on the standard environment variables, or fall back to the | ||
/// minimum version supported by `rustc`. | ||
pub fn deployment_target(sess: &Session) -> OSVersion { | ||
let min = minimum_deployment_target(&sess.target); | ||
let env_var = deployment_target_env_var(&sess.target.os); | ||
|
||
if let Ok(deployment_target) = env::var(env_var) { | ||
match parse_version(&deployment_target) { | ||
Ok(version) => { | ||
let os_min = os_minimum_deployment_target(&sess.target.os); | ||
// It is common that the deployment target is set a bit too low, for example on | ||
// macOS Aarch64 to also target older x86_64. So we only want to warn when variable | ||
// is lower than the minimum OS supported by rustc, not when the variable is lower | ||
// than the minimum for a specific target. | ||
if version < os_min { | ||
sess.dcx().emit_warn(AppleDeploymentTarget::TooLow { | ||
env_var, | ||
version: pretty_version(version).to_string(), | ||
os_min: pretty_version(os_min).to_string(), | ||
}); | ||
} | ||
|
||
// Raise the deployment target to the minimum supported. | ||
version.max(min) | ||
} | ||
Err(error) => { | ||
sess.dcx().emit_err(AppleDeploymentTarget::Invalid { env_var, error }); | ||
min | ||
} | ||
} | ||
} else { | ||
// If no deployment target variable is set, default to the minimum found above. | ||
min | ||
} | ||
} | ||
|
||
pub(super) fn add_version_to_llvm_target( | ||
llvm_target: &str, | ||
deployment_target: OSVersion, | ||
) -> String { | ||
let mut components = llvm_target.split("-"); | ||
let arch = components.next().expect("apple target should have arch"); | ||
let vendor = components.next().expect("apple target should have vendor"); | ||
let os = components.next().expect("apple target should have os"); | ||
let environment = components.next(); | ||
assert_eq!(components.next(), None, "too many LLVM triple components"); | ||
|
||
let (major, minor, patch) = deployment_target; | ||
|
||
assert!( | ||
!os.contains(|c: char| c.is_ascii_digit()), | ||
"LLVM target must not already be versioned" | ||
); | ||
|
||
if let Some(env) = environment { | ||
// Insert version into OS, before environment | ||
format!("{arch}-{vendor}-{os}{major}.{minor}.{patch}-{env}") | ||
} else { | ||
format!("{arch}-{vendor}-{os}{major}.{minor}.{patch}") | ||
} | ||
} |
Oops, something went wrong.