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

Support Apple Vision Pro #223

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ jobs:
matrix:
os: [ macOS-13, macOS-14 ]
sim: [ tvOS, watchOS ]
include:
- os: macos-14
sim: visionOS

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you add here:

            xcode_version: 15.2

then before you run the shell script you can add a step:

      - if: ${{ matrix.xcode_version != '' }}
        run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode_version }}.app

This is what I've done in my CI.

runs-on: ${{matrix.os}}

steps:
Expand Down
4 changes: 3 additions & 1 deletion .travis.apple-third-tier.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ then
if [ "$(uname -m)" = "arm64" ]; then
title "••••• Darwin: visionOS simulator tests •••••"
title "boot a simulator"
xcrun simctl list devicetypes vision
xcrun simctl list devices vision
system_profiler SPDeveloperToolsDataType
xcodebuild -showsdks
Comment on lines +99 to +101
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After looking into this a bit, the current default xcode used on the macOS-14 runner is 15.0.1. The visionOS simulator requires xcode 15.2+ and I don't feel like adding in the logic to switch between xcode versions in this CI.

Also, actions/runner-images#9511

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, this still applies. I can either remove visionOS from the CI matrix or we can wait until the macos runner updates the default xcode. I'm not sure what the xcode versioning policy is (if there is one) on github runners.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we do all the steps, including creating the simulator and deleting it, but making the steps that fail (presumably just lines 106 or 107) conditional:

if [ -z "${GITHUB_ACTIONS}" ]; then
   # These steps fail in GitHub Actions due to https://...
fi

VISIONOS_DEVICE_TYPE=$(xcrun simctl list devicetypes vision -j | jq -r '.devicetypes[0].identifier')
VISIONOS_RUNTIME_ID=$(xcrun simctl list runtimes | grep visionOS | cut -d ' ' -f 7 | tail -1)
export VISIONOS_SIM_ID=$(xcrun simctl create My-apple-vision-pro $VISIONOS_DEVICE_TYPE $VISIONOS_RUNTIME_ID)
Expand Down
45 changes: 45 additions & 0 deletions dinghy-lib/src/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ pub enum AppleSimulatorType {
Ios,
Watchos,
Tvos,
Visionos,
}
impl Display for AppleSimulatorType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let val = match self {
AppleSimulatorType::Ios => "ios",
AppleSimulatorType::Watchos => "watchos",
AppleSimulatorType::Tvos => "tvos",
AppleSimulatorType::Visionos => "visionos",
};
f.write_str(val)
}
Expand Down Expand Up @@ -197,6 +199,49 @@ impl PlatformManager for TvosManager {
}
}

pub struct VisionosManager {
devices: Vec<Box<dyn Device>>,
}

impl VisionosManager {
pub fn new() -> Result<Option<Self>> {
let devices = simulators(AppleSimulatorType::Visionos)?;
Ok(Some(Self { devices }))
}
}

impl PlatformManager for VisionosManager {
fn devices(&self) -> Result<Vec<Box<dyn Device>>> {
Ok(self.devices.clone())
}

fn platforms(&self) -> Result<Vec<Box<dyn Platform>>> {
["aarch64", "aarch64-sim"]
.iter()
.map(|arch| {
let id = format!("auto-visionos-{}", arch);
let rustc_triple = if *arch != "aarch64-sim" {
format!("{}-apple-visionos", arch)
} else {
format!("aarch64-apple-visionos-sim")
};
let simulator = if *arch == "aarch64-sim" {
Some(AppleSimulatorType::Visionos)
} else {
None
};
AppleDevicePlatform::new(
id,
&rustc_triple,
simulator,
crate::config::PlatformConfiguration::default(),
)
.map(|pf| pf as Box<dyn Platform>)
})
.collect()
}
}

fn simulators(sim_type: AppleSimulatorType) -> Result<Vec<Box<dyn Device>>> {
let sims_list = ::std::process::Command::new("xcrun")
.args(&[
Expand Down
6 changes: 6 additions & 0 deletions dinghy-lib/src/apple/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ impl AppleDevicePlatform {
Some(AppleSimulatorType::Watchos) => {
"watchsimulator"
}
Some(AppleSimulatorType::Visionos) => {
// xros and xrsimulator are sdk names.
// See https://github.com/rust-lang/rust/pull/121419#discussion_r1501908152 for
// more inconsistencies about visionOS and xrOS.
"xrsimulator"
}
None => "iphoneos"
};
let xcrun = process::Command::new("xcrun")
Expand Down
6 changes: 6 additions & 0 deletions dinghy-lib/src/apple/xcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ pub fn add_plist_to_app(
writeln!(plist, "<key>WKApplication</key><true/>",)?;
writeln!(plist, "<key>WKWatchOnly</key><true/>")?;
}
Some(AppleSimulatorType::Visionos) => {
writeln!(
plist,
"<key>UIDeviceFamily</key> <array> <integer>7</integer> </array>"
)?;
}
}
writeln!(plist, r#"</dict></plist>"#)?;
Ok(())
Expand Down
4 changes: 4 additions & 0 deletions dinghy-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use crate::apple::{
IosManager,
TvosManager,
WatchosManager,
VisionosManager,
};

use crate::platform::regular_platform::RegularPlatform;
Expand Down Expand Up @@ -71,6 +72,9 @@ impl Dinghy {
if let Some(man) = WatchosManager::new().context("Could not initialize tvOS manager")? {
managers.push(Box::new(man));
}
if let Some(man) = VisionosManager::new().context("Could not initialize tvOS manager")? {
managers.push(Box::new(man));
}
}

let mut devices = vec![];
Expand Down
2 changes: 2 additions & 0 deletions dinghy-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub fn test_project_path() -> PathBuf {
target_os = "ios",
target_os = "watchos",
target_os = "tvos",
target_os = "visionos",
target_os = "android"
)) || env::var("DINGHY").is_ok() {
let current_exe = env::current_exe().expect("Current exe path not accessible");
Expand Down Expand Up @@ -37,6 +38,7 @@ pub fn try_test_file_path(test_data_id: &str) -> Option<PathBuf> {
target_os = "ios",
target_os = "watchos",
target_os = "tvos",
target_os = "visionos",
target_os = "android"
)) || env::var("DINGHY").is_ok() {
current_exe
Expand Down
Loading