Skip to content

Commit 09e9dc1

Browse files
authored
feat(cli): allow xcodebuild to manage iOS signing and provisioning (#10752)
1 parent 5c369e6 commit 09e9dc1

File tree

5 files changed

+48
-8
lines changed

5 files changed

+48
-8
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'tauri-cli': 'patch:feat'
3+
'@tauri-apps/cli': 'patch:feat'
4+
---
5+
6+
Allow Xcode to manage iOS code sign and provisioning profiles by default.
7+
On CI, the `APPLE_API_KEY`, `APPLE_API_ISSUER` and `APPLE_API_KEY_PATH` environment variables must be provided for authentication.

tooling/cli/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tooling/cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ name = "cargo-tauri"
3939
path = "src/main.rs"
4040

4141
[dependencies]
42-
cargo-mobile2 = { version = "0.13.5", default-features = false }
42+
cargo-mobile2 = { version = "0.14", default-features = false }
4343
jsonrpsee = { version = "0.24", features = [ "server" ] }
4444
jsonrpsee-core = "0.24"
4545
jsonrpsee-client-transport = { version = "0.24", features = [ "ws" ] }

tooling/cli/ENVIRONMENT_VARIABLES.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ These environment variables are inputs to the CLI which may have an equivalent C
2626
- `APPLE_ID` — The Apple ID used to notarize the application. If this environment variable is provided, `APPLE_PASSWORD` and `APPLE_TEAM_ID` must also be set. Alternatively, `APPLE_API_KEY` and `APPLE_API_ISSUER` can be used to authenticate.
2727
- `APPLE_PASSWORD` — The Apple password used to authenticate for application notarization. Required if `APPLE_ID` is specified. An app-specific password can be used. Alternatively to entering the password in plaintext, it may also be specified using a '@keychain:' or '@env:' prefix followed by a keychain password item name or environment variable name.
2828
- `APPLE_TEAM_ID`: Developer team ID. To find your Team ID, go to the [Account](https://developer.apple.com/account) page on the Apple Developer website, and check your membership details.
29-
- `APPLE_API_KEY` — Alternative to `APPLE_ID` and `APPLE_PASSWORD` for notarization authentication using JWT.
29+
- `APPLE_API_KEY` — Alternative to `APPLE_ID` and `APPLE_PASSWORD` for notarization authentication using JWT. Also an option to allow automated iOS certificate and provisioning profile management.
3030
- See [creating API keys](https://developer.apple.com/documentation/appstoreconnectapi/creating_api_keys_for_app_store_connect_api) for more information.
3131
- `API_PRIVATE_KEYS_DIR` — Specify the directory where your AuthKey file is located. See `APPLE_API_KEY`.
3232
- `APPLE_API_ISSUER` — Issuer ID. Required if `APPLE_API_KEY` is specified.
33-
- `APPLE_API_KEY_PATH` - path to the API key `.p8` file. If not specified, the bundler searches the following directories in sequence for a private key file with the name of 'AuthKey\_<api_key>.p8': './private_keys', '~/private_keys', '~/.private_keys', and '~/.appstoreconnect/private_keys'.
33+
- `APPLE_API_KEY_PATH` - path to the API key `.p8` file. If not specified, for macOS apps the bundler searches the following directories in sequence for a private key file with the name of 'AuthKey\_<api_key>.p8': './private_keys', '~/private_keys', '~/.private_keys', and '~/.appstoreconnect/private_keys'. **For iOS this variable is required**.
3434
- `APPLE_SIGNING_IDENTITY` — The identity used to code sign. Overwrites `tauri.conf.json > bundle > macOS > signingIdentity`. If neither are set, it is inferred from `APPLE_CERTIFICATE` when provided.
3535
- `APPLE_PROVIDER_SHORT_NAME` — If your Apple ID is connected to multiple teams, you have to specify the provider short name of the team you want to use to notarize your app. Overwrites `tauri.conf.json > bundle > macOS > providerShortName`.
3636
- `APPLE_DEVELOPMENT_TEAM` — The team ID used to code sign on iOS. Overwrites `tauri.conf.json > bundle > iOS > developmentTeam`. Can be found in https://developer.apple.com/account#MembershipDetailsCard.

tooling/cli/src/mobile/ios/build.rs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,20 @@ use clap::{ArgAction, Parser, ValueEnum};
2222

2323
use anyhow::Context;
2424
use cargo_mobile2::{
25-
apple::{config::Config as AppleConfig, target::Target},
25+
apple::{
26+
config::Config as AppleConfig,
27+
target::{ExportConfig, Target},
28+
},
2629
env::Env,
2730
opts::{NoiseLevel, Profile},
2831
target::{call_for_targets_with_fallback, TargetInvalid, TargetTrait},
2932
};
3033

31-
use std::{env::set_current_dir, fs};
34+
use std::{
35+
env::{set_current_dir, var, var_os},
36+
fs,
37+
path::PathBuf,
38+
};
3239

3340
#[derive(Debug, Clone, Parser)]
3441
#[clap(
@@ -294,7 +301,13 @@ fn run_build(
294301

295302
target.build(config, env, NoiseLevel::FranklyQuitePedantic, profile)?;
296303
target.archive(config, env, noise_level, profile, Some(app_version))?;
297-
target.export(config, env, noise_level)?;
304+
305+
let mut export_config = ExportConfig::new().allow_provisioning_updates();
306+
if let Some(credentials) = auth_credentials_from_env()? {
307+
export_config = export_config.authentication_credentials(credentials);
308+
}
309+
310+
target.export(config, env, noise_level, export_config)?;
298311

299312
if let Ok(ipa_path) = config.ipa_path() {
300313
let out_dir = config.export_dir().join(target.arch);
@@ -313,3 +326,23 @@ fn run_build(
313326

314327
Ok(handle)
315328
}
329+
330+
fn auth_credentials_from_env() -> Result<Option<cargo_mobile2::apple::target::AuthCredentials>> {
331+
match (
332+
var("APPLE_API_KEY"),
333+
var("APPLE_API_ISSUER"),
334+
var_os("APPLE_API_KEY_PATH").map(PathBuf::from),
335+
) {
336+
(Ok(key_id), Ok(key_issuer_id), Some(key_path)) => {
337+
Ok(Some(cargo_mobile2::apple::target::AuthCredentials {
338+
key_path,
339+
key_id,
340+
key_issuer_id,
341+
}))
342+
}
343+
(Err(_), Err(_), None) => Ok(None),
344+
_ => anyhow::bail!(
345+
"APPLE_API_KEY, APPLE_API_ISSUER and APPLE_API_KEY_PATH must be provided for code signing"
346+
),
347+
}
348+
}

0 commit comments

Comments
 (0)