Emit diagnostics for incorrect deployment targets
This commit is contained in:
parent
e75a7ddad3
commit
1ef1af1c60
@ -2,6 +2,12 @@ codegen_ssa_L4Bender_exporting_symbols_unimplemented = exporting symbols not imp
|
|||||||
|
|
||||||
codegen_ssa_add_native_library = failed to add native library {$library_path}: {$error}
|
codegen_ssa_add_native_library = failed to add native library {$library_path}: {$error}
|
||||||
|
|
||||||
|
codegen_ssa_apple_deployment_target_invalid =
|
||||||
|
failed to parse deployment target specified in {$env_var}: {$error}
|
||||||
|
|
||||||
|
codegen_ssa_apple_deployment_target_too_low =
|
||||||
|
deployment target in {$env_var} was set to {$version}, but the minimum supported by `rustc` is {$os_min}
|
||||||
|
|
||||||
codegen_ssa_apple_sdk_error_sdk_path = failed to get {$sdk_name} SDK path: {$error}
|
codegen_ssa_apple_sdk_error_sdk_path = failed to get {$sdk_name} SDK path: {$error}
|
||||||
|
|
||||||
codegen_ssa_archive_build_failure = failed to build archive at `{$path}`: {$error}
|
codegen_ssa_archive_build_failure = failed to build archive at `{$path}`: {$error}
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
use std::env;
|
use std::env;
|
||||||
|
use std::fmt::{Display, from_fn};
|
||||||
use std::num::ParseIntError;
|
use std::num::ParseIntError;
|
||||||
|
|
||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
use rustc_target::spec::Target;
|
use rustc_target::spec::Target;
|
||||||
|
|
||||||
|
use crate::errors::AppleDeploymentTarget;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
@ -42,6 +45,17 @@ fn parse_version(version: &str) -> Result<OSVersion, ParseIntError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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`.
|
/// Minimum operating system versions currently supported by `rustc`.
|
||||||
fn os_minimum_deployment_target(os: &str) -> OSVersion {
|
fn os_minimum_deployment_target(os: &str) -> OSVersion {
|
||||||
// When bumping a version in here, remember to update the platform-support docs too.
|
// When bumping a version in here, remember to update the platform-support docs too.
|
||||||
@ -98,17 +112,31 @@ fn deployment_target_env_var(os: &str) -> &'static str {
|
|||||||
/// minimum version supported by `rustc`.
|
/// minimum version supported by `rustc`.
|
||||||
pub fn deployment_target(sess: &Session) -> OSVersion {
|
pub fn deployment_target(sess: &Session) -> OSVersion {
|
||||||
let min = minimum_deployment_target(&sess.target);
|
let min = minimum_deployment_target(&sess.target);
|
||||||
|
let env_var = deployment_target_env_var(&sess.target.os);
|
||||||
|
|
||||||
if let Ok(deployment_target) = env::var(deployment_target_env_var(&sess.target.os)) {
|
if let Ok(deployment_target) = env::var(env_var) {
|
||||||
match parse_version(&deployment_target) {
|
match parse_version(&deployment_target) {
|
||||||
// It is common that the deployment target is set too low, e.g. on macOS Aarch64 to also
|
Ok(version) => {
|
||||||
// target older x86_64, the user may set a lower deployment target than supported.
|
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
|
||||||
// To avoid such issues, we silently raise the deployment target here.
|
// macOS Aarch64 to also target older x86_64. So we only want to warn when variable
|
||||||
// FIXME: We want to show a warning when `version < os_min`.
|
// is lower than the minimum OS supported by rustc, not when the variable is lower
|
||||||
Ok(version) => version.max(min),
|
// than the minimum for a specific target.
|
||||||
// FIXME: Report erroneous environment variable to user.
|
if version < os_min {
|
||||||
Err(_) => 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 {
|
} else {
|
||||||
// If no deployment target variable is set, default to the minimum found above.
|
// If no deployment target variable is set, default to the minimum found above.
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::io::Error;
|
use std::io::Error;
|
||||||
|
use std::num::ParseIntError;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::ExitStatus;
|
use std::process::ExitStatus;
|
||||||
|
|
||||||
@ -539,6 +540,14 @@ pub(crate) struct UnsupportedArch<'a> {
|
|||||||
pub os: &'a str,
|
pub os: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
pub(crate) enum AppleDeploymentTarget {
|
||||||
|
#[diag(codegen_ssa_apple_deployment_target_invalid)]
|
||||||
|
Invalid { env_var: &'static str, error: ParseIntError },
|
||||||
|
#[diag(codegen_ssa_apple_deployment_target_too_low)]
|
||||||
|
TooLow { env_var: &'static str, version: String, os_min: String },
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
pub(crate) enum AppleSdkRootError<'a> {
|
pub(crate) enum AppleSdkRootError<'a> {
|
||||||
#[diag(codegen_ssa_apple_sdk_error_sdk_path)]
|
#[diag(codegen_ssa_apple_sdk_error_sdk_path)]
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#![doc(rust_logo)]
|
#![doc(rust_logo)]
|
||||||
#![feature(assert_matches)]
|
#![feature(assert_matches)]
|
||||||
#![feature(box_patterns)]
|
#![feature(box_patterns)]
|
||||||
|
#![feature(debug_closure_helpers)]
|
||||||
#![feature(file_buffered)]
|
#![feature(file_buffered)]
|
||||||
#![feature(if_let_guard)]
|
#![feature(if_let_guard)]
|
||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
|
@ -857,9 +857,10 @@ fn print_crate_info(
|
|||||||
}
|
}
|
||||||
DeploymentTarget => {
|
DeploymentTarget => {
|
||||||
if sess.target.is_like_osx {
|
if sess.target.is_like_osx {
|
||||||
let (major, minor, patch) = apple::deployment_target(sess);
|
println_info!(
|
||||||
let patch = if patch != 0 { format!(".{patch}") } else { String::new() };
|
"deployment_target={}",
|
||||||
println_info!("deployment_target={major}.{minor}{patch}")
|
apple::pretty_version(apple::deployment_target(sess))
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
#[allow(rustc::diagnostic_outside_of_impl)]
|
#[allow(rustc::diagnostic_outside_of_impl)]
|
||||||
sess.dcx().fatal("only Apple targets currently support deployment version info")
|
sess.dcx().fatal("only Apple targets currently support deployment version info")
|
||||||
|
Loading…
Reference in New Issue
Block a user