Skip to content

Add target_env = "macabi" and target_env = "sim" #139451

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_ssa/src/back/apple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod tests;

/// The canonical name of the desired SDK for a given target.
pub(super) fn sdk_name(target: &Target) -> &'static str {
match (&*target.os, &*target.abi) {
match (&*target.os, &*target.env) {
("macos", "") => "MacOSX",
("ios", "") => "iPhoneOS",
("ios", "sim") => "iPhoneSimulator",
Expand All @@ -34,7 +34,7 @@ pub(super) fn sdk_name(target: &Target) -> &'static str {
}

pub(super) fn macho_platform(target: &Target) -> u32 {
match (&*target.os, &*target.abi) {
match (&*target.os, &*target.env) {
("macos", _) => object::macho::PLATFORM_MACOS,
("ios", "macabi") => object::macho::PLATFORM_MACCATALYST,
("ios", "sim") => object::macho::PLATFORM_IOSSIMULATOR,
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3040,7 +3040,7 @@ pub(crate) fn are_upstream_rust_objects_already_included(sess: &Session) -> bool
/// We need to communicate five things to the linker on Apple/Darwin targets:
/// - The architecture.
/// - The operating system (and that it's an Apple platform).
/// - The environment / ABI.
/// - The environment.
/// - The deployment target.
/// - The SDK version.
fn add_apple_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
Expand All @@ -3054,7 +3054,7 @@ fn add_apple_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavo
// `sess.target.arch` (`target_arch`) is not detailed enough.
let llvm_arch = sess.target.llvm_target.split_once('-').expect("LLVM target must have arch").0;
let target_os = &*sess.target.os;
let target_abi = &*sess.target.abi;
let target_env = &*sess.target.env;

// The architecture name to forward to the linker.
//
Expand Down Expand Up @@ -3105,14 +3105,14 @@ fn add_apple_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavo
// > - visionos-simulator
// > - xros-simulator
// > - driverkit
let platform_name = match (target_os, target_abi) {
let platform_name = match (target_os, target_env) {
(os, "") => os,
("ios", "macabi") => "mac-catalyst",
("ios", "sim") => "ios-simulator",
("tvos", "sim") => "tvos-simulator",
("watchos", "sim") => "watchos-simulator",
("visionos", "sim") => "visionos-simulator",
_ => bug!("invalid OS/ABI combination for Apple target: {target_os}, {target_abi}"),
_ => bug!("invalid OS/env combination for Apple target: {target_os}, {target_env}"),
};

let min_version = sess.apple_deployment_target().fmt_full().to_string();
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/native_libs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub fn walk_native_lib_search_dirs<R>(
// Mac Catalyst uses the macOS SDK, but to link to iOS-specific frameworks
// we must have the support library stubs in the library search path (#121430).
if let Some(sdk_root) = apple_sdk_root
&& sess.target.llvm_target.contains("macabi")
&& sess.target.env == "macabi"
{
f(&sdk_root.join("System/iOSSupport/usr/lib"), false)?;
f(&sdk_root.join("System/iOSSupport/System/Library/Frameworks"), true)?;
Expand Down
43 changes: 25 additions & 18 deletions compiler/rustc_target/src/spec/base/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ impl Arch {
})
}

fn target_cpu(self, abi: TargetAbi) -> &'static str {
fn target_cpu(self, env: TargetEnv) -> &'static str {
match self {
Armv7k => "cortex-a8",
Armv7s => "swift", // iOS 10 is only supported on iPhone 5 or higher.
Arm64 => match abi {
TargetAbi::Normal => "apple-a7",
TargetAbi::Simulator => "apple-a12",
TargetAbi::MacCatalyst => "apple-a12",
Arm64 => match env {
TargetEnv::Normal => "apple-a7",
TargetEnv::Simulator => "apple-a12",
TargetEnv::MacCatalyst => "apple-a12",
},
Arm64e => "apple-a12",
Arm64_32 => "apple-s4",
Expand All @@ -83,14 +83,14 @@ impl Arch {
}

#[derive(Copy, Clone, PartialEq)]
pub(crate) enum TargetAbi {
pub(crate) enum TargetEnv {
Normal,
Simulator,
MacCatalyst,
}

impl TargetAbi {
fn target_abi(self) -> &'static str {
impl TargetEnv {
fn target_env(self) -> &'static str {
match self {
Self::Normal => "",
Self::MacCatalyst => "macabi",
Expand All @@ -104,13 +104,20 @@ impl TargetAbi {
pub(crate) fn base(
os: &'static str,
arch: Arch,
abi: TargetAbi,
env: TargetEnv,
) -> (TargetOptions, StaticCow<str>, StaticCow<str>) {
let mut opts = TargetOptions {
abi: abi.target_abi().into(),
llvm_floatabi: Some(FloatAbi::Hard),
os: os.into(),
cpu: arch.target_cpu(abi).into(),
env: env.target_env().into(),
// NOTE: We originally set `cfg(target_abi = "macabi")` / `cfg(target_abi = "sim")`,
// before it was discovered that those are actually environments:
// https://github.com/rust-lang/rust/issues/133331
//
// But let's continue setting them for backwards compatibility.
// FIXME(madsmtm): Warn about using these in the future.
abi: env.target_env().into(),
cpu: arch.target_cpu(env).into(),
link_env_remove: link_env_remove(os),
vendor: "apple".into(),
linker_flavor: LinkerFlavor::Darwin(Cc::Yes, Lld::No),
Expand Down Expand Up @@ -162,14 +169,14 @@ pub(crate) fn base(
// All Apple x86-32 targets have SSE2.
opts.rustc_abi = Some(RustcAbi::X86Sse2);
}
(opts, unversioned_llvm_target(os, arch, abi), arch.target_arch())
(opts, unversioned_llvm_target(os, arch, env), arch.target_arch())
}

/// Generate part of the LLVM target triple.
///
/// See `rustc_codegen_ssa::back::versioned_llvm_target` for the full triple passed to LLVM and
/// Clang.
fn unversioned_llvm_target(os: &str, arch: Arch, abi: TargetAbi) -> StaticCow<str> {
fn unversioned_llvm_target(os: &str, arch: Arch, env: TargetEnv) -> StaticCow<str> {
let arch = arch.target_name();
// Convert to the "canonical" OS name used by LLVM:
// https://github.com/llvm/llvm-project/blob/llvmorg-18.1.8/llvm/lib/TargetParser/Triple.cpp#L236-L282
Expand All @@ -181,10 +188,10 @@ fn unversioned_llvm_target(os: &str, arch: Arch, abi: TargetAbi) -> StaticCow<st
"visionos" => "xros",
_ => unreachable!("tried to get LLVM target OS for non-Apple platform"),
};
let environment = match abi {
TargetAbi::Normal => "",
TargetAbi::MacCatalyst => "-macabi",
TargetAbi::Simulator => "-simulator",
let environment = match env {
TargetEnv::Normal => "",
TargetEnv::MacCatalyst => "-macabi",
TargetEnv::Simulator => "-simulator",
};
format!("{arch}-apple-{os}{environment}").into()
}
Expand Down Expand Up @@ -303,7 +310,7 @@ impl OSVersion {
/// 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>
pub fn minimum_deployment_target(target: &Target) -> Self {
let (major, minor, patch) = match (&*target.os, &*target.arch, &*target.abi) {
let (major, minor, patch) = match (&*target.os, &*target.arch, &*target.env) {
("macos", "aarch64", _) => (11, 0, 0),
("ios", "aarch64", "macabi") => (14, 0, 0),
("ios", "aarch64", "sim") => (14, 0, 0),
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_target/src/spec/base/apple/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::spec::targets::{
};

#[test]
fn simulator_targets_set_abi() {
fn simulator_targets_set_env() {
let all_sim_targets = [
x86_64_apple_ios::target(),
x86_64_apple_tvos::target(),
Expand All @@ -18,7 +18,9 @@ fn simulator_targets_set_abi() {
];

for target in &all_sim_targets {
assert_eq!(target.abi, "sim")
assert_eq!(target.env, "sim");
// Ensure backwards compat
assert_eq!(target.abi, "sim");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::spec::base::apple::{Arch, TargetAbi, base};
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{FramePointer, SanitizerSet, Target, TargetMetadata, TargetOptions};

pub(crate) fn target() -> Target {
let (opts, llvm_target, arch) = base("macos", Arch::Arm64, TargetAbi::Normal);
let (opts, llvm_target, arch) = base("macos", Arch::Arm64, TargetEnv::Normal);
Target {
llvm_target,
metadata: TargetMetadata {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_target/src/spec/targets/aarch64_apple_ios.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::spec::base::apple::{Arch, TargetAbi, base};
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{FramePointer, SanitizerSet, Target, TargetMetadata, TargetOptions};

pub(crate) fn target() -> Target {
let (opts, llvm_target, arch) = base("ios", Arch::Arm64, TargetAbi::Normal);
let (opts, llvm_target, arch) = base("ios", Arch::Arm64, TargetEnv::Normal);
Target {
llvm_target,
metadata: TargetMetadata {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::spec::base::apple::{Arch, TargetAbi, base};
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{FramePointer, SanitizerSet, Target, TargetMetadata, TargetOptions};

pub(crate) fn target() -> Target {
let (opts, llvm_target, arch) = base("ios", Arch::Arm64, TargetAbi::MacCatalyst);
let (opts, llvm_target, arch) = base("ios", Arch::Arm64, TargetEnv::MacCatalyst);
Target {
llvm_target,
metadata: TargetMetadata {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::spec::base::apple::{Arch, TargetAbi, base};
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{FramePointer, SanitizerSet, Target, TargetMetadata, TargetOptions};

pub(crate) fn target() -> Target {
let (opts, llvm_target, arch) = base("ios", Arch::Arm64, TargetAbi::Simulator);
let (opts, llvm_target, arch) = base("ios", Arch::Arm64, TargetEnv::Simulator);
Target {
llvm_target,
metadata: TargetMetadata {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_target/src/spec/targets/aarch64_apple_tvos.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::spec::base::apple::{Arch, TargetAbi, base};
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{FramePointer, Target, TargetMetadata, TargetOptions};

pub(crate) fn target() -> Target {
let (opts, llvm_target, arch) = base("tvos", Arch::Arm64, TargetAbi::Normal);
let (opts, llvm_target, arch) = base("tvos", Arch::Arm64, TargetEnv::Normal);
Target {
llvm_target,
metadata: TargetMetadata {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::spec::base::apple::{Arch, TargetAbi, base};
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{FramePointer, Target, TargetMetadata, TargetOptions};

pub(crate) fn target() -> Target {
let (opts, llvm_target, arch) = base("tvos", Arch::Arm64, TargetAbi::Simulator);
let (opts, llvm_target, arch) = base("tvos", Arch::Arm64, TargetEnv::Simulator);
Target {
llvm_target,
metadata: TargetMetadata {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::spec::base::apple::{Arch, TargetAbi, base};
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{FramePointer, SanitizerSet, Target, TargetMetadata, TargetOptions};

pub(crate) fn target() -> Target {
let (opts, llvm_target, arch) = base("visionos", Arch::Arm64, TargetAbi::Normal);
let (opts, llvm_target, arch) = base("visionos", Arch::Arm64, TargetEnv::Normal);
Target {
llvm_target,
metadata: TargetMetadata {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::spec::base::apple::{Arch, TargetAbi, base};
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{FramePointer, SanitizerSet, Target, TargetMetadata, TargetOptions};

pub(crate) fn target() -> Target {
let (opts, llvm_target, arch) = base("visionos", Arch::Arm64, TargetAbi::Simulator);
let (opts, llvm_target, arch) = base("visionos", Arch::Arm64, TargetEnv::Simulator);
Target {
llvm_target,
metadata: TargetMetadata {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::spec::base::apple::{Arch, TargetAbi, base};
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{Target, TargetMetadata, TargetOptions};

pub(crate) fn target() -> Target {
let (opts, llvm_target, arch) = base("watchos", Arch::Arm64, TargetAbi::Normal);
let (opts, llvm_target, arch) = base("watchos", Arch::Arm64, TargetEnv::Normal);
Target {
llvm_target,
metadata: TargetMetadata {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::spec::base::apple::{Arch, TargetAbi, base};
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{FramePointer, Target, TargetMetadata, TargetOptions};

pub(crate) fn target() -> Target {
let (opts, llvm_target, arch) = base("watchos", Arch::Arm64, TargetAbi::Simulator);
let (opts, llvm_target, arch) = base("watchos", Arch::Arm64, TargetEnv::Simulator);
Target {
llvm_target,
metadata: TargetMetadata {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::spec::base::apple::{Arch, TargetAbi, base};
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{Target, TargetMetadata, TargetOptions};

pub(crate) fn target() -> Target {
let (opts, llvm_target, arch) = base("watchos", Arch::Arm64_32, TargetAbi::Normal);
let (opts, llvm_target, arch) = base("watchos", Arch::Arm64_32, TargetEnv::Normal);
Target {
llvm_target,
metadata: TargetMetadata {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_target/src/spec/targets/arm64e_apple_darwin.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::spec::base::apple::{Arch, TargetAbi, base};
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{FramePointer, SanitizerSet, Target, TargetMetadata, TargetOptions};

pub(crate) fn target() -> Target {
let (opts, llvm_target, arch) = base("macos", Arch::Arm64e, TargetAbi::Normal);
let (opts, llvm_target, arch) = base("macos", Arch::Arm64e, TargetEnv::Normal);
Target {
llvm_target,
metadata: TargetMetadata {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_target/src/spec/targets/arm64e_apple_ios.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::spec::base::apple::{Arch, TargetAbi, base};
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{FramePointer, SanitizerSet, Target, TargetMetadata, TargetOptions};

pub(crate) fn target() -> Target {
let (opts, llvm_target, arch) = base("ios", Arch::Arm64e, TargetAbi::Normal);
let (opts, llvm_target, arch) = base("ios", Arch::Arm64e, TargetEnv::Normal);
Target {
llvm_target,
metadata: TargetMetadata {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_target/src/spec/targets/arm64e_apple_tvos.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::spec::base::apple::{Arch, TargetAbi, base};
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{FramePointer, Target, TargetMetadata, TargetOptions};

pub(crate) fn target() -> Target {
let (opts, llvm_target, arch) = base("tvos", Arch::Arm64e, TargetAbi::Normal);
let (opts, llvm_target, arch) = base("tvos", Arch::Arm64e, TargetEnv::Normal);
Target {
llvm_target,
metadata: TargetMetadata {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::spec::base::apple::{Arch, TargetAbi, base};
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{Target, TargetMetadata, TargetOptions};

pub(crate) fn target() -> Target {
let (opts, llvm_target, arch) = base("watchos", Arch::Armv7k, TargetAbi::Normal);
let (opts, llvm_target, arch) = base("watchos", Arch::Armv7k, TargetEnv::Normal);
Target {
llvm_target,
metadata: TargetMetadata {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_target/src/spec/targets/armv7s_apple_ios.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::spec::base::apple::{Arch, TargetAbi, base};
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{Target, TargetMetadata, TargetOptions};

pub(crate) fn target() -> Target {
let (opts, llvm_target, arch) = base("ios", Arch::Armv7s, TargetAbi::Normal);
let (opts, llvm_target, arch) = base("ios", Arch::Armv7s, TargetEnv::Normal);
Target {
llvm_target,
metadata: TargetMetadata {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_target/src/spec/targets/i386_apple_ios.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::spec::base::apple::{Arch, TargetAbi, base};
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{Target, TargetMetadata, TargetOptions};

pub(crate) fn target() -> Target {
// i386-apple-ios is a simulator target, even though it isn't declared
// that way in the target name like the other ones...
let (opts, llvm_target, arch) = base("ios", Arch::I386, TargetAbi::Simulator);
let (opts, llvm_target, arch) = base("ios", Arch::I386, TargetEnv::Simulator);
Target {
llvm_target,
metadata: TargetMetadata {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_target/src/spec/targets/i686_apple_darwin.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::spec::base::apple::{Arch, TargetAbi, base};
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{FramePointer, Target, TargetMetadata, TargetOptions};

pub(crate) fn target() -> Target {
let (opts, llvm_target, arch) = base("macos", Arch::I686, TargetAbi::Normal);
let (opts, llvm_target, arch) = base("macos", Arch::I686, TargetEnv::Normal);
Target {
llvm_target,
metadata: TargetMetadata {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_target/src/spec/targets/x86_64_apple_darwin.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::spec::base::apple::{Arch, TargetAbi, base};
use crate::spec::base::apple::{Arch, TargetEnv, base};
use crate::spec::{FramePointer, SanitizerSet, Target, TargetMetadata, TargetOptions};

pub(crate) fn target() -> Target {
let (opts, llvm_target, arch) = base("macos", Arch::X86_64, TargetAbi::Normal);
let (opts, llvm_target, arch) = base("macos", Arch::X86_64, TargetEnv::Normal);
Target {
llvm_target,
metadata: TargetMetadata {
Expand Down
Loading
Loading