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

Use devicectl for launching on iOS 17 or greater. #214

Closed
Closed
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
50 changes: 42 additions & 8 deletions dinghy-lib/src/apple/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use std::process;
pub struct IosDevice {
pub id: String,
pub name: String,
pub version: String,
arch_cpu: &'static str,
rustc_triple: String,
}
Expand All @@ -47,16 +48,24 @@ impl IosDevice {
.as_str()
.context("DeviceName expected to be a string")?
.to_owned();
let version = device["ProductVersion"]
.as_str()
.context("ProductVersion expected to be a string")?
.to_owned();
let arch_cpu = device["modelArch"]
.as_str()
.context("DeviceName expected to be a string")?;
// Somewhere between the iPhone 8 and the iPhone 15, ios-deploy stopped including
// `modelArch` in the payload. Perhaps this is because all iOS devices are arm64?
.unwrap_or("arm64");
let cpu = match &*arch_cpu {
"arm64" | "arm64e" => "aarch64",
_ => "armv7",
};

Ok(IosDevice {
name: name,
id: id,
version: version.into(),
arch_cpu: cpu.into(),
rustc_triple: format!("{}-apple-ios", cpu),
})
Expand Down Expand Up @@ -115,11 +124,36 @@ impl IosDevice {
envs: &[&str],
debugger: bool,
) -> Result<()> {
let mut command = process::Command::new("ios-deploy");
command.args(&["-i", &self.id, "-b", &app_path, "-m"]);
command.args(&["-a", &args.join(" ")]);
command.args(&["-s", &envs.join(" ")]);
command.arg(if debugger { "-d" } else { "-I" });
let mut command = if self.version.starts_with("17") {
let signing = xcode::look_for_signature_settings(&self.id)?
.pop()
.ok_or_else(|| anyhow!("no signing identity found"))?;
let app_id = signing
.name
.split(" ")
.last()
.ok_or_else(|| anyhow!("no app id ?"))?;
Comment on lines +128 to +135
Copy link
Contributor Author

Choose a reason for hiding this comment

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

From what I can tell, devicectl requires using the app bundle id. It fails when just Dinghy is used.

Ideally, this would just use the already called xcode::look_for_signature_settings that was used in make_app. I every way I looked, this required modifying BuildBundle or the Device trait both seemed worse than this option.


let mut command = process::Command::new("xcrun");
command.args(&[
"devicectl",
"device",
"process",
"launch",
"--device",
&self.id,
app_id,
]);
command
} else {
let mut command = process::Command::new("ios-deploy");
command.args(&["-i", &self.id, "-b", &app_path, "-m"]);
command.args(&["-a", &args.join(" ")]);
command.args(&["-s", &envs.join(" ")]);
command.arg(if debugger { "-d" } else { "-I" });
command
};
debug!("Running {command:?}");
command.stderr(process::Stdio::inherit());
command.stdout(process::Stdio::inherit());
let status = command
Expand Down Expand Up @@ -305,8 +339,8 @@ impl Display for IosDevice {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
Ok(fmt.write_str(
format!(
"IosDevice {{ \"id\": \"{}\", \"name\": {}, \"arch_cpu\": {} }}",
self.id, self.name, self.arch_cpu
"IosDevice {{ \"id\": \"{}\", \"name\": {}, \"arch_cpu\": {}, version: \"{}\"}}",
self.id, self.name, self.arch_cpu, self.version,
)
.as_str(),
)?)
Expand Down
4 changes: 4 additions & 0 deletions dinghy-lib/src/apple/xcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ pub fn add_plist_to_app(
plist,
"<key>CFBundleExecutable</key><string>Dinghy</string>",
)?;
writeln!(
plist,
"<key>CFBundleName</key><string>Dinghy</string>",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure why but devicectl wouldn't work without this key.

)?;
writeln!(
plist,
"<key>CFBundleIdentifier</key><string>{}</string>",
Expand Down