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")

0 commit comments

Comments
 (0)