Skip to content

Commit 4f6f433

Browse files
committed
Support for visionOS
1 parent 21d94a3 commit 4f6f433

File tree

45 files changed

+550
-29
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+550
-29
lines changed

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,7 @@ fn target_is_apple(cgcx: &CodegenContext<LlvmCodegenBackend>) -> bool {
912912
|| cgcx.opts.target_triple.triple().contains("-darwin")
913913
|| cgcx.opts.target_triple.triple().contains("-tvos")
914914
|| cgcx.opts.target_triple.triple().contains("-watchos")
915+
|| cgcx.opts.target_triple.triple().contains("-visionos")
915916
}
916917

917918
fn target_is_aix(cgcx: &CodegenContext<LlvmCodegenBackend>) -> bool {

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2941,7 +2941,7 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
29412941
let os = &sess.target.os;
29422942
let llvm_target = &sess.target.llvm_target;
29432943
if sess.target.vendor != "apple"
2944-
|| !matches!(os.as_ref(), "ios" | "tvos" | "watchos" | "macos")
2944+
|| !matches!(os.as_ref(), "ios" | "tvos" | "watchos" | "visionos" | "macos")
29452945
|| !matches!(flavor, LinkerFlavor::Darwin(..))
29462946
{
29472947
return;
@@ -2966,6 +2966,8 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
29662966
("arm64_32", "watchos") => "watchos",
29672967
("aarch64", "watchos") if llvm_target.ends_with("-simulator") => "watchsimulator",
29682968
("aarch64", "watchos") => "watchos",
2969+
("aarch64", "visionos") if llvm_target.ends_with("-simulator") => "xrsimulator",
2970+
("aarch64", "visionos") => "visionos",
29692971
("arm", "watchos") => "watchos",
29702972
(_, "macos") => "macosx",
29712973
_ => {
@@ -3022,6 +3024,12 @@ fn get_apple_sdk_root(sdk_name: &str) -> Result<String, errors::AppleSdkRootErro
30223024
|| sdkroot.contains("MacOSX.platform") => {}
30233025
"watchsimulator"
30243026
if sdkroot.contains("WatchOS.platform") || sdkroot.contains("MacOSX.platform") => {}
3027+
"visionos"
3028+
if sdkroot.contains("visionos.platform") || sdkroot.contains("MacOSX.platform") => {
3029+
}
3030+
"visionossimulator"
3031+
if sdkroot.contains("visionos.platform") || sdkroot.contains("MacOSX.platform") => {
3032+
}
30253033
// Ignore `SDKROOT` if it's not a valid path.
30263034
_ if !p.is_absolute() || p == Path::new("/") || !p.exists() => {}
30273035
_ => return Ok(sdkroot),

compiler/rustc_target/src/spec/base/apple/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ fn pre_link_args(os: &'static str, arch: Arch, abi: &'static str) -> LinkArgs {
102102
"ios" => ios_deployment_target(arch, abi),
103103
"tvos" => tvos_deployment_target(),
104104
"watchos" => watchos_deployment_target(),
105+
"visionos" => visionos_deployment_target(),
105106
"macos" => macos_deployment_target(arch),
106107
_ => unreachable!(),
107108
};
@@ -202,6 +203,8 @@ pub fn sdk_version(platform: u32) -> Option<(u32, u32)> {
202203
| object::macho::PLATFORM_TVOSSIMULATOR
203204
| object::macho::PLATFORM_MACCATALYST => Some((16, 2)),
204205
object::macho::PLATFORM_WATCHOS | object::macho::PLATFORM_WATCHOSSIMULATOR => Some((9, 1)),
206+
// FIXME: Upgrade to yet unreleased `object-rs` implementation with visionos platform definition
207+
11 | 12 => Some((1, 0)),
205208
_ => None,
206209
}
207210
}
@@ -216,6 +219,9 @@ pub fn platform(target: &Target) -> Option<u32> {
216219
("watchos", _) => object::macho::PLATFORM_WATCHOS,
217220
("tvos", "sim") => object::macho::PLATFORM_TVOSSIMULATOR,
218221
("tvos", _) => object::macho::PLATFORM_TVOS,
222+
// FIXME: Upgrade to yet unreleased `object-rs` implementation with visionos platform definition
223+
("visionos", "sim") => 12,
224+
("visionos", _) => 11,
219225
_ => return None,
220226
})
221227
}
@@ -240,6 +246,7 @@ pub fn deployment_target(target: &Target) -> Option<(u32, u32)> {
240246
}
241247
"watchos" => watchos_deployment_target(),
242248
"tvos" => tvos_deployment_target(),
249+
"visionos" => visionos_deployment_target(),
243250
_ => return None,
244251
};
245252

