Skip to content

Commit a9ec128

Browse files
feat: add option to not wait on notarization to finish (#13521)
* feat: add option to not wait on notarization to finish * cli arg istead of config * changefile * fix serde --------- Co-authored-by: Lucas Nogueira <[email protected]>
1 parent f0dcf96 commit a9ec128

File tree

11 files changed

+109
-11
lines changed

11 files changed

+109
-11
lines changed

.changes/feat-skip-stapling.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
tauri-macos-sign: 'minor:feat'
3+
tauri-bundler: 'minor:feat'
4+
tauri-cli: 'minor:feat'
5+
---
6+
7+
Added a `--skip-stapling` option to make `tauri build|bundle` _not_ wait for notarization to finish on macOS.

crates/tauri-bundler/src/bundle/macos/app.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
use super::{
2626
icon::create_icns_file,
27-
sign::{notarize, notarize_auth, sign, NotarizeAuthError, SignTarget},
27+
sign::{notarize, notarize_auth, notarize_without_stapling, sign, NotarizeAuthError, SignTarget},
2828
};
2929
use crate::{
3030
utils::{fs_utils, CommandExt},
@@ -121,7 +121,11 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
121121
// notarization is required for distribution
122122
match notarize_auth() {
123123
Ok(auth) => {
124-
notarize(&keychain, app_bundle_path.clone(), &auth)?;
124+
if settings.macos().skip_stapling {
125+
notarize_without_stapling(&keychain, app_bundle_path.clone(), &auth)?;
126+
} else {
127+
notarize(&keychain, app_bundle_path.clone(), &auth)?;
128+
}
125129
}
126130
Err(e) => {
127131
if matches!(e, NotarizeAuthError::MissingTeamId) {

crates/tauri-bundler/src/bundle/macos/sign.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ pub fn notarize(
7171
tauri_macos_sign::notarize(keychain, &app_bundle_path, credentials).map_err(Into::into)
7272
}
7373

74+
pub fn notarize_without_stapling(
75+
keychain: &tauri_macos_sign::Keychain,
76+
app_bundle_path: PathBuf,
77+
credentials: &tauri_macos_sign::AppleNotarizationCredentials,
78+
) -> crate::Result<()> {
79+
tauri_macos_sign::notarize_without_stapling(keychain, &app_bundle_path, credentials)
80+
.map_err(Into::into)
81+
}
82+
7483
#[derive(Debug, thiserror::Error)]
7584
pub enum NotarizeAuthError {
7685
#[error(

crates/tauri-bundler/src/bundle/settings.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,15 @@ pub struct MacOsSettings {
346346
pub exception_domain: Option<String>,
347347
/// Code signing identity.
348348
pub signing_identity: Option<String>,
349+
/// Whether to wait for notarization to finish and `staple` the ticket onto the app.
350+
///
351+
/// Gatekeeper will look for stapled tickets to tell whether your app was notarized without
352+
/// reaching out to Apple's servers which is helpful in offline environments.
353+
///
354+
/// Enabling this option will also result in `tauri build` not waiting for notarization to finish
355+
/// which is helpful for the very first time your app is notarized as this can take multiple hours.
356+
/// On subsequent runs, it's recommended to disable this setting again.
357+
pub skip_stapling: bool,
349358
/// Preserve the hardened runtime version flag, see <https://developer.apple.com/documentation/security/hardened_runtime>
350359
///
351360
/// Settings this to `false` is useful when using an ad-hoc signature, making it less strict.

crates/tauri-cli/src/build.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ pub struct Options {
6060
/// Skip prompting for values
6161
#[clap(long, env = "CI")]
6262
pub ci: bool,
63+
/// Whether to wait for notarization to finish and `staple` the ticket onto the app.
64+
///
65+
/// Gatekeeper will look for stapled tickets to tell whether your app was notarized without
66+
/// reaching out to Apple's servers which is helpful in offline environments.
67+
///
68+
/// Enabling this option will also result in `tauri build` not waiting for notarization to finish
69+
/// which is helpful for the very first time your app is notarized as this can take multiple hours.
70+
/// On subsequent runs, it's recommended to disable this setting again.
71+
#[clap(long)]
72+
pub skip_stapling: bool,
6373
}
6474

6575
pub fn command(mut options: Options, verbosity: u8) -> Result<()> {

crates/tauri-cli/src/bundle.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ pub struct Options {
8282
/// Skip prompting for values
8383
#[clap(long, env = "CI")]
8484
pub ci: bool,
85+
/// Whether to wait for notarization to finish and `staple` the ticket onto the app.
86+
///
87+
/// Gatekeeper will look for stapled tickets to tell whether your app was notarized without
88+
/// reaching out to Apple's servers which is helpful in offline environments.
89+
///
90+
/// Enabling this option will also result in `tauri build` not waiting for notarization to finish
91+
/// which is helpful for the very first time your app is notarized as this can take multiple hours.
92+
/// On subsequent runs, it's recommended to disable this setting again.
93+
#[clap(long)]
94+
pub skip_stapling: bool,
8595
}
8696

8797
impl From<crate::build::Options> for Options {
@@ -93,6 +103,7 @@ impl From<crate::build::Options> for Options {
93103
debug: value.debug,
94104
ci: value.ci,
95105
config: value.config,
106+
skip_stapling: value.skip_stapling,
96107
}
97108
}
98109
}

crates/tauri-cli/src/interface/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub trait AppSettings {
3131
fn get_package_settings(&self) -> tauri_bundler::PackageSettings;
3232
fn get_bundle_settings(
3333
&self,
34+
options: &Options,
3435
config: &Config,
3536
features: &[String],
3637
) -> crate::Result<tauri_bundler::BundleSettings>;
@@ -52,7 +53,7 @@ pub trait AppSettings {
5253
enabled_features.push("default".into());
5354
}
5455

55-
let target: String = if let Some(target) = options.target {
56+
let target: String = if let Some(target) = options.target.clone() {
5657
target
5758
} else {
5859
tauri_utils::platform::target_triple()?
@@ -66,7 +67,7 @@ pub trait AppSettings {
6667

6768
let mut settings_builder = SettingsBuilder::new()
6869
.package_settings(self.get_package_settings())
69-
.bundle_settings(self.get_bundle_settings(config, &enabled_features)?)
70+
.bundle_settings(self.get_bundle_settings(&options, config, &enabled_features)?)
7071
.binaries(bins)
7172
.project_out_directory(out_dir)
7273
.target(target)

crates/tauri-cli/src/interface/rust.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub struct Options {
5555
pub args: Vec<String>,
5656
pub config: Vec<ConfigValue>,
5757
pub no_watch: bool,
58+
pub skip_stapling: bool,
5859
pub additional_watch_folders: Vec<PathBuf>,
5960
}
6061

@@ -68,6 +69,7 @@ impl From<crate::build::Options> for Options {
6869
args: options.args,
6970
config: options.config,
7071
no_watch: true,
72+
skip_stapling: options.skip_stapling,
7173
additional_watch_folders: Vec::new(),
7274
}
7375
}
@@ -81,6 +83,7 @@ impl From<crate::bundle::Options> for Options {
8183
target: options.target,
8284
features: options.features,
8385
no_watch: true,
86+
skip_stapling: options.skip_stapling,
8487
..Default::default()
8588
}
8689
}
@@ -96,6 +99,7 @@ impl From<crate::dev::Options> for Options {
9699
args: options.args,
97100
config: options.config,
98101
no_watch: options.no_watch,
102+
skip_stapling: false,
99103
additional_watch_folders: options.additional_watch_folders,
100104
}
101105
}
@@ -813,6 +817,7 @@ impl AppSettings for RustAppSettings {
813817

814818
fn get_bundle_settings(
815819
&self,
820+
options: &Options,
816821
config: &Config,
817822
features: &[String],
818823
) -> crate::Result<BundleSettings> {
@@ -851,6 +856,8 @@ impl AppSettings for RustAppSettings {
851856
arch64bits,
852857
)?;
853858

859+
settings.macos.skip_stapling = options.skip_stapling;
860+
854861
if let Some(plugin_config) = config
855862
.plugins
856863
.0
@@ -1466,6 +1473,7 @@ fn tauri_config_to_bundle_settings(
14661473
minimum_system_version: config.macos.minimum_system_version,
14671474
exception_domain: config.macos.exception_domain,
14681475
signing_identity,
1476+
skip_stapling: false,
14691477
hardened_runtime: config.macos.hardened_runtime,
14701478
provider_short_name,
14711479
entitlements: config.macos.entitlements,

crates/tauri-cli/src/mobile/android/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ impl From<Options> for BuildOptions {
9292
config: options.config,
9393
args: options.args,
9494
ci: options.ci,
95+
skip_stapling: false,
9596
}
9697
}
9798
}

crates/tauri-cli/src/mobile/ios/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ impl From<Options> for BuildOptions {
132132
config: options.config,
133133
args: options.args,
134134
ci: options.ci,
135+
skip_stapling: false,
135136
}
136137
}
137138
}

0 commit comments

Comments
 (0)