Skip to content
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

Add aarch64-apple-visionos and aarch64-apple-visionos-sim tier 3 targets #121419

Merged
merged 12 commits into from
Apr 6, 2024
1 change: 1 addition & 0 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,7 @@ fn target_is_apple(cgcx: &CodegenContext<LlvmCodegenBackend>) -> bool {
|| cgcx.opts.target_triple.triple().contains("-darwin")
|| cgcx.opts.target_triple.triple().contains("-tvos")
|| cgcx.opts.target_triple.triple().contains("-watchos")
|| cgcx.opts.target_triple.triple().contains("-visionos")
}

fn target_is_aix(cgcx: &CodegenContext<LlvmCodegenBackend>) -> bool {
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2941,7 +2941,7 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
let os = &sess.target.os;
let llvm_target = &sess.target.llvm_target;
if sess.target.vendor != "apple"
|| !matches!(os.as_ref(), "ios" | "tvos" | "watchos" | "macos")
|| !matches!(os.as_ref(), "ios" | "tvos" | "watchos" | "visionos" | "macos")
|| !matches!(flavor, LinkerFlavor::Darwin(..))
{
return;
Expand All @@ -2966,6 +2966,8 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
("arm64_32", "watchos") => "watchos",
("aarch64", "watchos") if llvm_target.ends_with("-simulator") => "watchsimulator",
("aarch64", "watchos") => "watchos",
("aarch64", "visionos") if llvm_target.ends_with("-simulator") => "xrsimulator",
("aarch64", "visionos") => "xros",
("arm", "watchos") => "watchos",
(_, "macos") => "macosx",
_ => {
Expand Down Expand Up @@ -3022,6 +3024,10 @@ fn get_apple_sdk_root(sdk_name: &str) -> Result<String, errors::AppleSdkRootErro
|| sdkroot.contains("MacOSX.platform") => {}
"watchsimulator"
if sdkroot.contains("WatchOS.platform") || sdkroot.contains("MacOSX.platform") => {}
"visionos"
if sdkroot.contains("XROS.platform") || sdkroot.contains("MacOSX.platform") => {}
"visionossimulator"
if sdkroot.contains("XROS.platform") || sdkroot.contains("MacOSX.platform") => {}
// Ignore `SDKROOT` if it's not a valid path.
_ if !p.is_absolute() || p == Path::new("/") || !p.exists() => {}
_ => return Ok(sdkroot),
Expand Down
24 changes: 24 additions & 0 deletions compiler/rustc_target/src/spec/base/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ fn pre_link_args(os: &'static str, arch: Arch, abi: &'static str) -> LinkArgs {
"ios" => ios_deployment_target(arch, abi),
"tvos" => tvos_deployment_target(),
"watchos" => watchos_deployment_target(),
"visionos" => visionos_deployment_target(),
"macos" => macos_deployment_target(arch),
_ => unreachable!(),
};
Expand Down Expand Up @@ -202,6 +203,8 @@ pub fn sdk_version(platform: u32) -> Option<(u32, u32)> {
| object::macho::PLATFORM_TVOSSIMULATOR
| object::macho::PLATFORM_MACCATALYST => Some((16, 2)),
object::macho::PLATFORM_WATCHOS | object::macho::PLATFORM_WATCHOSSIMULATOR => Some((9, 1)),
// FIXME: Upgrade to yet unreleased `object-rs` implementation with visionos platform definition
agg23 marked this conversation as resolved.
Show resolved Hide resolved
11 | 12 => Some((1, 0)),
_ => None,
}
}
Expand All @@ -216,6 +219,9 @@ pub fn platform(target: &Target) -> Option<u32> {
("watchos", _) => object::macho::PLATFORM_WATCHOS,
("tvos", "sim") => object::macho::PLATFORM_TVOSSIMULATOR,
("tvos", _) => object::macho::PLATFORM_TVOS,
// FIXME: Upgrade to yet unreleased `object-rs` implementation with visionos platform definition
("visionos", "sim") => 12,
("visionos", _) => 11,
_ => return None,
})
}
Expand All @@ -240,6 +246,7 @@ pub fn deployment_target(target: &Target) -> Option<(u32, u32)> {
}
"watchos" => watchos_deployment_target(),
"tvos" => tvos_deployment_target(),
"visionos" => visionos_deployment_target(),
_ => return None,
};

