Skip to content

Commit 9f4a637

Browse files
committed
Support for xrOS
1 parent 9e079a7 commit 9f4a637

File tree

42 files changed

+423
-27
lines changed

Some content is hidden

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

42 files changed

+423
-27
lines changed

Cargo.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6505,3 +6505,7 @@ dependencies = [
65056505
"crossbeam-utils",
65066506
"flate2",
65076507
]
6508+
6509+
[[patch.unused]]
6510+
name = "libc"
6511+
version = "0.2.151"

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ strip = true
118118
rustc-std-workspace-core = { path = 'library/rustc-std-workspace-core' }
119119
rustc-std-workspace-alloc = { path = 'library/rustc-std-workspace-alloc' }
120120
rustc-std-workspace-std = { path = 'library/rustc-std-workspace-std' }
121+
libc = { path = '../libc' }
121122

122123
[patch."https://github.com/rust-lang/rust-clippy"]
123124
clippy_lints = { path = "src/tools/clippy/clippy_lints" }

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,7 @@ fn target_is_apple(cgcx: &CodegenContext<LlvmCodegenBackend>) -> bool {
902902
|| cgcx.opts.target_triple.triple().contains("-darwin")
903903
|| cgcx.opts.target_triple.triple().contains("-tvos")
904904
|| cgcx.opts.target_triple.triple().contains("-watchos")
905+
|| cgcx.opts.target_triple.triple().contains("-xros")
905906
}
906907

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

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2896,7 +2896,7 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
28962896
let os = &sess.target.os;
28972897
let llvm_target = &sess.target.llvm_target;
28982898
if sess.target.vendor != "apple"
2899-
|| !matches!(os.as_ref(), "ios" | "tvos" | "watchos" | "macos")
2899+
|| !matches!(os.as_ref(), "ios" | "tvos" | "watchos" | "xros" | "macos")
29002900
|| !matches!(flavor, LinkerFlavor::Darwin(..))
29012901
{
29022902
return;
@@ -2921,6 +2921,8 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
29212921
("arm64_32", "watchos") => "watchos",
29222922
("aarch64", "watchos") if llvm_target.ends_with("-simulator") => "watchsimulator",
29232923
("aarch64", "watchos") => "watchos",
2924+
("aarch64", "xros") if llvm_target.ends_with("-simulator") => "xrossimulator",
2925+
("aarch64", "xros") => "xros",
29242926
("arm", "watchos") => "watchos",
29252927
(_, "macos") => "macosx",
29262928
_ => {
@@ -2977,6 +2979,9 @@ fn get_apple_sdk_root(sdk_name: &str) -> Result<String, errors::AppleSdkRootErro
29772979
|| sdkroot.contains("MacOSX.platform") => {}
29782980
"watchsimulator"
29792981
if sdkroot.contains("WatchOS.platform") || sdkroot.contains("MacOSX.platform") => {}
2982+
"xros" if sdkroot.contains("XROS.platform") || sdkroot.contains("MacOSX.platform") => {}
2983+
"xrossimulator"
2984+
if sdkroot.contains("XROS.platform") || sdkroot.contains("MacOSX.platform") => {}
29802985
// Ignore `SDKROOT` if it's not a valid path.
29812986
_ if !p.is_absolute() || p == Path::new("/") || !p.exists() => {}
29822987
_ => return Ok(sdkroot),

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

Lines changed: 22 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+
"xros" => xros_deployment_target(),
105106
"macos" => macos_deployment_target(arch),
106107
_ => unreachable!(),
107108
};
@@ -202,6 +203,7 @@ 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+
object::macho::PLATFORM_XROS | object::macho::PLATFORM_XROSSIMULATOR => Some((1, 0)),
205207
_ => None,
206208
}
207209
}
@@ -216,6 +218,8 @@ pub fn platform(target: &Target) -> Option<u32> {
216218
("watchos", _) => object::macho::PLATFORM_WATCHOS,
217219
("tvos", "sim") => object::macho::PLATFORM_TVOSSIMULATOR,
218220
("tvos", _) => object::macho::PLATFORM_TVOS,
221+
("xros", "sim") => object::macho::PLATFORM_XROSSIMULATOR,
222+
("xros", _) => object::macho::PLATFORM_XROS,
219223
_ => return None,
220224
})
221225
}
@@ -240,6 +244,7 @@ pub fn deployment_target(target: &Target) -> Option<(u32, u32)> {
240244
}
241245
"watchos" => watchos_deployment_target(),
242246
"tvos" => tvos_deployment_target(),
247+
"xros" => xros_deployment_target(),
243248
_ => return None,
244249
};
245250

