From 5f9017d5cd618f3052f8fa3285e27cdbcb8f9c5d Mon Sep 17 00:00:00 2001 From: Eugene Hauptmann Date: Thu, 30 May 2024 18:51:46 -0400 Subject: [PATCH 1/9] fix(apple): renamed keys to longer triples --- src/apple/target.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/apple/target.rs b/src/apple/target.rs index d888586f..9dd166a8 100644 --- a/src/apple/target.rs +++ b/src/apple/target.rs @@ -143,14 +143,14 @@ pub struct Target<'a> { } impl<'a> TargetTrait<'a> for Target<'a> { - const DEFAULT_KEY: &'static str = "aarch64"; + const DEFAULT_KEY: &'static str = "aarch64-apple-ios"; fn all() -> &'a BTreeMap<&'a str, Self> { static TARGETS: OnceCell>> = OnceCell::new(); TARGETS.get_or_init(|| { let mut targets = BTreeMap::new(); targets.insert( - "aarch64", + "aarch64-apple-ios", Target { triple: "aarch64-apple-ios", arch: "arm64", @@ -160,7 +160,7 @@ impl<'a> TargetTrait<'a> for Target<'a> { }, ); targets.insert( - "x86_64", + "x86_64-apple-ios", Target { triple: "x86_64-apple-ios", arch: "x86_64", @@ -175,7 +175,7 @@ impl<'a> TargetTrait<'a> for Target<'a> { }, ); targets.insert( - "aarch64-sim", + "aarch64-apple-ios-sim", Target { triple: "aarch64-apple-ios-sim", arch: "arm64-sim", From d3866c1d111b074b94d6b4761490fc4d435ad37a Mon Sep 17 00:00:00 2001 From: Eugene Hauptmann Date: Thu, 30 May 2024 18:54:24 -0400 Subject: [PATCH 2/9] fix(apple): added visionos targets --- src/apple/target.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/apple/target.rs b/src/apple/target.rs index 9dd166a8..8ce968c0 100644 --- a/src/apple/target.rs +++ b/src/apple/target.rs @@ -155,7 +155,7 @@ impl<'a> TargetTrait<'a> for Target<'a> { triple: "aarch64-apple-ios", arch: "arm64", sdk: "iphoneos", - alias: Some("arm64e"), + alias: Some("arm64e-ios"), min_xcode_version: None, }, ); @@ -180,7 +180,27 @@ impl<'a> TargetTrait<'a> for Target<'a> { triple: "aarch64-apple-ios-sim", arch: "arm64-sim", sdk: "iphonesimulator", - alias: Some("arm64e-sim"), + alias: Some("arm64e-ios-sim"), + min_xcode_version: None, + }, + ); + targets.insert( + "aarch64-apple-visionos", + Target { + triple: "aarch64-apple-visionos", + arch: "arm64", + sdk: "xros", + alias: Some("arm64e-xros"), + min_xcode_version: None, + }, + ); + targets.insert( + "aarch64-apple-visionos-sim", + Target { + triple: "aarch64-apple-visionos-sim", + arch: "arm64-sim", + sdk: "xrsimulator", + alias: Some("arm64e-xros-sim"), min_xcode_version: None, }, ); From b57b20bf5ddee4385fa8637c8489ed63584432a1 Mon Sep 17 00:00:00 2001 From: Eugene Hauptmann Date: Thu, 30 May 2024 20:20:52 -0400 Subject: [PATCH 3/9] added visionos to apple config --- src/apple/config/mod.rs | 8 ++++++++ src/apple/config/raw.rs | 3 +++ 2 files changed, 11 insertions(+) diff --git a/src/apple/config/mod.rs b/src/apple/config/mod.rs index 8187d231..61ce1957 100644 --- a/src/apple/config/mod.rs +++ b/src/apple/config/mod.rs @@ -21,6 +21,7 @@ use thiserror::Error; static DEFAULT_PROJECT_DIR: &str = "gen/apple"; const DEFAULT_BUNDLE_VERSION: VersionNumber = VersionNumber::new(VersionTriple::new(1, 0, 0), None); const DEFAULT_IOS_VERSION: VersionDouble = VersionDouble::new(13, 0); +const DEFAULT_VISIONOS_VERSION: VersionDouble = VersionDouble::new(1, 0); const DEFAULT_MACOS_VERSION: VersionDouble = VersionDouble::new(11, 0); #[derive(Debug, Default, Serialize, Deserialize)] @@ -286,6 +287,7 @@ pub struct Config { bundle_version: VersionNumber, bundle_version_short: VersionTriple, ios_version: VersionDouble, + visionos_version: VersionDouble, macos_version: VersionDouble, use_legacy_build_system: bool, plist_pairs: Vec, @@ -353,6 +355,12 @@ impl Config { .transpose() .map_err(Error::IosVersionInvalid)? .unwrap_or(DEFAULT_IOS_VERSION), + visionos_version: raw + .visionos_version + .map(|str| VersionDouble::from_str(&str)) + .transpose() + .map_err(Error::IosVersionInvalid)? + .unwrap_or(DEFAULT_VISIONOS_VERSION), macos_version: raw .macos_version .map(|str| VersionDouble::from_str(&str)) diff --git a/src/apple/config/raw.rs b/src/apple/config/raw.rs index 4014d00f..562f5c71 100644 --- a/src/apple/config/raw.rs +++ b/src/apple/config/raw.rs @@ -123,6 +123,7 @@ pub struct Raw { pub bundle_version: Option, pub bundle_version_short: Option, pub ios_version: Option, + pub visionos_version: Option, pub macos_version: Option, pub use_legacy_build_system: Option, pub plist_pairs: Option>, @@ -145,6 +146,7 @@ impl Raw { bundle_version: None, bundle_version_short: None, ios_version: None, + visionos_version: None, macos_version: None, use_legacy_build_system: None, plist_pairs: None, @@ -227,6 +229,7 @@ impl Raw { bundle_version: None, bundle_version_short: None, ios_version: None, + visionos_version: None, macos_version: None, use_legacy_build_system: None, plist_pairs: None, From c34487741ec58fdcaaddbf297f9cbaf92dde64ab Mon Sep 17 00:00:00 2001 From: Eugene Hauptmann Date: Fri, 31 May 2024 15:01:25 -0400 Subject: [PATCH 4/9] feature(apple): added for_triple to the Target --- src/apple/target.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/apple/target.rs b/src/apple/target.rs index 8ce968c0..3ae94d43 100644 --- a/src/apple/target.rs +++ b/src/apple/target.rs @@ -242,6 +242,12 @@ impl<'a> Target<'a> { .values() .find(|target| target.arch == arch || target.alias == Some(arch)) } + + pub fn for_triple(triple: &str) -> Option<&'a Self> { + Self::all() + .values() + .find(|target| target.triple == triple || target.alias == Some(triple)) + } fn min_xcode_version_satisfied(&self) -> Result<(), VersionCheckError> { self.min_xcode_version From 1f4187465eb4abb8118ee8864a0eddec8c4c64ee Mon Sep 17 00:00:00 2001 From: Eugene Hauptmann Date: Fri, 31 May 2024 18:09:14 -0400 Subject: [PATCH 5/9] added visionos --- src/apple/config/mod.rs | 7 +++++++ src/apple/target.rs | 37 +++++++++++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/apple/config/mod.rs b/src/apple/config/mod.rs index 61ce1957..50926629 100644 --- a/src/apple/config/mod.rs +++ b/src/apple/config/mod.rs @@ -152,6 +152,8 @@ pub struct Metadata { #[serde(default)] pub ios: Platform, #[serde(default)] + pub visionos: Platform, + #[serde(default)] pub macos: Platform, } @@ -160,6 +162,7 @@ impl Default for Metadata { Self { supported: true, ios: Default::default(), + visionos: Default::default(), macos: Default::default(), } } @@ -173,6 +176,10 @@ impl Metadata { pub fn ios(&self) -> &Platform { &self.ios } + + pub fn visionos(&self) -> &Platform { + &self.visionos + } pub fn macos(&self) -> &Platform { &self.macos diff --git a/src/apple/target.rs b/src/apple/target.rs index 3ae94d43..ba4889a7 100644 --- a/src/apple/target.rs +++ b/src/apple/target.rs @@ -221,6 +221,13 @@ impl<'a> TargetTrait<'a> for Target<'a> { } } +enum TargetPlatform { + MacOS, + #[allow(non_camel_case_types)] + iOS, + VisionOS +} + impl<'a> Target<'a> { // TODO: Make this cleaner pub fn macos() -> Self { @@ -233,9 +240,31 @@ impl<'a> Target<'a> { } } + pub fn get_platform(&self) -> TargetPlatform{ + let platform = if self.is_macos() { + TargetPlatform::MacOS + } else if self.is_ios() { + TargetPlatform::iOS + } else if self.is_visionos() { + TargetPlatform::VisionOS + } else { + TargetPlatform::MacOS + }; + + platform + } + pub fn is_macos(&self) -> bool { *self == Self::macos() } + + pub fn is_ios(&self) -> bool { + self.triple.contains("apple-ios") + } + + pub fn is_visionos(&self) -> bool { + self.triple.contains("apple-visionos") + } pub fn for_arch(arch: &str) -> Option<&'a Self> { Self::all() @@ -273,10 +302,10 @@ impl<'a> Target<'a> { metadata: &'a Metadata, subcommand: &'a str, ) -> Result, VersionCheckError> { - let metadata = if self.is_macos() { - metadata.macos() - } else { - metadata.ios() + let metadata = match self.get_platform() { + TargetPlatform::MacOS => metadata.macos(), + TargetPlatform::iOS => metadata.ios(), + TargetPlatform::VisionOS => metadata.visionos() }; self.min_xcode_version_satisfied().map(|()| { CargoCommand::new(subcommand) From c14ceaf06fcd66387cd25377e003062c0e7fadd6 Mon Sep 17 00:00:00 2001 From: Eugene Hauptmann Date: Fri, 31 May 2024 18:15:07 -0400 Subject: [PATCH 6/9] fixed visibility of the enum --- src/apple/target.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apple/target.rs b/src/apple/target.rs index ba4889a7..0ebbbce6 100644 --- a/src/apple/target.rs +++ b/src/apple/target.rs @@ -221,7 +221,7 @@ impl<'a> TargetTrait<'a> for Target<'a> { } } -enum TargetPlatform { +pub enum TargetPlatform { MacOS, #[allow(non_camel_case_types)] iOS, From 58ac2c6122053cf25edd1a768730851bd750b41c Mon Sep 17 00:00:00 2001 From: Eugene Hauptmann Date: Sat, 1 Jun 2024 16:58:03 -0400 Subject: [PATCH 7/9] added visionos support --- src/apple/device/mod.rs | 3 ++- src/apple/device/simctl/mod.rs | 20 +++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/apple/device/mod.rs b/src/apple/device/mod.rs index 80cdbd80..e761268d 100644 --- a/src/apple/device/mod.rs +++ b/src/apple/device/mod.rs @@ -58,6 +58,7 @@ impl Reportable for RunError { pub enum DeviceKind { Simulator, IosDeployDevice, + VisionOsDeployDevice, DeviceCtlDevice, } @@ -133,7 +134,7 @@ impl<'a> Device<'a> { match self.kind { DeviceKind::Simulator => simctl::run(config, env, non_interactive, &self.id) .map_err(|e| RunError::DeployFailed(e.to_string())), - DeviceKind::IosDeployDevice | DeviceKind::DeviceCtlDevice => { + DeviceKind::IosDeployDevice | DeviceKind::VisionOsDeployDevice | DeviceKind::DeviceCtlDevice => { println!("Exporting app..."); self.target .export(config, env, noise_level) diff --git a/src/apple/device/simctl/mod.rs b/src/apple/device/simctl/mod.rs index ee62f431..9489254c 100644 --- a/src/apple/device/simctl/mod.rs +++ b/src/apple/device/simctl/mod.rs @@ -27,15 +27,25 @@ impl Display for Device { impl<'a> From for AppleDevice<'a> { fn from(device: Device) -> AppleDevice<'a> { + let name = device.name.clone(); + let is_visionos = name.contains("Apple Vision Pro"); + let target = Target::for_triple(if cfg!(target_arch = "aarch64") { + match is_visionos { + true => "aarch64-apple-visionos", + _ => "aarch64-apple-ios" + // TODO: figure out how to check for sim here, or probably do this elsewhere, and just add -sim to the triple + // true => "aarch64-apple-visionos-sim", + // _ => "aarch64-apple-ios-sim + } + } else { + "x86_64-apple-ios" + }); + AppleDevice::new( device.udid, device.name, "".into(), - Target::for_arch(if cfg!(target_arch = "aarch64") { - "arm64-sim" - } else { - "x86_64" - }) + target .unwrap(), DeviceKind::Simulator, ) From 52ef761fe4df4ac31c0216f1deb8145a101b87e8 Mon Sep 17 00:00:00 2001 From: Eugene Hauptmann Date: Tue, 4 Jun 2024 09:46:12 -0400 Subject: [PATCH 8/9] added changes file --- .changes/visionos.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changes/visionos.md diff --git a/.changes/visionos.md b/.changes/visionos.md new file mode 100644 index 00000000..d400b06e --- /dev/null +++ b/.changes/visionos.md @@ -0,0 +1,5 @@ +--- +"cargo-mobile2": minor +--- + +Added visionOS support for Apple Vision Pro based on https://github.com/rust-lang/rust/pull/121419 \ No newline at end of file From dd2be042ca3b1419aec702997e6b433a524a303b Mon Sep 17 00:00:00 2001 From: Eugene Hauptmann Date: Tue, 4 Jun 2024 10:41:03 -0400 Subject: [PATCH 9/9] fixed formatting --- src/apple/config/mod.rs | 2 +- src/apple/device/mod.rs | 4 +++- src/apple/device/simctl/mod.rs | 10 ++++------ src/apple/target.rs | 12 ++++++------ 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/apple/config/mod.rs b/src/apple/config/mod.rs index 50926629..565a133a 100644 --- a/src/apple/config/mod.rs +++ b/src/apple/config/mod.rs @@ -176,7 +176,7 @@ impl Metadata { pub fn ios(&self) -> &Platform { &self.ios } - + pub fn visionos(&self) -> &Platform { &self.visionos } diff --git a/src/apple/device/mod.rs b/src/apple/device/mod.rs index e761268d..6e5a18f6 100644 --- a/src/apple/device/mod.rs +++ b/src/apple/device/mod.rs @@ -134,7 +134,9 @@ impl<'a> Device<'a> { match self.kind { DeviceKind::Simulator => simctl::run(config, env, non_interactive, &self.id) .map_err(|e| RunError::DeployFailed(e.to_string())), - DeviceKind::IosDeployDevice | DeviceKind::VisionOsDeployDevice | DeviceKind::DeviceCtlDevice => { + DeviceKind::IosDeployDevice + | DeviceKind::VisionOsDeployDevice + | DeviceKind::DeviceCtlDevice => { println!("Exporting app..."); self.target .export(config, env, noise_level) diff --git a/src/apple/device/simctl/mod.rs b/src/apple/device/simctl/mod.rs index 9489254c..eeac51c8 100644 --- a/src/apple/device/simctl/mod.rs +++ b/src/apple/device/simctl/mod.rs @@ -32,10 +32,9 @@ impl<'a> From for AppleDevice<'a> { let target = Target::for_triple(if cfg!(target_arch = "aarch64") { match is_visionos { true => "aarch64-apple-visionos", - _ => "aarch64-apple-ios" - // TODO: figure out how to check for sim here, or probably do this elsewhere, and just add -sim to the triple - // true => "aarch64-apple-visionos-sim", - // _ => "aarch64-apple-ios-sim + _ => "aarch64-apple-ios", // TODO: figure out how to check for sim here, or probably do this elsewhere, and just add -sim to the triple + // true => "aarch64-apple-visionos-sim", + // _ => "aarch64-apple-ios-sim } } else { "x86_64-apple-ios" @@ -45,8 +44,7 @@ impl<'a> From for AppleDevice<'a> { device.udid, device.name, "".into(), - target - .unwrap(), + target.unwrap(), DeviceKind::Simulator, ) } diff --git a/src/apple/target.rs b/src/apple/target.rs index 0ebbbce6..4980f40f 100644 --- a/src/apple/target.rs +++ b/src/apple/target.rs @@ -225,7 +225,7 @@ pub enum TargetPlatform { MacOS, #[allow(non_camel_case_types)] iOS, - VisionOS + VisionOS, } impl<'a> Target<'a> { @@ -240,7 +240,7 @@ impl<'a> Target<'a> { } } - pub fn get_platform(&self) -> TargetPlatform{ + pub fn get_platform(&self) -> TargetPlatform { let platform = if self.is_macos() { TargetPlatform::MacOS } else if self.is_ios() { @@ -257,11 +257,11 @@ impl<'a> Target<'a> { pub fn is_macos(&self) -> bool { *self == Self::macos() } - + pub fn is_ios(&self) -> bool { self.triple.contains("apple-ios") } - + pub fn is_visionos(&self) -> bool { self.triple.contains("apple-visionos") } @@ -271,7 +271,7 @@ impl<'a> Target<'a> { .values() .find(|target| target.arch == arch || target.alias == Some(arch)) } - + pub fn for_triple(triple: &str) -> Option<&'a Self> { Self::all() .values() @@ -305,7 +305,7 @@ impl<'a> Target<'a> { let metadata = match self.get_platform() { TargetPlatform::MacOS => metadata.macos(), TargetPlatform::iOS => metadata.ios(), - TargetPlatform::VisionOS => metadata.visionos() + TargetPlatform::VisionOS => metadata.visionos(), }; self.min_xcode_version_satisfied().map(|()| { CargoCommand::new(subcommand)