Expand Down Expand Up @@ -290,6 +297,7 @@ fn link_env_remove(os: &'static str) -> StaticCow<[StaticCow<str>]> {
|| sdkroot.contains("AppleTVSimulator.platform")
|| sdkroot.contains("WatchOS.platform")
|| sdkroot.contains("WatchSimulator.platform")
|| sdkroot.contains("XROS.platform")
{
env_remove.push("SDKROOT".into())
}
Expand All @@ -299,6 +307,7 @@ fn link_env_remove(os: &'static str) -> StaticCow<[StaticCow<str>]> {
// although this is apparently ignored when using the linker at "/usr/bin/ld".
env_remove.push("IPHONEOS_DEPLOYMENT_TARGET".into());
env_remove.push("TVOS_DEPLOYMENT_TARGET".into());
env_remove.push("XROS_DEPLOYMENT_TARGET".into());
env_remove.into()
} else {
// Otherwise if cross-compiling for a different OS/SDK (including Mac Catalyst), remove any part
Expand Down Expand Up @@ -363,3 +372,18 @@ pub fn watchos_sim_llvm_target(arch: Arch) -> String {
let (major, minor) = watchos_deployment_target();
format!("{}-apple-watchos{}.{}.0-simulator", arch.target_name(), major, minor)
}

fn visionos_deployment_target() -> (u32, u32) {
// If you are looking for the default deployment target, prefer `rustc --print deployment-target`.
from_set_deployment_target("XROS_DEPLOYMENT_TARGET").unwrap_or((1, 0))
}

pub fn visionos_llvm_target(arch: Arch) -> String {
let (major, minor) = visionos_deployment_target();
format!("{}-apple-visionos{}.{}.0", arch.target_name(), major, minor)
}

pub fn visionos_sim_llvm_target(arch: Arch) -> String {
let (major, minor) = visionos_deployment_target();
format!("{}-apple-visionos{}.{}.0-simulator", arch.target_name(), major, minor)
}
12 changes: 9 additions & 3 deletions compiler/rustc_target/src/spec/base/apple/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::spec::targets::{
aarch64_apple_darwin, aarch64_apple_ios_sim, aarch64_apple_watchos_sim, i686_apple_darwin,
x86_64_apple_darwin, x86_64_apple_ios, x86_64_apple_tvos, x86_64_apple_watchos_sim,
aarch64_apple_darwin, aarch64_apple_ios_sim, aarch64_apple_visionos_sim,
aarch64_apple_watchos_sim, i686_apple_darwin, x86_64_apple_darwin, x86_64_apple_ios,
x86_64_apple_tvos, x86_64_apple_watchos_sim,
};

#[test]
Expand All @@ -12,6 +13,7 @@ fn simulator_targets_set_abi() {
aarch64_apple_ios_sim::target(),
// Note: There is currently no ARM64 tvOS simulator target
aarch64_apple_watchos_sim::target(),
aarch64_apple_visionos_sim::target(),
];

for target in &all_sim_targets {
Expand All @@ -32,7 +34,11 @@ fn macos_link_environment_unmodified() {
// for the host.
assert_eq!(
target.link_env_remove,
crate::spec::cvs!["IPHONEOS_DEPLOYMENT_TARGET", "TVOS_DEPLOYMENT_TARGET"],
crate::spec::cvs![
"IPHONEOS_DEPLOYMENT_TARGET",
"TVOS_DEPLOYMENT_TARGET",
"XROS_DEPLOYMENT_TARGET"
],
);
}
}
3 changes: 3 additions & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1557,6 +1557,9 @@ supported_targets! {
("aarch64-apple-watchos", aarch64_apple_watchos),
("aarch64-apple-watchos-sim", aarch64_apple_watchos_sim),

("aarch64-apple-visionos", aarch64_apple_visionos),
("aarch64-apple-visionos-sim", aarch64_apple_visionos_sim),

("armebv7r-none-eabi", armebv7r_none_eabi),
("armebv7r-none-eabihf", armebv7r_none_eabihf),
("armv7r-none-eabi", armv7r_none_eabi),
Expand Down
27 changes: 27 additions & 0 deletions compiler/rustc_target/src/spec/targets/aarch64_apple_visionos.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use crate::spec::base::apple::{opts, visionos_llvm_target, Arch};
use crate::spec::{FramePointer, SanitizerSet, Target, TargetOptions};

pub fn target() -> Target {
let arch = Arch::Arm64;
let mut base = opts("visionos", arch);
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::THREAD;

Target {
llvm_target: visionos_llvm_target(arch).into(),
metadata: crate::spec::TargetMetadata {
description: None,
tier: None,
agg23 marked this conversation as resolved.
Show resolved Hide resolved
host_tools: None,
std: None,
},
pointer_width: 64,
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
arch: arch.target_arch(),
options: TargetOptions {
features: "+neon,+fp-armv8,+apple-a16".into(),
max_atomic_width: Some(128),
frame_pointer: FramePointer::NonLeaf,
..base
},
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use crate::spec::base::apple::{opts, visionos_sim_llvm_target, Arch};
use crate::spec::{FramePointer, SanitizerSet, Target, TargetOptions};

pub fn target() -> Target {
let arch = Arch::Arm64_sim;
let mut base = opts("visionos", arch);
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::THREAD;

Target {
llvm_target: visionos_sim_llvm_target(arch).into(),
metadata: crate::spec::TargetMetadata {
description: None,
tier: None,
host_tools: None,
std: None,
},
pointer_width: 64,
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
arch: arch.target_arch(),
options: TargetOptions {
features: "+neon,+fp-armv8,+apple-a16".into(),
max_atomic_width: Some(128),
frame_pointer: FramePointer::NonLeaf,
..base
},
}
}
1 change: 1 addition & 0 deletions library/std/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ fn main() {
|| target_os == "ios"
|| target_os == "tvos"
|| target_os == "watchos"
|| target_os == "visionos"
|| target_os == "windows"
|| target_os == "fuchsia"
|| (target_vendor == "fortanix" && target_env == "sgx")
Expand Down
17 changes: 14 additions & 3 deletions library/std/src/fs/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1644,8 +1644,8 @@ fn test_file_times() {
use crate::os::macos::fs::FileTimesExt;
#[cfg(target_os = "tvos")]
use crate::os::tvos::fs::FileTimesExt;
#[cfg(target_os = "tvos")]
use crate::os::tvos::fs::FileTimesExt;
#[cfg(target_os = "visionos")]
use crate::os::visionos::fs::FileTimesExt;
#[cfg(target_os = "watchos")]
use crate::os::watchos::fs::FileTimesExt;
#[cfg(windows)]
Expand All @@ -1662,6 +1662,7 @@ fn test_file_times() {
target_os = "macos",
target_os = "ios",
target_os = "watchos",
target_os = "visionos",
target_os = "tvos",
))]
let created = SystemTime::UNIX_EPOCH + Duration::from_secs(32123);
Expand All @@ -1670,6 +1671,7 @@ fn test_file_times() {
target_os = "macos",
target_os = "ios",
target_os = "watchos",
target_os = "visionos",
target_os = "tvos",
))]
{
Expand Down Expand Up @@ -1701,6 +1703,7 @@ fn test_file_times() {
target_os = "macos",
target_os = "ios",
target_os = "watchos",
target_os = "visionos",
target_os = "tvos",
))]
{
Expand All @@ -1709,14 +1712,22 @@ fn test_file_times() {
}

#[test]
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos"))]
#[cfg(any(
target_os = "macos",
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "visionos"
))]
fn test_file_times_pre_epoch_with_nanos() {
#[cfg(target_os = "ios")]
use crate::os::ios::fs::FileTimesExt;
#[cfg(target_os = "macos")]
use crate::os::macos::fs::FileTimesExt;
#[cfg(target_os = "tvos")]
use crate::os::tvos::fs::FileTimesExt;
#[cfg(target_os = "visionos")]
use crate::os::visionos::fs::FileTimesExt;
#[cfg(target_os = "watchos")]
use crate::os::watchos::fs::FileTimesExt;

Expand Down
2 changes: 2 additions & 0 deletions library/std/src/os/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ pub mod solid;
pub(crate) mod tvos;
#[cfg(target_os = "uefi")]
pub mod uefi;
#[cfg(target_os = "visionos")]
pub(crate) mod visionos;
#[cfg(target_os = "vita")]
pub mod vita;
#[cfg(target_os = "vxworks")]
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/os/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ mod platform {
pub use crate::os::solaris::*;
#[cfg(target_os = "tvos")]
pub use crate::os::tvos::*;
#[cfg(target_os = "visionos")]
pub use crate::os::visionos::*;
#[cfg(target_os = "vita")]
pub use crate::os::vita::*;
#[cfg(target_os = "vxworks")]
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/os/unix/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mod tests;
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "visionos",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
Expand All @@ -46,6 +47,7 @@ pub use self::stream::*;
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "visionos",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/os/unix/net/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
target_os = "tvos",
target_os = "macos",
target_os = "watchos",
target_os = "visionos",
target_os = "netbsd",
target_os = "openbsd"
))]
Expand Down Expand Up @@ -233,6 +234,7 @@ impl UnixStream {
target_os = "tvos",
target_os = "macos",
target_os = "watchos",
target_os = "visionos",
target_os = "netbsd",
target_os = "openbsd"
))]
Expand Down
16 changes: 14 additions & 2 deletions library/std/src/os/unix/net/ucred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ pub(super) use self::impl_linux::peer_cred;
))]
pub(super) use self::impl_bsd::peer_cred;

#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos"))]
#[cfg(any(
target_os = "macos",
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "visionos"
))]
pub(super) use self::impl_mac::peer_cred;

#[cfg(any(target_os = "linux", target_os = "android"))]
Expand Down Expand Up @@ -96,7 +102,13 @@ mod impl_bsd {
}
}

#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos"))]
#[cfg(any(
target_os = "macos",
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "visionos"
))]
mod impl_mac {
use super::UCred;
use crate::os::unix::io::AsRawFd;
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/os/unix/net/ucred/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use libc::{getegid, geteuid, getpid};
target_os = "tvos",
target_os = "macos",
target_os = "watchos",
target_os = "visionos",
target_os = "openbsd"
))]
fn test_socket_pair() {
Expand All @@ -32,6 +33,7 @@ fn test_socket_pair() {
target_os = "ios",
target_os = "macos",
target_os = "watchos",
target_os = "visionos",
target_os = "tvos",
))]
fn test_socket_pair_pids(arg: Type) -> RetType {
Expand Down