Skip to content

Commit 3296bc7

Browse files
committed
Support for xrOS
1 parent 82c2ed0 commit 3296bc7

File tree

43 files changed

+425
-30
lines changed

Some content is hidden

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

43 files changed

+425
-30
lines changed

Cargo.lock

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,8 +2162,6 @@ checksum = "db13adb97ab515a3691f56e4dbab09283d0b86cb45abd991d8634a9d6f501760"
21622162
[[package]]
21632163
name = "libc"
21642164
version = "0.2.150"
2165-
source = "registry+https://github.com/rust-lang/crates.io-index"
2166-
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
21672165
dependencies = [
21682166
"rustc-std-workspace-core",
21692167
]

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
@@ -2892,7 +2892,7 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
28922892
let os = &sess.target.os;
28932893
let llvm_target = &sess.target.llvm_target;
28942894
if sess.target.vendor != "apple"
2895-
|| !matches!(os.as_ref(), "ios" | "tvos" | "watchos" | "macos")
2895+
|| !matches!(os.as_ref(), "ios" | "tvos" | "watchos" | "xros" | "macos")
28962896
|| !matches!(flavor, LinkerFlavor::Darwin(..))
28972897
{
28982898
return;
@@ -2917,6 +2917,8 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
29172917
("arm64_32", "watchos") => "watchos",
29182918
("aarch64", "watchos") if llvm_target.ends_with("-simulator") => "watchsimulator",
29192919
("aarch64", "watchos") => "watchos",
2920+
("aarch64", "xros") if llvm_target.ends_with("-simulator") => "xrossimulator",
2921+
("aarch64", "xros") => "xros",
29202922
("arm", "watchos") => "watchos",
29212923
(_, "macos") => "macosx",
29222924
_ => {
@@ -2973,6 +2975,9 @@ fn get_apple_sdk_root(sdk_name: &str) -> Result<String, errors::AppleSdkRootErro
29732975
|| sdkroot.contains("MacOSX.platform") => {}
29742976
"watchsimulator"
29752977
if sdkroot.contains("WatchOS.platform") || sdkroot.contains("MacOSX.platform") => {}
2978+
"xros" if sdkroot.contains("XROS.platform") || sdkroot.contains("MacOSX.platform") => {}
2979+
"xrossimulator"
2980+
if sdkroot.contains("XROS.platform") || sdkroot.contains("MacOSX.platform") => {}
29762981
// Ignore `SDKROOT` if it's not a valid path.
29772982
_ if !p.is_absolute() || p == Path::new("/") || !p.exists() => {}
29782983
_ => return Ok(sdkroot),

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

Lines changed: 27 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_lld_platform_version(arch),
103103
"tvos" => tvos_lld_platform_version(),
104104
"watchos" => watchos_lld_platform_version(),
105+
"xros" => xros_lld_platform_version(),
105106
"macos" => macos_lld_platform_version(arch),
106107
_ => unreachable!(),
107108
}
@@ -192,6 +193,7 @@ pub fn sdk_version(platform: u32) -> Option<(u32, u32)> {
192193
| object::macho::PLATFORM_TVOSSIMULATOR
193194
| object::macho::PLATFORM_MACCATALYST => Some((16, 2)),
194195
object::macho::PLATFORM_WATCHOS | object::macho::PLATFORM_WATCHOSSIMULATOR => Some((9, 1)),
196+
object::macho::PLATFORM_XROS | object::macho::PLATFORM_XROSSIMULATOR => Some((1, 0)),
195197
_ => None,
196198
}
197199
}
@@ -206,6 +208,8 @@ pub fn platform(target: &Target) -> Option<u32> {
206208
("watchos", _) => object::macho::PLATFORM_WATCHOS,
207209
("tvos", "sim") => object::macho::PLATFORM_TVOSSIMULATOR,
208210
("tvos", _) => object::macho::PLATFORM_TVOS,
211+
("xros", "sim") => object::macho::PLATFORM_XROSSIMULATOR,
212+
("xros", _) => object::macho::PLATFORM_XROS,
209213
_ => return None,
210214
})
211215
}
@@ -233,6 +237,7 @@ pub fn deployment_target(target: &Target) -> Option<(u32, u32)> {
233237
},
234238
"watchos" => watchos_deployment_target(),
235239
"tvos" => tvos_deployment_target(),
240+
"xros" => xros_deployment_target(),
236241
_ => return None,
237242
};
238243

@@ -288,6 +293,7 @@ fn link_env_remove(arch: Arch, os: &'static str) -> StaticCow<[StaticCow<str>]>
288293
|| sdkroot.contains("AppleTVSimulator.platform")
289294
|| sdkroot.contains("WatchOS.platform")
290295
|| sdkroot.contains("WatchSimulator.platform")
296+
|| sdkroot.contains("XROS.platform")
291297
{
292298
env_remove.push("SDKROOT".into())
293299
}
@@ -297,6 +303,7 @@ fn link_env_remove(arch: Arch, os: &'static str) -> StaticCow<[StaticCow<str>]>
297303
// although this is apparently ignored when using the linker at "/usr/bin/ld".
298304
env_remove.push("IPHONEOS_DEPLOYMENT_TARGET".into());
299305
env_remove.push("TVOS_DEPLOYMENT_TARGET".into());
306+
env_remove.push("XROS_DEPLOYMENT_TARGET".into());
300307
env_remove.into()
301308
} else {
302309
// Otherwise if cross-compiling for a different OS/SDK, remove any part
@@ -377,3 +384,23 @@ pub fn watchos_sim_llvm_target(arch: Arch) -> String {
377384
let (major, minor) = watchos_deployment_target();
378385
format!("{}-apple-watchos{}.{}.0-simulator", arch.target_name(), major, minor)
379386
}
387+
388+
fn xros_deployment_target() -> (u32, u32) {
389+
// If you are looking for the default deployment target, prefer `rustc --print deployment-target`.
390+
from_set_deployment_target("XROS_DEPLOYMENT_TARGET").unwrap_or((1, 0))
391+
}
392+
393+
fn xros_lld_platform_version() -> String {
394+
let (major, minor) = xros_deployment_target();
395+
format!("{major}.{minor}")
396+
}
397+
398+
pub fn xros_llvm_target(arch: Arch) -> String {
399+
let (major, minor) = xros_deployment_target();
400+
format!("{}-apple-xros{}.{}.0", arch.target_name(), major, minor)
401+
}
402+
403+
pub fn xros_sim_llvm_target(arch: Arch) -> String {
404+
let (major, minor) = xros_deployment_target();
405+
format!("{}-apple-xros{}.{}.0-simulator", arch.target_name(), major, minor)
406+
}

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
@@ -14,6 +14,7 @@ fn main() {
1414
|| target.contains("apple-ios")
1515
|| target.contains("apple-tvos")
1616
|| target.contains("apple-watchos")
17+
|| target.contains("apple-xros")
1718
|| target.contains("uwp")
1819
|| target.contains("windows")
1920
|| target.contains("fuchsia")

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)