Skip to content

Commit

Permalink
fix(apple): add devicectl interface (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Oct 7, 2023
1 parent 241329a commit 739c965
Show file tree
Hide file tree
Showing 20 changed files with 541 additions and 179 deletions.
5 changes: 5 additions & 0 deletions .changes/macos-14-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cargo-mobile2": minor
---

Use `devicectl` on macOS 14+ to connect to iOS 17+ devices.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ core-foundation = "0.9"
openssl = "0.10"
objc = "0.2"
objc_id = "0.1"
os_info = "3"

[target."cfg(not(target_os = \"macos\"))".dependencies]
ureq = { version = "2.8", default-features = false, features = [ "gzip" ] }
Expand Down
30 changes: 16 additions & 14 deletions src/apple/cli.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{
apple::{
config::{Config, Metadata},
device::{Device, RunError},
ios_deploy, rust_version_check,
device::{self, Device, RunError},
rust_version_check,
target::{ArchiveError, BuildError, CheckError, CompileLibError, ExportError, Target},
NAME,
},
Expand Down Expand Up @@ -152,7 +152,7 @@ pub enum Command {
pub enum Error {
EnvInitFailed(EnvError),
RustVersionCheckFailed(util::RustVersionError),
DevicePromptFailed(PromptError<ios_deploy::DeviceListError>),
DevicePromptFailed(PromptError<String>),
TargetInvalid(TargetInvalid),
ConfigFailed(LoadOrGenError),
MetadataFailed(metadata::Error),
Expand All @@ -164,7 +164,7 @@ pub enum Error {
ArchiveFailed(ArchiveError),
ExportFailed(ExportError),
RunFailed(RunError),
ListFailed(ios_deploy::DeviceListError),
ListFailed(String),
NoHomeDir(util::NoHomeDir),
CargoEnvFailed(std::io::Error),
SdkRootInvalid { sdk_root: PathBuf },
Expand Down Expand Up @@ -197,7 +197,7 @@ impl Reportable for Error {
Self::ArchiveFailed(err) => err.report(),
Self::ExportFailed(err) => err.report(),
Self::RunFailed(err) => err.report(),
Self::ListFailed(err) => err.report(),
Self::ListFailed(err) => Report::error("Failed to list devices", err),
Self::NoHomeDir(err) => Report::error("Failed to load cargo env profile", err),
Self::CargoEnvFailed(err) => Report::error("Failed to load cargo env profile", err),
Self::SdkRootInvalid { sdk_root } => Report::error(
Expand Down Expand Up @@ -232,7 +232,7 @@ impl Exec for Input {
}

fn exec(self, wrapper: &TextWrapper) -> Result<(), Self::Report> {
define_device_prompt!(ios_deploy::device_list, ios_deploy::DeviceListError, iOS);
define_device_prompt!(crate::apple::device::list_devices, String, iOS);
fn detect_target_ok<'a>(env: &Env) -> Option<&'a Target<'a>> {
device_prompt(env).map(|device| device.target()).ok()
}
Expand Down Expand Up @@ -356,17 +356,19 @@ impl Exec for Input {
.map_err(Error::DevicePromptFailed)?
.run(config, &env, noise_level, non_interactive, profile)
.and_then(|h| {
h.wait().map(|_| ()).map_err(|e| {
RunError::DeployFailed(ios_deploy::RunAndDebugError::DeployFailed(e))
})
h.wait()
.map(|_| ())
.map_err(|e| RunError::DeployFailed(e.to_string()))
})
.map_err(Error::RunFailed)
}),
Command::List => ios_deploy::device_list(&env)
.map_err(Error::ListFailed)
.map(|device_list| {
prompt::list_display_only(device_list.iter(), device_list.len());
}),
Command::List => {
device::list_devices(&env)
.map_err(Error::ListFailed)
.map(|device_list| {
prompt::list_display_only(device_list.iter(), device_list.len());
})
}
Command::Pod { mut arguments } => with_config(non_interactive, wrapper, |config, _| {
arguments.push(format!(
"--project-directory={}",
Expand Down
9 changes: 7 additions & 2 deletions src/apple/deps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ mod update;
pub(crate) mod xcode_plugin;

use self::update::{Outdated, OutdatedError};
use super::system_profile::{self, DeveloperTools};
use super::{
device_ctl_available,
system_profile::{self, DeveloperTools},
};
use crate::util::{
self,
cli::{Report, TextWrapper},
Expand All @@ -14,7 +17,6 @@ use thiserror::Error;

static PACKAGES: &[PackageSpec] = &[
PackageSpec::brew("xcodegen"),
PackageSpec::brew("ios-deploy"),
PackageSpec::brew("libimobiledevice").with_bin_name("idevicesyslog"),
PackageSpec::brew_or_gem("cocoapods").with_bin_name("pod"),
];
Expand Down Expand Up @@ -188,6 +190,9 @@ pub fn install_all(
for package in PACKAGES {
package.install(reinstall_deps, &mut gem_cache)?;
}
if !device_ctl_available() {
PackageSpec::brew("ios-deploy").install(reinstall_deps, &mut gem_cache)?;
}
gem_cache.initialize()?;
let outdated = Outdated::load(&mut gem_cache)?;
outdated.print_notice();
Expand Down
144 changes: 0 additions & 144 deletions src/apple/device.rs

This file was deleted.

Loading

0 comments on commit 739c965

Please sign in to comment.