Skip to content

Commit

Permalink
feat(apple): add config to allow provisoning updates (#371)
Browse files Browse the repository at this point in the history
changes the Target::export method to be configurable, adding options to allow provisioning updates - which means code signing certificates and provisioning profiles are managed by xcodebuild (with API key config for CI authentication)
  • Loading branch information
lucasfernog authored Aug 23, 2024
1 parent e7f4e84 commit d0e9e58
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/apple-export-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cargo-mobile2": minor
---

Added a `ExportConfig` argument to the `Target::export` iOS method to allow provisioning updates.
3 changes: 2 additions & 1 deletion src/apple/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use super::{
target::{ArchiveError, BuildError, ExportError, Target},
};
use crate::{
apple::target::ExportConfig,
env::{Env, ExplicitEnv as _},
opts,
util::cli::{Report, Reportable},
Expand Down Expand Up @@ -140,7 +141,7 @@ impl<'a> Device<'a> {
DeviceKind::IosDeployDevice | DeviceKind::DeviceCtlDevice => {
println!("Exporting app...");
self.target
.export(config, env, noise_level)
.export(config, env, noise_level, ExportConfig::default())
.map_err(RunError::ExportFailed)?;
println!("Extracting IPA...");

Expand Down
41 changes: 41 additions & 0 deletions src/apple/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use once_cell_regex::exports::once_cell::sync::OnceCell;
use std::{
collections::{BTreeMap, HashMap},
ffi::{OsStr, OsString},
path::PathBuf,
};
use thiserror::Error;

Expand Down Expand Up @@ -133,6 +134,34 @@ impl Reportable for ExportError {
}
}

#[derive(Default)]
pub struct ExportConfig {
allow_provisioning_updates: bool,
authentication_credentials: Option<AuthCredentials>,
}

impl ExportConfig {
pub fn new() -> Self {
Self::default()
}

pub fn allow_provisioning_updates(mut self) -> Self {
self.allow_provisioning_updates = true;
self
}

pub fn authentication_credentials(mut self, credentials: AuthCredentials) -> Self {
self.authentication_credentials.replace(credentials);
self
}
}

pub struct AuthCredentials {
pub key_path: PathBuf,
pub key_id: String,
pub key_issuer_id: String,
}

#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct Target<'a> {
pub triple: &'a str,
Expand Down Expand Up @@ -415,6 +444,7 @@ impl<'a> Target<'a> {
config: &Config,
env: &Env,
noise_level: opts::NoiseLevel,
export_config: ExportConfig,
) -> Result<(), ExportError> {
// Super fun discrepancy in expectation of `-archivePath` value
let archive_path = config
Expand All @@ -437,6 +467,17 @@ impl<'a> Target<'a> {
.arg(&export_plist_path)
.arg("-exportPath")
.arg(&export_dir);

if export_config.allow_provisioning_updates {
cmd.arg("-allowProvisioningUpdates");
}
if let Some(credentials) = &export_config.authentication_credentials {
cmd.args(["-authenticationKeyID", &credentials.key_id])
.arg("-authenticationKeyPath")
.arg(&credentials.key_path)
.args(["-authenticationKeyIssuerID", &credentials.key_issuer_id]);
}

Ok(())
})
.dup_stdio()
Expand Down

0 comments on commit d0e9e58

Please sign in to comment.