Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 6 additions & 0 deletions .changes/fix-build-bundles-arg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri-cli": patch:bug
Comment thread
acx0 marked this conversation as resolved.
Resolved
"@tauri-apps/cli": patch:bug
---

Fix `build --bundles` to allow `nsis` arg in linux+macOS
19 changes: 14 additions & 5 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,10 +16,8 @@ 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: {}",
Expand All @@ -37,6 +34,8 @@ fn patch_binary(binary: &PathBuf, package_type: &PackageType) -> crate::Result<(
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,6 +54,17 @@ 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",
_ => {
return Err(crate::Error::InvalidPackageType(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

didn't test it but i think this will return an error when you're building for macos on macos now. I think we still should not patch these binaries but we could return Ok(()) in these cases. Just wondering if that should happen at the top of the function so we don't print the "Patchin x with bundle type information" stuff 🤔

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.

Oops yeah it emitted a warning about but still but continued with the rest of the bundling process since patching is best-effort:

    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");
    }

I moved things around a bit, lmk what you think

macos native bundle:

    Finished `release` profile [optimized] target(s) in 32.46s
       Built application at: /Users/sentinowl/src/sentinowl-desktop/core/target/aarch64-apple-darwin/release/sentinowl
    Bundling Sentinowl.app (/Users/sentinowl/src/sentinowl-desktop/core/target/aarch64-apple-darwin/release/bundle/macos/Sentinowl.app)
     Signing with identity "M4DQ8GQP99"
Signing with identity "M4DQ8GQP99"
Signing /Users/sentinowl/src/sentinowl-desktop/core/target/aarch64-apple-darwin/release/bundle/macos/Sentinowl.app/Contents/MacOS/smartctl
/Users/sentinowl/src/sentinowl-desktop/core/target/aarch64-apple-darwin/release/bundle/macos/Sentinowl.app/Contents/MacOS/smartctl: replacing existing signature
Signing with identity "M4DQ8GQP99"
Signing /Users/sentinowl/src/sentinowl-desktop/core/target/aarch64-apple-darwin/release/bundle/macos/Sentinowl.app/Contents/MacOS/sentinowl
/Users/sentinowl/src/sentinowl-desktop/core/target/aarch64-apple-darwin/release/bundle/macos/Sentinowl.app/Contents/MacOS/sentinowl: replacing existing signature
Signing with identity "M4DQ8GQP99"
Signing /Users/sentinowl/src/sentinowl-desktop/core/target/aarch64-apple-darwin/release/bundle/macos/Sentinowl.app
/Users/sentinowl/src/sentinowl-desktop/core/target/aarch64-apple-darwin/release/bundle/macos/Sentinowl.app: replacing existing signature
Signing with identity "M4DQ8GQP99"
Signing /var/folders/dn/9c46q9997jq536qwbl3k67x40000gr/T/.tmpJn8d56/Sentinowl.zip
Notarizing /Users/sentinowl/src/sentinowl-desktop/core/target/aarch64-apple-darwin/release/bundle/macos/Sentinowl.app
Notarizing Finished with status Accepted for id 8c4b306d-5a9f-443b-964d-7f51dcfd00d2 (Processing complete)
Stapling app...
    Bundling Sentinowl_0.10.1_aarch64.dmg (/Users/sentinowl/src/sentinowl-desktop/core/target/aarch64-apple-darwin/release/bundle/dmg/Sentinowl_0.10.1_aarch64.dmg)
     Running bundle_dmg.sh
     Signing with identity "M4DQ8GQP99"
Signing with identity "M4DQ8GQP99"
Signing /Users/sentinowl/src/sentinowl-desktop/core/target/aarch64-apple-darwin/release/bundle/dmg/Sentinowl_0.10.1_aarch64.dmg
    Bundling /Users/sentinowl/src/sentinowl-desktop/core/target/aarch64-apple-darwin/release/bundle/macos/Sentinowl.app.tar.gz (/Users/sentinowl/src/sentinowl-desktop/core/target/aarch64-apple-darwin/release/bundle/macos/Sentinowl.app.tar.gz)
    Finished 2 bundles at:
        /Users/sentinowl/src/sentinowl-desktop/core/target/aarch64-apple-darwin/release/bundle/macos/Sentinowl.app
        /Users/sentinowl/src/sentinowl-desktop/core/target/aarch64-apple-darwin/release/bundle/dmg/Sentinowl_0.10.1_aarch64.dmg
        /Users/sentinowl/src/sentinowl-desktop/core/target/aarch64-apple-darwin/release/bundle/macos/Sentinowl.app.tar.gz (updater)

    Finished 1 updater signature at:
        /Users/sentinowl/src/sentinowl-desktop/core/target/aarch64-apple-darwin/release/bundle/macos/Sentinowl.app.tar.gz.sig

macos host + cargo-xwin:

   Compiling sentinowl v0.10.1 (/Users/sentinowl/src/sentinowl-desktop/core)
    Finished `release` profile [optimized] target(s) in 31.70s
       Built application at: /Users/sentinowl/src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/sentinowl.exe
        Warn Cross-platform compilation is experimental and does not support all features. Please use a matching host system for full compatibility.
        Warn Signing, by default, is only supported on Windows hosts, but you can specify a custom signing command in `bundler > windows > sign_command`, for now, skipping signing the installer...
        Info Patching /Users/sentinowl/src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/sentinowl.exe with bundle type information: nsis
        Info Target: x64
     Running makensis to produce /Users/sentinowl/src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/bundle/nsis/Sentinowl_0.10.1_x64-setup.exe
warning 5202: -OUTPUTCHARSET is disabled for non Win32 platforms.
        Warn Signing, by default, is only supported on Windows hosts, but you can specify a custom signing command in `bundler > windows > sign_command`, for now, skipping signing the installer...
    Finished 1 bundle at:
        /Users/sentinowl/src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/bundle/nsis/Sentinowl_0.10.1_x64-setup.exe

    Finished 1 updater signature at:
        /Users/sentinowl/src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/bundle/nsis/Sentinowl_0.10.1_x64-setup.exe.sig

linux host + cargo-xin:

   Compiling sentinowl v0.10.1 (/src/sentinowl-desktop/core)
    Finished `release` profile [optimized] target(s) in 25.15s
       Built application at: /src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/sentinowl.exe
        Warn Cross-platform compilation is experimental and does not support all features. Please use a matching host system for full compatibility.
     Signing ../../build-artifacts/smartmontools/smartctl-x86_64-pc-windows-msvc.exe
     Signing ../../build-artifacts/smartmontools/smartctl-x86_64-pc-windows-msvc.exe with a custom signing command
     Signing Output of signing command:
skipping signing of smartctl binary [../../build-artifacts/smartmontools/smartctl-x86_64-pc-windows-msvc.exe]
        Info Patching /src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/sentinowl.exe with bundle type information: nsis
     Signing /src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/sentinowl.exe
     Signing /src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/sentinowl.exe with a custom signing command
     Signing Output of signing command:
Adding Authenticode signature to /src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/sentinowl.exe
        Info Target: x64
        Info Signing NSIS plugins
     Signing /src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/nsis/x64/Plugins/x86-unicode/NSISdl.dll
     Signing /src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/nsis/x64/Plugins/x86-unicode/NSISdl.dll with a custom signing command
     Signing Output of signing command:
skipping signing of dll [/src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/nsis/x64/Plugins/x86-unicode/NSISdl.dll]
     Signing /src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/nsis/x64/Plugins/x86-unicode/StartMenu.dll
     Signing /src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/nsis/x64/Plugins/x86-unicode/StartMenu.dll with a custom signing command
     Signing Output of signing command:
skipping signing of dll [/src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/nsis/x64/Plugins/x86-unicode/StartMenu.dll]
     Signing /src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/nsis/x64/Plugins/x86-unicode/System.dll
     Signing /src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/nsis/x64/Plugins/x86-unicode/System.dll with a custom signing command
     Signing Output of signing command:
skipping signing of dll [/src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/nsis/x64/Plugins/x86-unicode/System.dll]
     Signing /src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/nsis/x64/Plugins/x86-unicode/nsDialogs.dll
     Signing /src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/nsis/x64/Plugins/x86-unicode/nsDialogs.dll with a custom signing command
     Signing Output of signing command:
skipping signing of dll [/src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/nsis/x64/Plugins/x86-unicode/nsDialogs.dll]
     Signing /src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/nsis/x64/Plugins/x86-unicode/additional/nsis_tauri_utils.dll
     Signing /src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/nsis/x64/Plugins/x86-unicode/additional/nsis_tauri_utils.dll with a custom signing command
     Signing Output of signing command:
skipping signing of dll [/src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/nsis/x64/Plugins/x86-unicode/additional/nsis_tauri_utils.dll]
     Running makensis to produce /src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/bundle/nsis/Sentinowl_0.10.1_x64-setup.exe
warning 5202: -OUTPUTCHARSET is disabled for non Win32 platforms.
Adding Authenticode signature to /tmp/makensisgFoE6r
     Signing /src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/bundle/nsis/Sentinowl_0.10.1_x64-setup.exe
     Signing /src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/bundle/nsis/Sentinowl_0.10.1_x64-setup.exe with a custom signing command
     Signing Output of signing command:
Adding Authenticode signature to /src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/bundle/nsis/Sentinowl_0.10.1_x64-setup.exe
    Finished 1 bundle at:
        /src/sentinowl-desktop/core/target/x86_64-pc-windows-msvc/release/bundle/nsis/Sentinowl_0.10.1_x64-setup.exe

    Finished 1 updater signature at:
        /home/sam/var/cargo-build/sentinowl/x86_64-pc-windows-msvc/release/bundle/nsis/Sentinowl_0.10.1_x64-setup.exe.sig

package_type.short_name().to_owned(),
"macOS".to_owned(),
))
}
};

file_data[bundle_var_index..bundle_var_index + BUNDLE_VAR_TOKEN.len()]
.copy_from_slice(bundle_type);
Expand Down Expand Up @@ -133,7 +143,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 +172,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