@@ -290,6 +297,7 @@ fn link_env_remove(os: &'static str) -> StaticCow<[StaticCow<str>]> {
290297
|| sdkroot.contains("AppleTVSimulator.platform")
291298
|| sdkroot.contains("WatchOS.platform")
292299
|| sdkroot.contains("WatchSimulator.platform")
300+
|| sdkroot.contains("visionos.platform")
293301
{
294302
env_remove.push("SDKROOT".into())
295303
}
@@ -299,6 +307,7 @@ fn link_env_remove(os: &'static str) -> StaticCow<[StaticCow<str>]> {
299307
// although this is apparently ignored when using the linker at "/usr/bin/ld".
300308
env_remove.push("IPHONEOS_DEPLOYMENT_TARGET".into());
301309
env_remove.push("TVOS_DEPLOYMENT_TARGET".into());
310+
env_remove.push("visionos_DEPLOYMENT_TARGET".into());
302311
env_remove.into()
303312
} else {
304313
// Otherwise if cross-compiling for a different OS/SDK (including Mac Catalyst), remove any part
@@ -363,3 +372,18 @@ pub fn watchos_sim_llvm_target(arch: Arch) -> String {
363372
let (major, minor) = watchos_deployment_target();
364373
format!("{}-apple-watchos{}.{}.0-simulator", arch.target_name(), major, minor)
365374
}
375+
376+
fn visionos_deployment_target() -> (u32, u32) {
377+
// If you are looking for the default deployment target, prefer `rustc --print deployment-target`.
378+
from_set_deployment_target("XROS_DEPLOYMENT_TARGET").unwrap_or((1, 0))
379+
}
380+
381+
pub fn visionos_llvm_target(arch: Arch) -> String {
382+
let (major, minor) = visionos_deployment_target();
383+
format!("{}-apple-visionos{}.{}.0", arch.target_name(), major, minor)
384+
}
385+
386+
pub fn visionos_sim_llvm_target(arch: Arch) -> String {
387+
let (major, minor) = visionos_deployment_target();
388+
format!("{}-apple-visionos{}.{}.0-simulator", arch.target_name(), major, minor)
389+
}

compiler/rustc_target/src/spec/base/apple/tests.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::spec::targets::{
2-
aarch64_apple_darwin, aarch64_apple_ios_sim, aarch64_apple_watchos_sim, i686_apple_darwin,
3-
x86_64_apple_darwin, x86_64_apple_ios, x86_64_apple_tvos, x86_64_apple_watchos_sim,
2+
aarch64_apple_darwin, aarch64_apple_ios_sim, aarch64_apple_visionos_sim,
3+
aarch64_apple_watchos_sim, i686_apple_darwin, x86_64_apple_darwin, x86_64_apple_ios,
4+
x86_64_apple_tvos, x86_64_apple_watchos_sim,
45
};
56

67
#[test]
@@ -12,6 +13,7 @@ fn simulator_targets_set_abi() {
1213
aarch64_apple_ios_sim::target(),
1314
// Note: There is currently no ARM64 tvOS simulator target
1415
aarch64_apple_watchos_sim::target(),
16+
aarch64_apple_visionos_sim::target(),
1517
];
1618

1719
for target in &all_sim_targets {

compiler/rustc_target/src/spec/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,9 @@ supported_targets! {
15571557
("aarch64-apple-watchos", aarch64_apple_watchos),
15581558
("aarch64-apple-watchos-sim", aarch64_apple_watchos_sim),
15591559

1560+
("aarch64-apple-visionos", aarch64_apple_visionos),
1561+
("aarch64-apple-visionos-sim", aarch64_apple_visionos_sim),
1562+
15601563
("armebv7r-none-eabi", armebv7r_none_eabi),
15611564
("armebv7r-none-eabihf", armebv7r_none_eabihf),
15621565
("armv7r-none-eabi", armv7r_none_eabi),
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use crate::spec::base::apple::{opts, visionos_llvm_target, Arch};
2+
use crate::spec::{FramePointer, SanitizerSet, Target, TargetOptions};
3+
4+
pub fn target() -> Target {
5+
let arch = Arch::Arm64;
6+
let mut base = opts("visionos", arch);
7+
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::THREAD;
8+
9+
Target {
10+
llvm_target: visionos_llvm_target(arch).into(),
11+
description: None,
12+
pointer_width: 64,
13+
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(),
14+
arch: arch.target_arch(),
15+
options: TargetOptions {
16+
features: "+neon,+fp-armv8,+apple-a12".into(),
17+
max_atomic_width: Some(128),
18+
frame_pointer: FramePointer::NonLeaf,
19+
..base
20+
},
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use crate::spec::base::apple::{opts, visionos_sim_llvm_target, Arch};
2+
use crate::spec::{FramePointer, SanitizerSet, Target, TargetOptions};
3+
4+
pub fn target() -> Target {
5+
let arch = Arch::Arm64_sim;
6+
let mut base = opts("visionos", arch);
7+
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::THREAD;
8+
9+
Target {
10+
llvm_target: visionos_sim_llvm_target(arch).into(),
11+
description: None,
12+
pointer_width: 64,
13+
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".into(),
14+
arch: arch.target_arch(),
15+
options: TargetOptions {
16+
features: "+neon,+fp-armv8,+apple-m1".into(),
17+
max_atomic_width: Some(128),
18+
frame_pointer: FramePointer::NonLeaf,
19+
..base
20+
},
21+
}
22+
}

library/std/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ fn main() {
2222
|| target_os == "ios"
2323
|| target_os == "tvos"
2424
|| target_os == "watchos"
25+
|| target_os == "visionos"
2526
|| target_os == "windows"
2627
|| target_os == "fuchsia"
2728
|| (target_vendor == "fortanix" && target_env == "sgx")

library/std/src/fs/tests.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,8 +1644,8 @@ fn test_file_times() {
16441644
use crate::os::macos::fs::FileTimesExt;
16451645
#[cfg(target_os = "tvos")]
16461646
use crate::os::tvos::fs::FileTimesExt;
1647-
#[cfg(target_os = "tvos")]
1648-
use crate::os::tvos::fs::FileTimesExt;
1647+
#[cfg(target_os = "visionos")]
1648+
use crate::os::visionos::fs::FileTimesExt;
16491649
#[cfg(target_os = "watchos")]
16501650
use crate::os::watchos::fs::FileTimesExt;
16511651
#[cfg(windows)]
@@ -1662,6 +1662,7 @@ fn test_file_times() {
16621662
target_os = "macos",
16631663
target_os = "ios",
16641664
target_os = "watchos",
1665+
target_os = "visionos",
16651666
target_os = "tvos",
16661667
))]
16671668
let created = SystemTime::UNIX_EPOCH + Duration::from_secs(32123);
@@ -1670,6 +1671,7 @@ fn test_file_times() {
16701671
target_os = "macos",
16711672
target_os = "ios",
16721673
target_os = "watchos",
1674+
target_os = "visionos",
16731675
target_os = "tvos",
16741676
))]
16751677
{
@@ -1701,6 +1703,7 @@ fn test_file_times() {
17011703
target_os = "macos",
17021704
target_os = "ios",
17031705
target_os = "watchos",
1706+
target_os = "visionos",
17041707
target_os = "tvos",
17051708
))]
17061709
{
@@ -1709,14 +1712,22 @@ fn test_file_times() {
17091712
}
17101713

17111714
#[test]
1712-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos"))]
1715+
#[cfg(any(
1716+
target_os = "macos",
1717+
target_os = "ios",
1718+
target_os = "tvos",
1719+
target_os = "watchos",
1720+
target_os = "visionos"
1721+
))]
17131722
fn test_file_times_pre_epoch_with_nanos() {
17141723
#[cfg(target_os = "ios")]
17151724
use crate::os::ios::fs::FileTimesExt;
17161725
#[cfg(target_os = "macos")]
17171726
use crate::os::macos::fs::FileTimesExt;
17181727
#[cfg(target_os = "tvos")]
17191728
use crate::os::tvos::fs::FileTimesExt;
1729+
#[cfg(target_os = "visionos")]
1730+
use crate::os::visionos::fs::FileTimesExt;
17201731
#[cfg(target_os = "watchos")]
17211732
use crate::os::watchos::fs::FileTimesExt;
17221733

library/std/src/os/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ pub mod solid;
149149
pub(crate) mod tvos;
150150
#[cfg(target_os = "uefi")]
151151
pub mod uefi;
152+
#[cfg(target_os = "visionos")]
153+
pub(crate) mod visionos;
152154
#[cfg(target_os = "vita")]
153155
pub mod vita;
154156
#[cfg(target_os = "vxworks")]

0 commit comments

Comments
 (0)