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/fix-build-bundles-arg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri-bundler": patch:bug
"tauri-cli": patch:bug
Comment thread
acx0 marked this conversation as resolved.
"@tauri-apps/cli": patch:bug
---

Fix `build --bundles` to allow `nsis` arg in linux+macOS
42 changes: 27 additions & 15 deletions crates/tauri-bundler/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// SPDX-License-Identifier: MIT

mod category;
#[cfg(any(target_os = "linux", target_os = "windows"))]
mod kmp;
#[cfg(target_os = "linux")]
mod linux;
Expand All @@ -17,26 +16,16 @@ mod windows;

use tauri_utils::{display_path, platform::Target as TargetPlatform};

#[cfg(any(target_os = "linux", target_os = "windows"))]
const BUNDLE_VAR_TOKEN: &[u8] = b"__TAURI_BUNDLE_TYPE_VAR_UNK";
/// Patch a binary with bundle type information
#[cfg(any(target_os = "linux", target_os = "windows"))]
fn patch_binary(binary: &PathBuf, package_type: &PackageType) -> crate::Result<()> {
log::info!(
"Patching {} with bundle type information: {}",
display_path(binary),
package_type.short_name()
);

let mut file_data = std::fs::read(binary).expect("Could not read binary file.");

let bundle_var_index =
kmp::index_of(BUNDLE_VAR_TOKEN, &file_data).ok_or(crate::Error::MissingBundleTypeVar)?;
#[cfg(target_os = "linux")]
let bundle_type = match package_type {
crate::PackageType::Deb => b"__TAURI_BUNDLE_TYPE_VAR_DEB",
crate::PackageType::Rpm => b"__TAURI_BUNDLE_TYPE_VAR_RPM",
crate::PackageType::AppImage => b"__TAURI_BUNDLE_TYPE_VAR_APP",
// NSIS installers can be built in linux using cargo-xwin
crate::PackageType::Nsis => b"__TAURI_BUNDLE_TYPE_VAR_NSS",
_ => {
return Err(crate::Error::InvalidPackageType(
package_type.short_name().to_owned(),
Expand All @@ -55,7 +44,31 @@ fn patch_binary(binary: &PathBuf, package_type: &PackageType) -> crate::Result<(
))
}
};
#[cfg(target_os = "macos")]
let bundle_type = match package_type {
// NSIS installers can be built in macOS using cargo-xwin
crate::PackageType::Nsis => b"__TAURI_BUNDLE_TYPE_VAR_NSS",
crate::PackageType::MacOsBundle | crate::PackageType::Dmg => {
// skip patching for macOS-native bundles
return Ok(());
}
_ => {
return Err(crate::Error::InvalidPackageType(
package_type.short_name().to_owned(),
"macOS".to_owned(),
))
}
};

log::info!(
"Patching {} with bundle type information: {}",
display_path(binary),
package_type.short_name()
);

let mut file_data = std::fs::read(binary).expect("Could not read binary file.");
let bundle_var_index =
kmp::index_of(BUNDLE_VAR_TOKEN, &file_data).ok_or(crate::Error::MissingBundleTypeVar)?;
file_data[bundle_var_index..bundle_var_index + BUNDLE_VAR_TOKEN.len()]
.copy_from_slice(bundle_type);

Expand Down Expand Up @@ -133,7 +146,6 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<Bundle>> {
continue;
}

#[cfg(any(target_os = "linux", target_os = "windows"))]
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");
}
Expand Down Expand Up @@ -163,7 +175,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<Bundle>> {

#[cfg(target_os = "windows")]
PackageType::WindowsMsi => windows::msi::bundle_project(settings, false)?,
// note: don't restrict to windows as NSIS installers can be built in linux using cargo-xwin
// don't restrict to windows as NSIS installers can be built in linux+macOS using cargo-xwin
PackageType::Nsis => windows::nsis::bundle_project(settings, false)?,

#[cfg(target_os = "linux")]
Expand Down
2 changes: 0 additions & 2 deletions crates/tauri-bundler/src/bundle/kmp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

// Knuth–Morris–Pratt algorithm
// based on https://github.com/howeih/rust_kmp
#[cfg(any(target_os = "linux", target_os = "windows"))]
pub fn index_of(pattern: &[u8], target: &[u8]) -> Option<usize> {
let failure_function = find_failure_function(pattern);

Expand Down Expand Up @@ -38,7 +37,6 @@ pub fn index_of(pattern: &[u8], target: &[u8]) -> Option<usize> {
None
}

#[cfg(any(target_os = "linux", target_os = "windows"))]
fn find_failure_function(pattern: &[u8]) -> Vec<usize> {
let mut i = 1;
let mut j = 0;
Expand Down
2 changes: 1 addition & 1 deletion crates/tauri-bundler/src/bundle/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const ALL_PACKAGE_TYPES: &[PackageType] = &[
PackageType::IosBundle,
#[cfg(target_os = "windows")]
PackageType::WindowsMsi,
#[cfg(target_os = "windows")]
// NSIS installers can be built on all platforms but it's hidden in the --help output on macOS/Linux.
PackageType::Nsis,
#[cfg(target_os = "macos")]
PackageType::MacOsBundle,
Expand Down
2 changes: 1 addition & 1 deletion crates/tauri-cli/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl ValueEnum for BundleFormat {
}

fn to_possible_value(&self) -> Option<PossibleValue> {
let hide = self.0 == PackageType::Updater;
let hide = (!cfg!(windows) && self.0 == PackageType::Nsis) || self.0 == PackageType::Updater;
Some(PossibleValue::new(self.0.short_name()).hide(hide))
}
}
Expand Down
Loading