Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add visionOS support #1029

Merged
merged 5 commits into from
Apr 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1892,6 +1892,7 @@ impl Build {
if !target.contains("apple-ios")
&& !target.contains("apple-watchos")
&& !target.contains("apple-tvos")
&& !target.contains("apple-visionos")
{
cmd.push_cc_arg("-ffunction-sections".into());
cmd.push_cc_arg("-fdata-sections".into());
Expand Down Expand Up @@ -2033,6 +2034,42 @@ impl Build {
format!("--target={}-apple-tvos{}", arch, deployment_target).into(),
);
}
} else if target.contains("visionos-sim") {
if let Some(arch) =
map_darwin_target_from_rust_to_compiler_architecture(target)
{
let sdk_details = apple_os_sdk_parts(
AppleOs::VisionOS,
&AppleArchSpec::Simulator(""),
);
let deployment_target = self.apple_deployment_version(
AppleOs::VisionOS,
None,
&sdk_details.sdk,
);
cmd.args.push(
format!(
"--target={}-apple-xros{}-simulator",
arch, deployment_target
)
.into(),
);
}
} else if target.contains("visionos") {
if let Some(arch) =
map_darwin_target_from_rust_to_compiler_architecture(target)
{
let sdk_details =
apple_os_sdk_parts(AppleOs::VisionOS, &AppleArchSpec::Device(""));
let deployment_target = self.apple_deployment_version(
AppleOs::VisionOS,
None,
&sdk_details.sdk,
);
cmd.args.push(
format!("--target={}-apple-xros{}", arch, deployment_target).into(),
);
}
} else if let Ok(index) = target_info::RISCV_ARCH_MAPPING
.binary_search_by_key(&arch, |(arch, _)| &arch)
{
Expand Down Expand Up @@ -2536,6 +2573,8 @@ impl Build {
AppleOs::WatchOs
} else if target.contains("-tvos") {
AppleOs::TvOs
} else if target.contains("-visionos") {
AppleOs::VisionOS
} else {
AppleOs::Ios
};
Expand Down Expand Up @@ -2805,6 +2844,7 @@ impl Build {
} else if target.contains("apple-ios")
| target.contains("apple-watchos")
| target.contains("apple-tvos")
| target.contains("apple-visionos")
{
clang.to_string()
} else if target.contains("android") {
Expand Down Expand Up @@ -3720,7 +3760,7 @@ impl Build {
return None;
}
}
// watchOS, tvOS, and others are all new enough that libc++ is their baseline.
// watchOS, tvOS, visionOS, and others are all new enough that libc++ is their baseline.
_ => {}
}

Expand Down Expand Up @@ -3764,6 +3804,10 @@ impl Build {
AppleOs::TvOs => deployment_from_env("TVOS_DEPLOYMENT_TARGET")
.or_else(default_deployment_from_sdk)
.unwrap_or_else(|| "9.0".into()),

AppleOs::VisionOS => deployment_from_env("VISIONOS_DEPLOYMENT_TARGET")
madsmtm marked this conversation as resolved.
Show resolved Hide resolved
.or_else(default_deployment_from_sdk)
.unwrap_or_else(|| "1.0".into()),
}
}

Expand Down Expand Up @@ -3792,6 +3836,7 @@ enum AppleOs {
Ios,
WatchOs,
TvOs,
VisionOS,
}

impl std::fmt::Debug for AppleOs {
Expand All @@ -3801,6 +3846,7 @@ impl std::fmt::Debug for AppleOs {
AppleOs::Ios => f.write_str("iOS"),
AppleOs::WatchOs => f.write_str("WatchOS"),
AppleOs::TvOs => f.write_str("AppleTVOS"),
AppleOs::VisionOS => f.write_str("visionOS"),
}
}
}
Expand All @@ -3817,6 +3863,7 @@ fn apple_os_sdk_parts(os: AppleOs, arch: &AppleArchSpec) -> AppleSdkTargetParts
AppleOs::Ios => ("iphone", "ios-"),
AppleOs::WatchOs => ("watch", "watch"),
AppleOs::TvOs => ("appletv", "appletv"),
AppleOs::VisionOS => ("xr", "xr"),
};
let sdk = match arch {
AppleArchSpec::Device(_) if os == AppleOs::MacOs => Cow::Borrowed("macosx"),
Expand Down