@@ -290,6 +295,7 @@ fn link_env_remove(os: &'static str) -> StaticCow<[StaticCow<str>]> {
290295
|| sdkroot.contains("AppleTVSimulator.platform")
291296
|| sdkroot.contains("WatchOS.platform")
292297
|| sdkroot.contains("WatchSimulator.platform")
298+
|| sdkroot.contains("XROS.platform")
293299
{
294300
env_remove.push("SDKROOT".into())
295301
}
@@ -299,6 +305,7 @@ fn link_env_remove(os: &'static str) -> StaticCow<[StaticCow<str>]> {
299305
// although this is apparently ignored when using the linker at "/usr/bin/ld".
300306
env_remove.push("IPHONEOS_DEPLOYMENT_TARGET".into());
301307
env_remove.push("TVOS_DEPLOYMENT_TARGET".into());
308+
env_remove.push("XROS_DEPLOYMENT_TARGET".into());
302309
env_remove.into()
303310
} else {
304311
// Otherwise if cross-compiling for a different OS/SDK (including Mac Catalyst), remove any part
@@ -363,3 +370,18 @@ pub fn watchos_sim_llvm_target(arch: Arch) -> String {
363370
let (major, minor) = watchos_deployment_target();
364371
format!("{}-apple-watchos{}.{}.0-simulator", arch.target_name(), major, minor)
365372
}
373+
374+
fn xros_deployment_target() -> (u32, u32) {
375+
// If you are looking for the default deployment target, prefer `rustc --print deployment-target`.
376+
from_set_deployment_target("XROS_DEPLOYMENT_TARGET").unwrap_or((1, 0))
377+
}
378+
379+
pub fn xros_llvm_target(arch: Arch) -> String {
380+
let (major, minor) = xros_deployment_target();
381+
format!("{}-apple-xros{}.{}.0", arch.target_name(), major, minor)
382+
}
383+
384+
pub fn xros_sim_llvm_target(arch: Arch) -> String {
385+
let (major, minor) = xros_deployment_target();
386+
format!("{}-apple-xros{}.{}.0-simulator", arch.target_name(), major, minor)
387+
}

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_watchos_sim, aarch64_apple_xros_sim,
3+
i686_apple_darwin, x86_64_apple_darwin, x86_64_apple_ios, x86_64_apple_tvos,
4+
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_xros_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
@@ -1539,6 +1539,9 @@ supported_targets! {
15391539
("aarch64-apple-watchos", aarch64_apple_watchos),
15401540
("aarch64-apple-watchos-sim", aarch64_apple_watchos_sim),
15411541

1542+
("aarch64-apple-xros", aarch64_apple_xros),
1543+
("aarch64-apple-xros-sim", aarch64_apple_xros_sim),
1544+
15421545
("armebv7r-none-eabi", armebv7r_none_eabi),
15431546
("armebv7r-none-eabihf", armebv7r_none_eabihf),
15441547
("armv7r-none-eabi", armv7r_none_eabi),
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use crate::spec::base::apple::{opts, xros_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("xros", arch);
7+
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::THREAD;
8+
9+
Target {
10+
llvm_target: xros_llvm_target(arch).into(),
11+
pointer_width: 64,
12+
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
13+
arch: arch.target_arch(),
14+
options: TargetOptions {
15+
features: "+neon,+fp-armv8,+apple-a7".into(),
16+
max_atomic_width: Some(128),
17+
frame_pointer: FramePointer::NonLeaf,
18+
..base
19+
},
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use crate::spec::base::apple::{opts, xros_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("xros", arch);
7+
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::THREAD;
8+
9+
Target {
10+
llvm_target: xros_sim_llvm_target(arch).into(),
11+
pointer_width: 64,
12+
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".into(),
13+
arch: arch.target_arch(),
14+
options: TargetOptions {
15+
features: "+neon,+fp-armv8,+apple-a7".into(),
16+
max_atomic_width: Some(128),
17+
frame_pointer: FramePointer::NonLeaf,
18+
..base
19+
},
20+
}
21+
}

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 == "xros"
2526
|| target_os == "windows"
2627
|| target_os == "fuchsia"
2728
|| (target_vendor == "fortanix" && target_env == "sgx")

library/std/src/fs/tests.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,10 +1646,10 @@ fn test_file_times() {
16461646
use crate::os::macos::fs::FileTimesExt;
16471647
#[cfg(target_os = "tvos")]
16481648
use crate::os::tvos::fs::FileTimesExt;
1649-
#[cfg(target_os = "tvos")]
1650-
use crate::os::tvos::fs::FileTimesExt;
16511649
#[cfg(target_os = "watchos")]
16521650
use crate::os::watchos::fs::FileTimesExt;
1651+
#[cfg(target_os = "xros")]
1652+
use crate::os::xros::fs::FileTimesExt;
16531653
#[cfg(windows)]
16541654
use crate::os::windows::fs::FileTimesExt;
16551655

@@ -1664,6 +1664,7 @@ fn test_file_times() {
16641664
target_os = "macos",
16651665
target_os = "ios",
16661666
target_os = "watchos",
1667+
target_os = "xros",
16671668
target_os = "tvos",
16681669
))]
16691670
let created = SystemTime::UNIX_EPOCH + Duration::from_secs(32123);
@@ -1672,6 +1673,7 @@ fn test_file_times() {
16721673
target_os = "macos",
16731674
target_os = "ios",
16741675
target_os = "watchos",
1676+
target_os = "xros",
16751677
target_os = "tvos",
16761678
))]
16771679
{
@@ -1703,6 +1705,7 @@ fn test_file_times() {
17031705
target_os = "macos",
17041706
target_os = "ios",
17051707
target_os = "watchos",
1708+
target_os = "xros",
17061709
target_os = "tvos",
17071710
))]
17081711
{
@@ -1711,7 +1714,7 @@ fn test_file_times() {
17111714
}
17121715

17131716
#[test]
1714-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos"))]
1717+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "xros"))]
17151718
fn test_file_times_pre_epoch_with_nanos() {
17161719
#[cfg(target_os = "ios")]
17171720
use crate::os::ios::fs::FileTimesExt;
@@ -1721,6 +1724,8 @@ fn test_file_times_pre_epoch_with_nanos() {
17211724
use crate::os::tvos::fs::FileTimesExt;
17221725
#[cfg(target_os = "watchos")]
17231726
use crate::os::watchos::fs::FileTimesExt;
1727+
#[cfg(target_os = "xros")]
1728+
use crate::os::xros::fs::FileTimesExt;
17241729

17251730
let tmp = tmpdir();
17261731
let file = File::create(tmp.join("foo")).unwrap();

library/std/src/os/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ pub mod vxworks;
154154
pub(crate) mod watchos;
155155
#[cfg(target_os = "xous")]
156156
pub mod xous;
157+
#[cfg(target_os = "xros")]
158+
pub(crate) mod xros;
157159

158160
#[cfg(any(unix, target_os = "wasi", doc))]
159161
pub mod fd;

library/std/src/os/unix/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ mod platform {
8585
pub use crate::os::vxworks::*;
8686
#[cfg(target_os = "watchos")]
8787
pub use crate::os::watchos::*;
88+
#[cfg(target_os = "xros")]
89+
pub use crate::os::xros::*;
8890
}
8991

9092
pub mod ffi;
@@ -104,6 +106,7 @@ pub mod thread;
104106
target_os = "ios",
105107
target_os = "tvos",
106108
target_os = "watchos",
109+
target_os = "xros",
107110
target_os = "macos",
108111
target_os = "netbsd",
109112
target_os = "openbsd",

library/std/src/os/unix/net/stream.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, Owned
1414
target_os = "tvos",
1515
target_os = "macos",
1616
target_os = "watchos",
17+
target_os = "xros",
1718
target_os = "netbsd",
1819
target_os = "openbsd"
1920
))]
@@ -34,6 +35,7 @@ use crate::time::Duration;
3435
target_os = "tvos",
3536
target_os = "macos",
3637
target_os = "watchos",
38+
target_os = "xros",
3739
target_os = "netbsd",
3840
target_os = "openbsd"
3941
))]
@@ -243,6 +245,7 @@ impl UnixStream {
243245
target_os = "tvos",
244246
target_os = "macos",
245247
target_os = "watchos",
248+
target_os = "xros",
246249
target_os = "netbsd",
247250
target_os = "openbsd"
248251
))]

library/std/src/os/unix/ucred.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub use self::impl_linux::peer_cred;
3636
))]
3737
pub use self::impl_bsd::peer_cred;
3838

39-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos"))]
39+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "xros"))]
4040
pub use self::impl_mac::peer_cred;
4141

4242
#[cfg(any(target_os = "linux", target_os = "android"))]
@@ -98,7 +98,7 @@ pub mod impl_bsd {
9898
}
9999
}
100100

101-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos"))]
101+
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos", target_os = "xros"))]
102102
pub mod impl_mac {
103103
use super::UCred;
104104
use crate::os::unix::io::AsRawFd;

library/std/src/os/unix/ucred/tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use libc::{getegid, geteuid, getpid};
1111
target_os = "tvos",
1212
target_os = "macos",
1313
target_os = "watchos",
14+
target_os = "xros",
1415
target_os = "openbsd"
1516
))]
1617
fn test_socket_pair() {
@@ -32,6 +33,7 @@ fn test_socket_pair() {
3233
target_os = "ios",
3334
target_os = "macos",
3435
target_os = "watchos",
36+
target_os = "xros",
3537
target_os = "tvos",
3638
))]
3739
fn test_socket_pair_pids(arg: Type) -> RetType {

0 commit comments

Comments
 (0)