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

0 commit comments

Comments
 (0)