Skip to content

Commit af465ea

Browse files
feat(cli): add --no-binary-patching flag to build and bundle (#15619)
* feat(bundler): add bundle > disableBinaryPatching option Tauri patches the main executable with bundle type information so the updater plugin can pick the matching installer format when multiple bundle types target the same platform. This rewrites the binary after it is built, invalidating an existing code signature on it, which breaks bundling an already-signed binary (e.g. inside the NSIS bundler). Add a `bundle > disableBinaryPatching` config option (default false). When set, the bundler skips patching the main binary and the subsequent re-sign, leaving the executable untouched. closes #15591 * feat(cli): add --no-binary-patching flag to build and bundle Switch the disable-binary-patching control from the proposed `bundle > disableBinaryPatching` config option to a `--no-binary-patching` CLI flag on `tauri build` and `tauri bundle`, mirroring the `--no-sign` precedent. When set, the bundler skips patching the main executable with bundle type information (and the subsequent re-sign), preserving an already-signed binary. Patching only matters when shipping multiple bundle types per platform. * chore: add @tauri-apps/cli to changefile * refactor(bundler): use positive binary_patching flag defaulting to true * refactor(bundler): hand-write SettingsBuilder default, notice on skip - Implement Default for SettingsBuilder manually so binary_patching defaults to true, instead of overriding it on top of a derived default. - Log a notice when --no-binary-patching skips patching, mirroring the --no-sign notice, and drop the now-redundant inline comment. * Always sign and warn with path data --------- Co-authored-by: Tony <68118705+Legend-Master@users.noreply.github.com> Co-authored-by: Tony <legendmastertony@gmail.com>
1 parent 19215f6 commit af465ea

7 files changed

Lines changed: 77 additions & 4 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri-bundler": "minor:feat"
3+
"tauri-cli": "minor:feat"
4+
"@tauri-apps/cli": "minor:feat"
5+
---
6+
7+
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.

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,15 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<Bundle>> {
147147
continue;
148148
}
149149

150-
if let Err(e) = patch_binary(&main_binary_path, package_type) {
151-
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");
150+
if settings.binary_patching() {
151+
if let Err(e) = patch_binary(&main_binary_path, package_type) {
152+
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");
153+
}
154+
} else {
155+
log::warn!(
156+
"Skipping binary patching for {} due to --no-binary-patching flag.",
157+
main_binary_path.display()
158+
);
152159
}
153160

154161
// sign main binary for every package type after patch

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

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,10 +830,11 @@ pub struct Settings {
830830
target: String,
831831
/// Whether to disable code signing during the bundling process.
832832
no_sign: bool,
833+
/// Whether to patch the main binary with bundle type information.
834+
binary_patching: bool,
833835
}
834836

835837
/// A builder for [`Settings`].
836-
#[derive(Default)]
837838
pub struct SettingsBuilder {
838839
log_level: Option<log::Level>,
839840
project_out_directory: Option<PathBuf>,
@@ -844,12 +845,31 @@ pub struct SettingsBuilder {
844845
target: Option<String>,
845846
local_tools_directory: Option<PathBuf>,
846847
no_sign: bool,
848+
binary_patching: bool,
849+
}
850+
851+
impl Default for SettingsBuilder {
852+
fn default() -> Self {
853+
Self {
854+
log_level: None,
855+
project_out_directory: None,
856+
package_types: None,
857+
package_settings: None,
858+
bundle_settings: BundleSettings::default(),
859+
binaries: Vec::new(),
860+
target: None,
861+
local_tools_directory: None,
862+
no_sign: false,
863+
// Binary patching is on by default; disabled via `--no-binary-patching`.
864+
binary_patching: true,
865+
}
866+
}
847867
}
848868

849869
impl SettingsBuilder {
850870
/// Creates the default settings builder.
851871
pub fn new() -> Self {
852-
Default::default()
872+
Self::default()
853873
}
854874

855875
/// Sets the project output directory. It's used as current working directory.
@@ -920,6 +940,13 @@ impl SettingsBuilder {
920940
self
921941
}
922942

943+
/// Sets whether to patch the main binary with bundle type information. Defaults to `true`.
944+
#[must_use]
945+
pub fn binary_patching(mut self, binary_patching: bool) -> Self {
946+
self.binary_patching = binary_patching;
947+
self
948+
}
949+
923950
/// Builds a Settings from the CLI args.
924951
///
925952
/// Package settings will be read from Cargo.toml.
@@ -964,6 +991,7 @@ impl SettingsBuilder {
964991
target_platform,
965992
target,
966993
no_sign: self.no_sign,
994+
binary_patching: self.binary_patching,
967995
})
968996
}
969997
}
@@ -1324,4 +1352,14 @@ impl Settings {
13241352
pub fn set_no_sign(&mut self, no_sign: bool) {
13251353
self.no_sign = no_sign;
13261354
}
1355+
1356+
/// Whether the main binary is patched with bundle type information.
1357+
pub fn binary_patching(&self) -> bool {
1358+
self.binary_patching
1359+
}
1360+
1361+
/// Set whether to patch the main binary with bundle type information.
1362+
pub fn set_binary_patching(&mut self, binary_patching: bool) {
1363+
self.binary_patching = binary_patching;
1364+
}
13271365
}

‎crates/tauri-cli/src/build.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ pub struct Options {
7979
/// Skip code signing when bundling the app
8080
#[clap(long)]
8181
pub no_sign: bool,
82+
/// Skip patching the main executable with bundle type information.
83+
///
84+
/// The patching rewrites the binary in place, invalidating an existing code
85+
/// signature. Skipping it preserves an already-signed binary at the cost of
86+
/// per-bundle-type updater support (only relevant when shipping multiple
87+
/// bundle types per platform).
88+
#[clap(long)]
89+
pub no_binary_patching: bool,
8290
}
8391

8492
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
@@ -100,6 +100,15 @@ pub struct Options {
100100
/// are not available or not needed.
101101
#[clap(long)]
102102
pub no_sign: bool,
103+
104+
/// Skip patching the main executable with bundle type information.
105+
///
106+
/// The patching rewrites the binary in place, invalidating an existing code
107+
/// signature. Skipping it preserves an already-signed binary at the cost of
108+
/// per-bundle-type updater support (only relevant when shipping multiple
109+
/// bundle types per platform).
110+
#[clap(long)]
111+
pub no_binary_patching: bool,
103112
}
104113

105114
impl From<crate::build::Options> for Options {
@@ -113,6 +122,7 @@ impl From<crate::build::Options> for Options {
113122
config: value.config,
114123
skip_stapling: value.skip_stapling,
115124
no_sign: value.no_sign,
125+
no_binary_patching: value.no_binary_patching,
116126
}
117127
}
118128
}
@@ -209,6 +219,7 @@ pub fn bundle<A: AppSettings>(
209219
)
210220
.context("failed to build bundler settings")?;
211221
settings.set_no_sign(options.no_sign);
222+
settings.set_binary_patching(!options.no_binary_patching);
212223

213224
settings.set_log_level(match verbosity {
214225
0 => log::Level::Error,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ impl From<Options> for BuildOptions {
106106
skip_stapling: false,
107107
ignore_version_mismatches: options.ignore_version_mismatches,
108108
no_sign: false,
109+
no_binary_patching: false,
109110
}
110111
}
111112
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ impl From<Options> for BuildOptions {
161161
skip_stapling: false,
162162
ignore_version_mismatches: options.ignore_version_mismatches,
163163
no_sign: options.no_sign,
164+
no_binary_patching: false,
164165
}
165166
}
166167
}

0 commit comments

Comments
 (0)