diff --git a/src/lib.rs b/src/lib.rs index 2da9a3c9..6c41d3e6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; @@ -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()); @@ -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()); @@ -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. diff --git a/src/target.rs b/src/target.rs index ed432df5..16832678 100644 --- a/src/target.rs +++ b/src/target.rs @@ -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. diff --git a/src/target/apple.rs b/src/target/apple.rs index bd65e00f..8db8fb59 100644 --- a/src/target/apple.rs +++ b/src/target/apple.rs @@ -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 { + 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), } } @@ -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), } } diff --git a/src/target/llvm.rs b/src/target/llvm.rs index 124ab2a0..63b0dfca 100644 --- a/src/target/llvm.rs +++ b/src/target/llvm.rs @@ -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 { diff --git a/src/target/parser.rs b/src/target/parser.rs index d22cc0e6..4bcf7043 100644 --- a/src/target/parser.rs +++ b/src/target/parser.rs @@ -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"), @@ -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. @@ -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" => { @@ -529,6 +540,11 @@ mod tests { } } + if matches!(target.abi, "macabi" | "sim") { + assert_eq!(target.env, target.abi); + target.abi = ""; + } + target }