Skip to content

Fix parsing of nigthly targets #1517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Aug 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ use shlex::Shlex;
mod parallel;
mod target;
mod windows;
use self::target::TargetInfo;
use self::target::*;
// Regardless of whether this should be in this crate's public API,
// it has been since 2015, so don't break it.
pub use windows::find_tools as windows_registry;
Expand Down Expand Up @@ -2301,11 +2301,12 @@ impl Build {
// So instead, we pass the deployment target with `-m*-version-min=`, and only
// pass it here on visionOS and Mac Catalyst where that option does not exist:
// https://github.com/rust-lang/cc-rs/issues/1383
let version = if target.os == "visionos" || target.abi == "macabi" {
Some(self.apple_deployment_target(target))
} else {
None
};
let version =
if target.os == "visionos" || target.get_apple_env() == Some(MacCatalyst) {
Some(self.apple_deployment_target(target))
} else {
None
};

let clang_target =
target.llvm_target(&self.get_raw_target()?, version.as_deref());
Expand Down Expand Up @@ -2791,7 +2792,9 @@ impl Build {
// https://github.com/llvm/llvm-project/issues/88271
// And the workaround to use `-mtargetos=` cannot be used with the `--target` flag that we
// otherwise specify. So we avoid emitting that, and put the version in `--target` instead.
if cmd.is_like_gnu() || !(target.os == "visionos" || target.abi == "macabi") {
if cmd.is_like_gnu()
|| !(target.os == "visionos" || target.get_apple_env() == Some(MacCatalyst))
{
let min_version = self.apple_deployment_target(&target);
cmd.args
.push(target.apple_version_flag(&min_version).into());
Expand All @@ -2811,7 +2814,7 @@ impl Build {
cmd.env
.push(("SDKROOT".into(), OsStr::new(&sdk_path).to_owned()));

if target.abi == "macabi" {
if target.get_apple_env() == Some(MacCatalyst) {
// Mac Catalyst uses the macOS SDK, but to compile against and
// link to iOS-specific frameworks, we should have the support
// library stubs in the include and library search path.
Expand Down
1 change: 1 addition & 0 deletions src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod generated;
mod llvm;
mod parser;

pub(crate) use apple::*;
pub(crate) use parser::TargetInfoParser;

/// Information specific to a `rustc` target.
Expand Down
59 changes: 37 additions & 22 deletions src/target/apple.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
use super::TargetInfo;

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub(crate) enum AppleEnv {
Simulator,
MacCatalyst,
}
pub(crate) use AppleEnv::*;

impl TargetInfo<'_> {
pub(crate) fn get_apple_env(&self) -> Option<AppleEnv> {
match (self.env, self.abi) {
("sim", _) | (_, "sim") => Some(Simulator),
("macabi", _) | (_, "macabi") => Some(MacCatalyst),
_ => None,
}
}

pub(crate) fn apple_sdk_name(&self) -> &'static str {
match (self.os, self.abi) {
("macos", "") => "macosx",
("ios", "") => "iphoneos",
("ios", "sim") => "iphonesimulator",
("ios", "macabi") => "macosx",
("tvos", "") => "appletvos",
("tvos", "sim") => "appletvsimulator",
("watchos", "") => "watchos",
("watchos", "sim") => "watchsimulator",
("visionos", "") => "xros",
("visionos", "sim") => "xrsimulator",
match (self.os, self.get_apple_env()) {
("macos", None) => "macosx",
("ios", None) => "iphoneos",
("ios", Some(Simulator)) => "iphonesimulator",
("ios", Some(MacCatalyst)) => "macosx",
("tvos", None) => "appletvos",
("tvos", Some(Simulator)) => "appletvsimulator",
("watchos", None) => "watchos",
("watchos", Some(Simulator)) => "watchsimulator",
("visionos", None) => "xros",
("visionos", Some(Simulator)) => "xrsimulator",
(os, _) => panic!("invalid Apple target OS {}", os),
}
}
Expand All @@ -30,19 +45,19 @@ impl TargetInfo<'_> {
// https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mmacos-version-min
// https://clang.llvm.org/docs/AttributeReference.html#availability
// https://gcc.gnu.org/onlinedocs/gcc/Darwin-Options.html#index-mmacosx-version-min
match (self.os, self.abi) {
("macos", "") => format!("-mmacosx-version-min={min_version}"),
("ios", "") => format!("-miphoneos-version-min={min_version}"),
("ios", "sim") => format!("-mios-simulator-version-min={min_version}"),
("ios", "macabi") => format!("-mtargetos=ios{min_version}-macabi"),
("tvos", "") => format!("-mappletvos-version-min={min_version}"),
("tvos", "sim") => format!("-mappletvsimulator-version-min={min_version}"),
("watchos", "") => format!("-mwatchos-version-min={min_version}"),
("watchos", "sim") => format!("-mwatchsimulator-version-min={min_version}"),
match (self.os, self.get_apple_env()) {
("macos", None) => format!("-mmacosx-version-min={min_version}"),
("ios", None) => format!("-miphoneos-version-min={min_version}"),
("ios", Some(Simulator)) => format!("-mios-simulator-version-min={min_version}"),
("ios", Some(MacCatalyst)) => format!("-mtargetos=ios{min_version}-macabi"),
("tvos", None) => format!("-mappletvos-version-min={min_version}"),
("tvos", Some(Simulator)) => format!("-mappletvsimulator-version-min={min_version}"),
("watchos", None) => format!("-mwatchos-version-min={min_version}"),
("watchos", Some(Simulator)) => format!("-mwatchsimulator-version-min={min_version}"),
// `-mxros-version-min` does not exist
// https://github.com/llvm/llvm-project/issues/88271
("visionos", "") => format!("-mtargetos=xros{min_version}"),
("visionos", "sim") => format!("-mtargetos=xros{min_version}-simulator"),
("visionos", None) => format!("-mtargetos=xros{min_version}"),
("visionos", Some(Simulator)) => format!("-mtargetos=xros{min_version}-simulator"),
(os, _) => panic!("invalid Apple target OS {}", os),
}
}
Expand Down
1 change: 1 addition & 0 deletions src/target/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ impl TargetInfo<'_> {
let env = match self.env {
"newlib" | "nto70" | "nto71" | "nto71_iosock" | "p1" | "p2" | "relibc" | "sgx"
| "uclibc" => "",
"sim" => "simulator",
env => env,
};
let abi = match self.abi {
Expand Down
22 changes: 19 additions & 3 deletions src/target/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ fn parse_envabi(last_component: &str) -> Option<(&str, &str)> {
"abiv2" => ("", "spe"),
"eabi" => ("", "eabi"),
"eabihf" => ("", "eabihf"),
"macabi" => ("", "macabi"),
"sim" => ("", "sim"),
"macabi" => ("macabi", ""),
"sim" => ("sim", ""),
"softfloat" => ("", "softfloat"),
"spe" => ("", "spe"),
"x32" => ("", "x32"),
Expand Down Expand Up @@ -266,6 +266,17 @@ impl<'a> TargetInfo<'a> {
});
}

if target == "armv7a-vex-v5" {
return Ok(Self {
full_arch: "armv7a",
arch: "arm",
vendor: "vex",
os: "vexos",
env: "v5",
abi: "eabihf",
});
}

let mut components = target.split('-');

// Insist that the target name contains at least a valid architecture.
Expand Down Expand Up @@ -344,7 +355,7 @@ impl<'a> TargetInfo<'a> {
match target {
// Actually simulator targets.
"i386-apple-ios" | "x86_64-apple-ios" | "x86_64-apple-tvos" => {
abi = "sim";
env = "sim";
}
// Name should've contained `muslabi64`.
"mips64-openwrt-linux-musl" => {
Expand Down Expand Up @@ -529,6 +540,11 @@ mod tests {
}
}

if matches!(target.abi, "macabi" | "sim") {
assert_eq!(target.env, target.abi);
target.abi = "";
}

target
}

Expand Down
Loading