Skip to content

Commit e80a19d

Browse files
authored
Add visionOS support (#1029)
* Add visionOS support * Fix visionOS deployment target name * Do not emit -mxros-version-min=... as that is not yet supported * Add simple test * Only run test on newer Xcode versions
1 parent f313ff5 commit e80a19d

File tree

2 files changed

+91
-11
lines changed

2 files changed

+91
-11
lines changed

src/lib.rs

+65-11
Original file line numberDiff line numberDiff line change
@@ -1892,6 +1892,7 @@ impl Build {
18921892
if !target.contains("apple-ios")
18931893
&& !target.contains("apple-watchos")
18941894
&& !target.contains("apple-tvos")
1895+
&& !target.contains("apple-visionos")
18951896
{
18961897
cmd.push_cc_arg("-ffunction-sections".into());
18971898
cmd.push_cc_arg("-fdata-sections".into());
@@ -2033,6 +2034,42 @@ impl Build {
20332034
format!("--target={}-apple-tvos{}", arch, deployment_target).into(),
20342035
);
20352036
}
2037+
} else if target.contains("visionos-sim") {
2038+
if let Some(arch) =
2039+
map_darwin_target_from_rust_to_compiler_architecture(target)
2040+
{
2041+
let sdk_details = apple_os_sdk_parts(
2042+
AppleOs::VisionOS,
2043+
&AppleArchSpec::Simulator(""),
2044+
);
2045+
let deployment_target = self.apple_deployment_version(
2046+
AppleOs::VisionOS,
2047+
None,
2048+
&sdk_details.sdk,
2049+
);
2050+
cmd.args.push(
2051+
format!(
2052+
"--target={}-apple-xros{}-simulator",
2053+
arch, deployment_target
2054+
)
2055+
.into(),
2056+
);
2057+
}
2058+
} else if target.contains("visionos") {
2059+
if let Some(arch) =
2060+
map_darwin_target_from_rust_to_compiler_architecture(target)
2061+
{
2062+
let sdk_details =
2063+
apple_os_sdk_parts(AppleOs::VisionOS, &AppleArchSpec::Device(""));
2064+
let deployment_target = self.apple_deployment_version(
2065+
AppleOs::VisionOS,
2066+
None,
2067+
&sdk_details.sdk,
2068+
);
2069+
cmd.args.push(
2070+
format!("--target={}-apple-xros{}", arch, deployment_target).into(),
2071+
);
2072+
}
20362073
} else if let Ok(index) = target_info::RISCV_ARCH_MAPPING
20372074
.binary_search_by_key(&arch, |(arch, _)| &arch)
20382075
{
@@ -2536,6 +2573,8 @@ impl Build {
25362573
AppleOs::WatchOs
25372574
} else if target.contains("-tvos") {
25382575
AppleOs::TvOs
2576+
} else if target.contains("-visionos") {
2577+
AppleOs::VisionOS
25392578
} else {
25402579
AppleOs::Ios
25412580
};
@@ -2625,9 +2664,14 @@ impl Build {
26252664
AppleArchSpec::Device(arch) => {
26262665
cmd.args.push("-arch".into());
26272666
cmd.args.push(arch.into());
2628-
cmd.args.push(
2629-
format!("-m{}os-version-min={}", sdk_details.sdk_prefix, min_version).into(),
2630-
);
2667+
// `-mxros-version-min` does not exist
2668+
// https://github.com/llvm/llvm-project/issues/88271
2669+
if os != AppleOs::VisionOS {
2670+
cmd.args.push(
2671+
format!("-m{}os-version-min={}", sdk_details.sdk_prefix, min_version)
2672+
.into(),
2673+
);
2674+
}
26312675
}
26322676
AppleArchSpec::Simulator(arch) => {
26332677
if arch.starts_with('-') {
@@ -2637,13 +2681,15 @@ impl Build {
26372681
cmd.args.push("-arch".into());
26382682
cmd.args.push(arch.into());
26392683
}
2640-
cmd.args.push(
2641-
format!(
2642-
"-m{}simulator-version-min={}",
2643-
sdk_details.sim_prefix, min_version
2644-
)
2645-
.into(),
2646-
);
2684+
if os != AppleOs::VisionOS {
2685+
cmd.args.push(
2686+
format!(
2687+
"-m{}simulator-version-min={}",
2688+
sdk_details.sim_prefix, min_version
2689+
)
2690+
.into(),
2691+
);
2692+
}
26472693
}
26482694
AppleArchSpec::Catalyst(_) => {}
26492695
};
@@ -2805,6 +2851,7 @@ impl Build {
28052851
} else if target.contains("apple-ios")
28062852
| target.contains("apple-watchos")
28072853
| target.contains("apple-tvos")
2854+
| target.contains("apple-visionos")
28082855
{
28092856
clang.to_string()
28102857
} else if target.contains("android") {
@@ -3720,7 +3767,7 @@ impl Build {
37203767
return None;
37213768
}
37223769
}
3723-
// watchOS, tvOS, and others are all new enough that libc++ is their baseline.
3770+
// watchOS, tvOS, visionOS, and others are all new enough that libc++ is their baseline.
37243771
_ => {}
37253772
}
37263773

@@ -3764,6 +3811,10 @@ impl Build {
37643811
AppleOs::TvOs => deployment_from_env("TVOS_DEPLOYMENT_TARGET")
37653812
.or_else(default_deployment_from_sdk)
37663813
.unwrap_or_else(|| "9.0".into()),
3814+
3815+
AppleOs::VisionOS => deployment_from_env("XROS_DEPLOYMENT_TARGET")
3816+
.or_else(default_deployment_from_sdk)
3817+
.unwrap_or_else(|| "1.0".into()),
37673818
}
37683819
}
37693820

@@ -3792,6 +3843,7 @@ enum AppleOs {
37923843
Ios,
37933844
WatchOs,
37943845
TvOs,
3846+
VisionOS,
37953847
}
37963848

37973849
impl std::fmt::Debug for AppleOs {
@@ -3801,6 +3853,7 @@ impl std::fmt::Debug for AppleOs {
38013853
AppleOs::Ios => f.write_str("iOS"),
38023854
AppleOs::WatchOs => f.write_str("WatchOS"),
38033855
AppleOs::TvOs => f.write_str("AppleTVOS"),
3856+
AppleOs::VisionOS => f.write_str("visionOS"),
38043857
}
38053858
}
38063859
}
@@ -3817,6 +3870,7 @@ fn apple_os_sdk_parts(os: AppleOs, arch: &AppleArchSpec) -> AppleSdkTargetParts
38173870
AppleOs::Ios => ("iphone", "ios-"),
38183871
AppleOs::WatchOs => ("watch", "watch"),
38193872
AppleOs::TvOs => ("appletv", "appletv"),
3873+
AppleOs::VisionOS => ("xr", "xr"),
38203874
};
38213875
let sdk = match arch {
38223876
AppleArchSpec::Device(_) if os == AppleOs::MacOs => Cow::Borrowed("macosx"),

tests/test.rs

+26
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,32 @@ fn clang_apple_tvsimulator() {
600600
}
601601
}
602602

603+
#[cfg(target_os = "macos")]
604+
#[test]
605+
fn clang_apple_visionos() {
606+
// Only run this test if visionOS is available on the host machine
607+
let output = std::process::Command::new("xcrun")
608+
.args(["--show-sdk-version", "--sdk", "xros"])
609+
.output()
610+
.unwrap();
611+
if !output.status.success() {
612+
return;
613+
}
614+
615+
let test = Test::clang();
616+
test.gcc()
617+
.__set_env("XROS_DEPLOYMENT_TARGET", "1.0")
618+
.target("aarch64-apple-visionos")
619+
.file("foo.c")
620+
.compile("foo");
621+
622+
dbg!(test.cmd(0).args);
623+
624+
test.cmd(0).must_have("--target=arm64-apple-xros1.0");
625+
test.cmd(0).must_not_have("-mxros-version-min=1.0");
626+
test.cmd(0).must_not_have("-mxrsimulator-version-min=1.0");
627+
}
628+
603629
#[test]
604630
fn compile_intermediates() {
605631
let test = Test::gnu();

0 commit comments

Comments
 (0)