Skip to content
Merged
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
7 changes: 7 additions & 0 deletions .changes/disable-binary-patching.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri-bundler": "minor:feat"
"tauri-cli": "minor:feat"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
"tauri-cli": "minor:feat"
"tauri-cli": "minor:feat"
"@tauri-apps/cli": "minor:feat"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied — the changefile now lists all three (tauri-bundler, tauri-cli, @tauri-apps/cli) as minor:feat.

"@tauri-apps/cli": "minor:feat"
---

Add a `--no-binary-patching` flag to `tauri build` and `tauri bundle`. When set, the bundler skips patching the main executable with bundle type information (and the subsequent re-signing), leaving an already-signed binary untouched. Patching is only required when shipping multiple bundle types per platform that should each update with their own installer format.
11 changes: 9 additions & 2 deletions crates/tauri-bundler/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,15 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<Bundle>> {
continue;
}

if let Err(e) = patch_binary(&main_binary_path, package_type) {
log::warn!("Failed to add bundler type to the binary: {e}. Updater plugin may not be able to update this package. This shouldn't normally happen, please report it to https://github.com/tauri-apps/tauri/issues");
if settings.binary_patching() {
if let Err(e) = patch_binary(&main_binary_path, package_type) {
log::warn!("Failed to add bundler type to the binary: {e}. Updater plugin may not be able to update this package. This shouldn't normally happen, please report it to https://github.com/tauri-apps/tauri/issues");
}
} else {
log::warn!(
"Skipping binary patching for {} due to --no-binary-patching flag.",
main_binary_path.display()
);
}

// sign main binary for every package type after patch
Expand Down
42 changes: 40 additions & 2 deletions crates/tauri-bundler/src/bundle/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,10 +830,11 @@ pub struct Settings {
target: String,
/// Whether to disable code signing during the bundling process.
no_sign: bool,
/// Whether to patch the main binary with bundle type information.
binary_patching: bool,
}

/// A builder for [`Settings`].
#[derive(Default)]
pub struct SettingsBuilder {
log_level: Option<log::Level>,
project_out_directory: Option<PathBuf>,
Expand All @@ -844,12 +845,31 @@ pub struct SettingsBuilder {
target: Option<String>,
local_tools_directory: Option<PathBuf>,
no_sign: bool,
binary_patching: bool,
}

impl Default for SettingsBuilder {
fn default() -> Self {
Self {
log_level: None,
project_out_directory: None,
package_types: None,
package_settings: None,
bundle_settings: BundleSettings::default(),
binaries: Vec::new(),
target: None,
local_tools_directory: None,
no_sign: false,
// Binary patching is on by default; disabled via `--no-binary-patching`.
binary_patching: true,
}
}
}

impl SettingsBuilder {
/// Creates the default settings builder.
pub fn new() -> Self {
Default::default()
Self::default()
}

/// Sets the project output directory. It's used as current working directory.
Expand Down Expand Up @@ -920,6 +940,13 @@ impl SettingsBuilder {
self
}

/// Sets whether to patch the main binary with bundle type information. Defaults to `true`.
#[must_use]
pub fn binary_patching(mut self, binary_patching: bool) -> Self {
self.binary_patching = binary_patching;
self
}

/// Builds a Settings from the CLI args.
///
/// Package settings will be read from Cargo.toml.
Expand Down Expand Up @@ -964,6 +991,7 @@ impl SettingsBuilder {
target_platform,
target,
no_sign: self.no_sign,
binary_patching: self.binary_patching,
})
}
}
Expand Down Expand Up @@ -1324,4 +1352,14 @@ impl Settings {
pub fn set_no_sign(&mut self, no_sign: bool) {
self.no_sign = no_sign;
}

/// Whether the main binary is patched with bundle type information.
pub fn binary_patching(&self) -> bool {
self.binary_patching
}

/// Set whether to patch the main binary with bundle type information.
pub fn set_binary_patching(&mut self, binary_patching: bool) {
self.binary_patching = binary_patching;
}
}
8 changes: 8 additions & 0 deletions crates/tauri-cli/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ pub struct Options {
/// Skip code signing when bundling the app
#[clap(long)]
pub no_sign: bool,
/// Skip patching the main executable with bundle type information.
///
/// The patching rewrites the binary in place, invalidating an existing code
/// signature. Skipping it preserves an already-signed binary at the cost of
/// per-bundle-type updater support (only relevant when shipping multiple
/// bundle types per platform).
#[clap(long)]
pub no_binary_patching: bool,
}

pub fn command(mut options: Options, verbosity: u8) -> Result<()> {
Expand Down
11 changes: 11 additions & 0 deletions crates/tauri-cli/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ pub struct Options {
/// are not available or not needed.
#[clap(long)]
pub no_sign: bool,

/// Skip patching the main executable with bundle type information.
///
/// The patching rewrites the binary in place, invalidating an existing code
/// signature. Skipping it preserves an already-signed binary at the cost of
/// per-bundle-type updater support (only relevant when shipping multiple
/// bundle types per platform).
#[clap(long)]
pub no_binary_patching: bool,
}

impl From<crate::build::Options> for Options {
Expand All @@ -113,6 +122,7 @@ impl From<crate::build::Options> for Options {
config: value.config,
skip_stapling: value.skip_stapling,
no_sign: value.no_sign,
no_binary_patching: value.no_binary_patching,
}
}
}
Expand Down Expand Up @@ -209,6 +219,7 @@ pub fn bundle<A: AppSettings>(
)
.context("failed to build bundler settings")?;
settings.set_no_sign(options.no_sign);
settings.set_binary_patching(!options.no_binary_patching);

settings.set_log_level(match verbosity {
0 => log::Level::Error,
Expand Down
1 change: 1 addition & 0 deletions crates/tauri-cli/src/mobile/android/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ impl From<Options> for BuildOptions {
skip_stapling: false,
ignore_version_mismatches: options.ignore_version_mismatches,
no_sign: false,
no_binary_patching: false,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/tauri-cli/src/mobile/ios/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ impl From<Options> for BuildOptions {
skip_stapling: false,
ignore_version_mismatches: options.ignore_version_mismatches,
no_sign: options.no_sign,
no_binary_patching: false,
}
}
}
Expand Down
Loading