Skip to content

Commit de7e8d5

Browse files
authored
Fix parsing of nigthly targets (#1517)
rust-lang/rust#139451 updated the sim/macabi to be env instead of abi
1 parent ca81dcc commit de7e8d5

File tree

5 files changed

+69
-33
lines changed

5 files changed

+69
-33
lines changed

src/lib.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ use shlex::Shlex;
262262
mod parallel;
263263
mod target;
264264
mod windows;
265-
use self::target::TargetInfo;
265+
use self::target::*;
266266
// Regardless of whether this should be in this crate's public API,
267267
// it has been since 2015, so don't break it.
268268
pub use windows::find_tools as windows_registry;
@@ -2301,11 +2301,12 @@ impl Build {
23012301
// So instead, we pass the deployment target with `-m*-version-min=`, and only
23022302
// pass it here on visionOS and Mac Catalyst where that option does not exist:
23032303
// https://github.com/rust-lang/cc-rs/issues/1383
2304-
let version = if target.os == "visionos" || target.abi == "macabi" {
2305-
Some(self.apple_deployment_target(target))
2306-
} else {
2307-
None
2308-
};
2304+
let version =
2305+
if target.os == "visionos" || target.get_apple_env() == Some(MacCatalyst) {
2306+
Some(self.apple_deployment_target(target))
2307+
} else {
2308+
None
2309+
};
23092310

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

2814-
if target.abi == "macabi" {
2817+
if target.get_apple_env() == Some(MacCatalyst) {
28152818
// Mac Catalyst uses the macOS SDK, but to compile against and
28162819
// link to iOS-specific frameworks, we should have the support
28172820
// library stubs in the include and library search path.

src/target.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mod generated;
66
mod llvm;
77
mod parser;
88

9+
pub(crate) use apple::*;
910
pub(crate) use parser::TargetInfoParser;
1011

1112
/// Information specific to a `rustc` target.

src/target/apple.rs

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
11
use super::TargetInfo;
22

3+
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
4+
pub(crate) enum AppleEnv {
5+
Simulator,
6+
MacCatalyst,
7+
}
8+
pub(crate) use AppleEnv::*;
9+
310
impl TargetInfo<'_> {
11+
pub(crate) fn get_apple_env(&self) -> Option<AppleEnv> {
12+
match (self.env, self.abi) {
13+
("sim", _) | (_, "sim") => Some(Simulator),
14+
("macabi", _) | (_, "macabi") => Some(MacCatalyst),
15+
_ => None,
16+
}
17+
}
18+
419
pub(crate) fn apple_sdk_name(&self) -> &'static str {
5-
match (self.os, self.abi) {
6-
("macos", "") => "macosx",
7-
("ios", "") => "iphoneos",
8-
("ios", "sim") => "iphonesimulator",
9-
("ios", "macabi") => "macosx",
10-
("tvos", "") => "appletvos",
11-
("tvos", "sim") => "appletvsimulator",
12-
("watchos", "") => "watchos",
13-
("watchos", "sim") => "watchsimulator",
14-
("visionos", "") => "xros",
15-
("visionos", "sim") => "xrsimulator",
20+
match (self.os, self.get_apple_env()) {
21+
("macos", None) => "macosx",
22+
("ios", None) => "iphoneos",
23+
("ios", Some(Simulator)) => "iphonesimulator",
24+
("ios", Some(MacCatalyst)) => "macosx",
25+
("tvos", None) => "appletvos",
26+
("tvos", Some(Simulator)) => "appletvsimulator",
27+
("watchos", None) => "watchos",
28+
("watchos", Some(Simulator)) => "watchsimulator",
29+
("visionos", None) => "xros",
30+
("visionos", Some(Simulator)) => "xrsimulator",
1631
(os, _) => panic!("invalid Apple target OS {}", os),
1732
}
1833
}
@@ -30,19 +45,19 @@ impl TargetInfo<'_> {
3045
// https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mmacos-version-min
3146
// https://clang.llvm.org/docs/AttributeReference.html#availability
3247
// https://gcc.gnu.org/onlinedocs/gcc/Darwin-Options.html#index-mmacosx-version-min
33-
match (self.os, self.abi) {
34-
("macos", "") => format!("-mmacosx-version-min={min_version}"),
35-
("ios", "") => format!("-miphoneos-version-min={min_version}"),
36-
("ios", "sim") => format!("-mios-simulator-version-min={min_version}"),
37-
("ios", "macabi") => format!("-mtargetos=ios{min_version}-macabi"),
38-
("tvos", "") => format!("-mappletvos-version-min={min_version}"),
39-
("tvos", "sim") => format!("-mappletvsimulator-version-min={min_version}"),
40-
("watchos", "") => format!("-mwatchos-version-min={min_version}"),
41-
("watchos", "sim") => format!("-mwatchsimulator-version-min={min_version}"),
48+
match (self.os, self.get_apple_env()) {
49+
("macos", None) => format!("-mmacosx-version-min={min_version}"),
50+
("ios", None) => format!("-miphoneos-version-min={min_version}"),
51+
("ios", Some(Simulator)) => format!("-mios-simulator-version-min={min_version}"),
52+
("ios", Some(MacCatalyst)) => format!("-mtargetos=ios{min_version}-macabi"),
53+
("tvos", None) => format!("-mappletvos-version-min={min_version}"),
54+
("tvos", Some(Simulator)) => format!("-mappletvsimulator-version-min={min_version}"),
55+
("watchos", None) => format!("-mwatchos-version-min={min_version}"),
56+
("watchos", Some(Simulator)) => format!("-mwatchsimulator-version-min={min_version}"),
4257
// `-mxros-version-min` does not exist
4358
// https://github.com/llvm/llvm-project/issues/88271
44-
("visionos", "") => format!("-mtargetos=xros{min_version}"),
45-
("visionos", "sim") => format!("-mtargetos=xros{min_version}-simulator"),
59+
("visionos", None) => format!("-mtargetos=xros{min_version}"),
60+
("visionos", Some(Simulator)) => format!("-mtargetos=xros{min_version}-simulator"),
4661
(os, _) => panic!("invalid Apple target OS {}", os),
4762
}
4863
}

src/target/llvm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ impl TargetInfo<'_> {
9191
let env = match self.env {
9292
"newlib" | "nto70" | "nto71" | "nto71_iosock" | "p1" | "p2" | "relibc" | "sgx"
9393
| "uclibc" => "",
94+
"sim" => "simulator",
9495
env => env,
9596
};
9697
let abi = match self.abi {

src/target/parser.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ fn parse_envabi(last_component: &str) -> Option<(&str, &str)> {
232232
"abiv2" => ("", "spe"),
233233
"eabi" => ("", "eabi"),
234234
"eabihf" => ("", "eabihf"),
235-
"macabi" => ("", "macabi"),
236-
"sim" => ("", "sim"),
235+
"macabi" => ("macabi", ""),
236+
"sim" => ("sim", ""),
237237
"softfloat" => ("", "softfloat"),
238238
"spe" => ("", "spe"),
239239
"x32" => ("", "x32"),
@@ -266,6 +266,17 @@ impl<'a> TargetInfo<'a> {
266266
});
267267
}
268268

269+
if target == "armv7a-vex-v5" {
270+
return Ok(Self {
271+
full_arch: "armv7a",
272+
arch: "arm",
273+
vendor: "vex",
274+
os: "vexos",
275+
env: "v5",
276+
abi: "eabihf",
277+
});
278+
}
279+
269280
let mut components = target.split('-');
270281

271282
// Insist that the target name contains at least a valid architecture.
@@ -344,7 +355,7 @@ impl<'a> TargetInfo<'a> {
344355
match target {
345356
// Actually simulator targets.
346357
"i386-apple-ios" | "x86_64-apple-ios" | "x86_64-apple-tvos" => {
347-
abi = "sim";
358+
env = "sim";
348359
}
349360
// Name should've contained `muslabi64`.
350361
"mips64-openwrt-linux-musl" => {
@@ -529,6 +540,11 @@ mod tests {
529540
}
530541
}
531542

543+
if matches!(target.abi, "macabi" | "sim") {
544+
assert_eq!(target.env, target.abi);
545+
target.abi = "";
546+
}
547+
532548
target
533549
}
534550

0 commit comments

Comments
 (0)