Skip to content

Commit e3bfb01

Browse files
authored
feat(nsis): support choosing compression algorithms, closes #7685 (#7776)
1 parent dfbbca4 commit e3bfb01

File tree

8 files changed

+118
-3
lines changed

8 files changed

+118
-3
lines changed

.changes/nsis-set-compressor.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tauri-bundler': 'patch:enhance'
3+
---
4+
5+
Add `compression` configuration option under `tauri > bundle > windows > nsis`.

core/tauri-config-schema/schema.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,6 +1777,17 @@
17771777
"description": "Whether to display a language selector dialog before the installer and uninstaller windows are rendered or not. By default the OS language is selected, with a fallback to the first language in the `languages` array.",
17781778
"default": false,
17791779
"type": "boolean"
1780+
},
1781+
"compression": {
1782+
"description": "Set the compression algorithm used to compress files in the installer.\n\nSee <https://nsis.sourceforge.io/Reference/SetCompressor>",
1783+
"anyOf": [
1784+
{
1785+
"$ref": "#/definitions/NsisCompression"
1786+
},
1787+
{
1788+
"type": "null"
1789+
}
1790+
]
17801791
}
17811792
},
17821793
"additionalProperties": false
@@ -1807,6 +1818,32 @@
18071818
}
18081819
]
18091820
},
1821+
"NsisCompression": {
1822+
"description": "Compression algorithms used in the NSIS installer.\n\nSee <https://nsis.sourceforge.io/Reference/SetCompressor>",
1823+
"oneOf": [
1824+
{
1825+
"description": "ZLIB uses the deflate algorithm, it is a quick and simple method. With the default compression level it uses about 300 KB of memory.",
1826+
"type": "string",
1827+
"enum": [
1828+
"zlib"
1829+
]
1830+
},
1831+
{
1832+
"description": "BZIP2 usually gives better compression ratios than ZLIB, but it is a bit slower and uses more memory. With the default compression level it uses about 4 MB of memory.",
1833+
"type": "string",
1834+
"enum": [
1835+
"bzip2"
1836+
]
1837+
},
1838+
{
1839+
"description": "LZMA (default) is a new compression method that gives very good compression ratios. The decompression speed is high (10-20 MB/s on a 2 GHz CPU), the compression speed is lower. The memory size that will be used for decompression is the dictionary size plus a few KBs, the default is 8 MB.",
1840+
"type": "string",
1841+
"enum": [
1842+
"lzma"
1843+
]
1844+
}
1845+
]
1846+
},
18101847
"AllowlistConfig": {
18111848
"description": "Allowlist configuration. The allowlist is a translation of the [Cargo allowlist features](https://docs.rs/tauri/latest/tauri/#cargo-allowlist-features).\n\n# Notes\n\n- Endpoints that don't have their own allowlist option are enabled by default. - There is only \"opt-in\", no \"opt-out\". Setting an option to `false` has no effect.\n\n# Examples\n\n- * [`\"app-all\": true`](https://tauri.app/v1/api/config/#appallowlistconfig.all) will make the [hide](https://tauri.app/v1/api/js/app#hide) endpoint be available regardless of whether `hide` is set to `false` or `true` in the allowlist.",
18121849
"type": "object",

core/tauri-utils/src/config.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,21 @@ pub struct WixConfig {
438438
pub dialog_image_path: Option<PathBuf>,
439439
}
440440

441+
/// Compression algorithms used in the NSIS installer.
442+
///
443+
/// See <https://nsis.sourceforge.io/Reference/SetCompressor>
444+
#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
445+
#[cfg_attr(feature = "schema", derive(JsonSchema))]
446+
#[serde(rename_all = "camelCase", deny_unknown_fields)]
447+
pub enum NsisCompression {
448+
/// ZLIB uses the deflate algorithm, it is a quick and simple method. With the default compression level it uses about 300 KB of memory.
449+
Zlib,
450+
/// BZIP2 usually gives better compression ratios than ZLIB, but it is a bit slower and uses more memory. With the default compression level it uses about 4 MB of memory.
451+
Bzip2,
452+
/// LZMA (default) is a new compression method that gives very good compression ratios. The decompression speed is high (10-20 MB/s on a 2 GHz CPU), the compression speed is lower. The memory size that will be used for decompression is the dictionary size plus a few KBs, the default is 8 MB.
453+
Lzma,
454+
}
455+
441456
/// Configuration for the Installer bundle using NSIS.
442457
#[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
443458
#[cfg_attr(feature = "schema", derive(JsonSchema))]
@@ -480,6 +495,10 @@ pub struct NsisConfig {
480495
/// By default the OS language is selected, with a fallback to the first language in the `languages` array.
481496
#[serde(default, alias = "display-language-selector")]
482497
pub display_language_selector: bool,
498+
/// Set the compression algorithm used to compress files in the installer.
499+
///
500+
/// See <https://nsis.sourceforge.io/Reference/SetCompressor>
501+
pub compression: Option<NsisCompression>,
483502
}
484503

485504
/// Install Modes for the NSIS installer.

tooling/bundler/src/bundle/settings.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use super::category::AppCategory;
77
use crate::bundle::{common, platform::target_triple};
88
pub use tauri_utils::config::WebviewInstallMode;
99
use tauri_utils::{
10-
config::{BundleType, NSISInstallerMode},
10+
config::{BundleType, NSISInstallerMode, NsisCompression},
1111
resources::{external_binaries, ResourcePaths},
1212
};
1313

@@ -313,6 +313,8 @@ pub struct NsisSettings {
313313
/// Whether to display a language selector dialog before the installer and uninstaller windows are rendered or not.
314314
/// By default the OS language is selected, with a fallback to the first language in the `languages` array.
315315
pub display_language_selector: bool,
316+
/// Set compression algorithm used to compress files in the installer.
317+
pub compression: Option<NsisCompression>,
316318
}
317319

318320
/// The Windows bundle settings.

tooling/bundler/src/bundle/windows/nsis.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use tauri_utils::display_path;
2020
use anyhow::Context;
2121
use handlebars::{to_json, Handlebars};
2222
use log::{info, warn};
23-
use tauri_utils::config::{NSISInstallerMode, WebviewInstallMode};
23+
use tauri_utils::config::{NSISInstallerMode, NsisCompression, WebviewInstallMode};
2424

2525
use std::{
2626
collections::{BTreeMap, HashMap},
@@ -242,6 +242,15 @@ fn build_nsis_app_installer(
242242
);
243243
}
244244

245+
data.insert(
246+
"compression",
247+
to_json(match &nsis.compression.unwrap_or(NsisCompression::Lzma) {
248+
NsisCompression::Zlib => "zlib",
249+
NsisCompression::Bzip2 => "bzip2",
250+
NsisCompression::Lzma => "lzma",
251+
}),
252+
);
253+
245254
data.insert(
246255
"display_language_selector",
247256
to_json(nsis.display_language_selector && languages.len() > 1),

tooling/bundler/src/bundle/windows/templates/installer.nsi

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
Unicode true
2-
SetCompressor /SOLID lzma
2+
; Set the compression algorithm. Default is LZMA.
3+
!if "{{compression}}" == ""
4+
SetCompressor /SOLID lzma
5+
!else
6+
SetCompressor /SOLID "{{compression}}"
7+
!endif
38

49
!include MUI2.nsh
510
!include FileFunc.nsh

tooling/cli/schema.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,6 +1777,17 @@
17771777
"description": "Whether to display a language selector dialog before the installer and uninstaller windows are rendered or not. By default the OS language is selected, with a fallback to the first language in the `languages` array.",
17781778
"default": false,
17791779
"type": "boolean"
1780+
},
1781+
"compression": {
1782+
"description": "Set the compression algorithm used to compress files in the installer.\n\nSee <https://nsis.sourceforge.io/Reference/SetCompressor>",
1783+
"anyOf": [
1784+
{
1785+
"$ref": "#/definitions/NsisCompression"
1786+
},
1787+
{
1788+
"type": "null"
1789+
}
1790+
]
17801791
}
17811792
},
17821793
"additionalProperties": false
@@ -1807,6 +1818,32 @@
18071818
}
18081819
]
18091820
},
1821+
"NsisCompression": {
1822+
"description": "Compression algorithms used in the NSIS installer.\n\nSee <https://nsis.sourceforge.io/Reference/SetCompressor>",
1823+
"oneOf": [
1824+
{
1825+
"description": "ZLIB uses the deflate algorithm, it is a quick and simple method. With the default compression level it uses about 300 KB of memory.",
1826+
"type": "string",
1827+
"enum": [
1828+
"zlib"
1829+
]
1830+
},
1831+
{
1832+
"description": "BZIP2 usually gives better compression ratios than ZLIB, but it is a bit slower and uses more memory. With the default compression level it uses about 4 MB of memory.",
1833+
"type": "string",
1834+
"enum": [
1835+
"bzip2"
1836+
]
1837+
},
1838+
{
1839+
"description": "LZMA (default) is a new compression method that gives very good compression ratios. The decompression speed is high (10-20 MB/s on a 2 GHz CPU), the compression speed is lower. The memory size that will be used for decompression is the dictionary size plus a few KBs, the default is 8 MB.",
1840+
"type": "string",
1841+
"enum": [
1842+
"lzma"
1843+
]
1844+
}
1845+
]
1846+
},
18101847
"AllowlistConfig": {
18111848
"description": "Allowlist configuration. The allowlist is a translation of the [Cargo allowlist features](https://docs.rs/tauri/latest/tauri/#cargo-allowlist-features).\n\n# Notes\n\n- Endpoints that don't have their own allowlist option are enabled by default. - There is only \"opt-in\", no \"opt-out\". Setting an option to `false` has no effect.\n\n# Examples\n\n- * [`\"app-all\": true`](https://tauri.app/v1/api/config/#appallowlistconfig.all) will make the [hide](https://tauri.app/v1/api/js/app#hide) endpoint be available regardless of whether `hide` is set to `false` or `true` in the allowlist.",
18121849
"type": "object",

tooling/cli/src/helpers/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ pub fn nsis_settings(config: NsisConfig) -> tauri_bundler::NsisSettings {
108108
languages: config.languages,
109109
custom_language_files: config.custom_language_files,
110110
display_language_selector: config.display_language_selector,
111+
compression: config.compression,
111112
}
112113
}
113114

0 commit comments

Comments
 (0)