Skip to content

Commit 058c0db

Browse files
authored
feat(bundler): add option to configure RPM compression (#11584)
1 parent f8994b2 commit 058c0db

File tree

8 files changed

+314
-5
lines changed

8 files changed

+314
-5
lines changed

.changes/rpm-compression-level.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"tauri-bundler": "minor:feat"
3+
"tauri-cli": "minor:feat"
4+
"@tauri-apps/cli": "minor:feat"
5+
"tauri-utils": "minor:feat"
6+
---
7+
8+
Add `bundle > linux > rpm > compression` config option to control RPM bundle compression type and level.
9+
10+

crates/tauri-bundler/src/bundle/linux/rpm.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::{
1212
fs::{self, File},
1313
path::{Path, PathBuf},
1414
};
15+
use tauri_utils::config::RpmCompression;
1516

1617
use super::freedesktop;
1718

@@ -54,11 +55,24 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
5455

5556
let license = settings.license().unwrap_or_default();
5657
let name = heck::AsKebabCase(settings.product_name()).to_string();
58+
59+
let compression = settings
60+
.rpm()
61+
.compression
62+
.map(|c| match c {
63+
RpmCompression::Gzip { level } => rpm::CompressionWithLevel::Gzip(level),
64+
RpmCompression::Zstd { level } => rpm::CompressionWithLevel::Zstd(level),
65+
RpmCompression::Xz { level } => rpm::CompressionWithLevel::Xz(level),
66+
RpmCompression::Bzip2 { level } => rpm::CompressionWithLevel::Bzip2(level),
67+
_ => rpm::CompressionWithLevel::None,
68+
})
69+
// This matches .deb compression. On a 240MB source binary the bundle will be 100KB larger than rpm's default while reducing build times by ~25%.
70+
.unwrap_or(rpm::CompressionWithLevel::Gzip(6));
71+
5772
let mut builder = rpm::PackageBuilder::new(&name, version, &license, arch, summary)
5873
.epoch(epoch)
5974
.release(release)
60-
// This matches .deb compression. On a 240MB source binary the bundle will be 100KB larger than rpm's default while reducing build times by ~25%.
61-
.compression(rpm::CompressionWithLevel::Gzip(6));
75+
.compression(compression);
6276

6377
if let Some(description) = settings.long_description() {
6478
builder = builder.description(description);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ use crate::bundle::{common, platform::target_triple};
88
use anyhow::Context;
99
pub use tauri_utils::config::WebviewInstallMode;
1010
use tauri_utils::{
11-
config::{BundleType, DeepLinkProtocol, FileAssociation, NSISInstallerMode, NsisCompression},
11+
config::{
12+
BundleType, DeepLinkProtocol, FileAssociation, NSISInstallerMode, NsisCompression,
13+
RpmCompression,
14+
},
1215
resources::{external_binaries, ResourcePaths},
1316
};
1417

@@ -262,6 +265,8 @@ pub struct RpmSettings {
262265
/// Path to script that will be executed after the package is removed. See
263266
/// <http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html>
264267
pub post_remove_script: Option<PathBuf>,
268+
/// Compression algorithm and level. Defaults to `Gzip` with level 6.
269+
pub compression: Option<RpmCompression>,
265270
}
266271

267272
/// Position coordinates struct.

crates/tauri-bundler/src/bundle/windows/nsis/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ pub fn bundle_project(settings: &Settings, updater: bool) -> crate::Result<Vec<P
9090

9191
if !mismatched.is_empty() {
9292
log::warn!("NSIS directory contains mis-hashed files. Redownloading them.");
93-
for (path, url, hash, hash_algorithim) in mismatched {
94-
let data = download_and_verify(url, hash, *hash_algorithim)?;
93+
for (path, url, hash, hash_algorithm) in mismatched {
94+
let data = download_and_verify(url, hash, *hash_algorithm)?;
9595
fs::write(nsis_toolset_path.join(path), data)?;
9696
}
9797
}

crates/tauri-cli/config.schema.json

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2789,10 +2789,133 @@
27892789
"string",
27902790
"null"
27912791
]
2792+
},
2793+
"compression": {
2794+
"description": "Compression algorithm and level. Defaults to `Gzip` with level 6.",
2795+
"anyOf": [
2796+
{
2797+
"$ref": "#/definitions/RpmCompression"
2798+
},
2799+
{
2800+
"type": "null"
2801+
}
2802+
]
27922803
}
27932804
},
27942805
"additionalProperties": false
27952806
},
2807+
"RpmCompression": {
2808+
"description": "Compression algorithms used when bundling RPM packages.",
2809+
"oneOf": [
2810+
{
2811+
"description": "Gzip compression",
2812+
"type": "object",
2813+
"required": [
2814+
"level",
2815+
"type"
2816+
],
2817+
"properties": {
2818+
"type": {
2819+
"type": "string",
2820+
"enum": [
2821+
"gzip"
2822+
]
2823+
},
2824+
"level": {
2825+
"description": "Gzip compression level",
2826+
"type": "integer",
2827+
"format": "uint32",
2828+
"minimum": 0.0
2829+
}
2830+
},
2831+
"additionalProperties": false
2832+
},
2833+
{
2834+
"description": "Zstd compression",
2835+
"type": "object",
2836+
"required": [
2837+
"level",
2838+
"type"
2839+
],
2840+
"properties": {
2841+
"type": {
2842+
"type": "string",
2843+
"enum": [
2844+
"zstd"
2845+
]
2846+
},
2847+
"level": {
2848+
"description": "Zstd compression level",
2849+
"type": "integer",
2850+
"format": "int32"
2851+
}
2852+
},
2853+
"additionalProperties": false
2854+
},
2855+
{
2856+
"description": "Xz compression",
2857+
"type": "object",
2858+
"required": [
2859+
"level",
2860+
"type"
2861+
],
2862+
"properties": {
2863+
"type": {
2864+
"type": "string",
2865+
"enum": [
2866+
"xz"
2867+
]
2868+
},
2869+
"level": {
2870+
"description": "Xz compression level",
2871+
"type": "integer",
2872+
"format": "uint32",
2873+
"minimum": 0.0
2874+
}
2875+
},
2876+
"additionalProperties": false
2877+
},
2878+
{
2879+
"description": "Bzip2 compression",
2880+
"type": "object",
2881+
"required": [
2882+
"level",
2883+
"type"
2884+
],
2885+
"properties": {
2886+
"type": {
2887+
"type": "string",
2888+
"enum": [
2889+
"bzip2"
2890+
]
2891+
},
2892+
"level": {
2893+
"description": "Bzip2 compression level",
2894+
"type": "integer",
2895+
"format": "uint32",
2896+
"minimum": 0.0
2897+
}
2898+
},
2899+
"additionalProperties": false
2900+
},
2901+
{
2902+
"description": "Disable compression",
2903+
"type": "object",
2904+
"required": [
2905+
"type"
2906+
],
2907+
"properties": {
2908+
"type": {
2909+
"type": "string",
2910+
"enum": [
2911+
"none"
2912+
]
2913+
}
2914+
},
2915+
"additionalProperties": false
2916+
}
2917+
]
2918+
},
27962919
"MacConfig": {
27972920
"description": "Configuration for the macOS bundles.\n\n See more: <https://v2.tauri.app/reference/config/#macconfig>",
27982921
"type": "object",

crates/tauri-cli/src/interface/rust.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,7 @@ fn tauri_config_to_bundle_settings(
13881388
post_install_script: config.linux.rpm.post_install_script,
13891389
pre_remove_script: config.linux.rpm.pre_remove_script,
13901390
post_remove_script: config.linux.rpm.post_remove_script,
1391+
compression: config.linux.rpm.compression,
13911392
},
13921393
dmg: DmgSettings {
13931394
background: config.macos.dmg.background,

crates/tauri-schema-generator/schemas/config.schema.json

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2789,10 +2789,133 @@
27892789
"string",
27902790
"null"
27912791
]
2792+
},
2793+
"compression": {
2794+
"description": "Compression algorithm and level. Defaults to `Gzip` with level 6.",
2795+
"anyOf": [
2796+
{
2797+
"$ref": "#/definitions/RpmCompression"
2798+
},
2799+
{
2800+
"type": "null"
2801+
}
2802+
]
27922803
}
27932804
},
27942805
"additionalProperties": false
27952806
},
2807+
"RpmCompression": {
2808+
"description": "Compression algorithms used when bundling RPM packages.",
2809+
"oneOf": [
2810+
{
2811+
"description": "Gzip compression",
2812+
"type": "object",
2813+
"required": [
2814+
"level",
2815+
"type"
2816+
],
2817+
"properties": {
2818+
"type": {
2819+
"type": "string",
2820+
"enum": [
2821+
"gzip"
2822+
]
2823+
},
2824+
"level": {
2825+
"description": "Gzip compression level",
2826+
"type": "integer",
2827+
"format": "uint32",
2828+
"minimum": 0.0
2829+
}
2830+
},
2831+
"additionalProperties": false
2832+
},
2833+
{
2834+
"description": "Zstd compression",
2835+
"type": "object",
2836+
"required": [
2837+
"level",
2838+
"type"
2839+
],
2840+
"properties": {
2841+
"type": {
2842+
"type": "string",
2843+
"enum": [
2844+
"zstd"
2845+
]
2846+
},
2847+
"level": {
2848+
"description": "Zstd compression level",
2849+
"type": "integer",
2850+
"format": "int32"
2851+
}
2852+
},
2853+
"additionalProperties": false
2854+
},
2855+
{
2856+
"description": "Xz compression",
2857+
"type": "object",
2858+
"required": [
2859+
"level",
2860+
"type"
2861+
],
2862+
"properties": {
2863+
"type": {
2864+
"type": "string",
2865+
"enum": [
2866+
"xz"
2867+
]
2868+
},
2869+
"level": {
2870+
"description": "Xz compression level",
2871+
"type": "integer",
2872+
"format": "uint32",
2873+
"minimum": 0.0
2874+
}
2875+
},
2876+
"additionalProperties": false
2877+
},
2878+
{
2879+
"description": "Bzip2 compression",
2880+
"type": "object",
2881+
"required": [
2882+
"level",
2883+
"type"
2884+
],
2885+
"properties": {
2886+
"type": {
2887+
"type": "string",
2888+
"enum": [
2889+
"bzip2"
2890+
]
2891+
},
2892+
"level": {
2893+
"description": "Bzip2 compression level",
2894+
"type": "integer",
2895+
"format": "uint32",
2896+
"minimum": 0.0
2897+
}
2898+
},
2899+
"additionalProperties": false
2900+
},
2901+
{
2902+
"description": "Disable compression",
2903+
"type": "object",
2904+
"required": [
2905+
"type"
2906+
],
2907+
"properties": {
2908+
"type": {
2909+
"type": "string",
2910+
"enum": [
2911+
"none"
2912+
]
2913+
}
2914+
},
2915+
"additionalProperties": false
2916+
}
2917+
]
2918+
},
27962919
"MacConfig": {
27972920
"description": "Configuration for the macOS bundles.\n\n See more: <https://v2.tauri.app/reference/config/#macconfig>",
27982921
"type": "object",

0 commit comments

Comments
 (0)