Skip to content

Commit

Permalink
feat(bundler): add option to configure RPM compression (#11584)
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir authored Nov 5, 2024
1 parent f8994b2 commit 058c0db
Show file tree
Hide file tree
Showing 8 changed files with 314 additions and 5 deletions.
10 changes: 10 additions & 0 deletions .changes/rpm-compression-level.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"tauri-bundler": "minor:feat"
"tauri-cli": "minor:feat"
"@tauri-apps/cli": "minor:feat"
"tauri-utils": "minor:feat"
---

Add `bundle > linux > rpm > compression` config option to control RPM bundle compression type and level.


18 changes: 16 additions & 2 deletions crates/tauri-bundler/src/bundle/linux/rpm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::{
fs::{self, File},
path::{Path, PathBuf},
};
use tauri_utils::config::RpmCompression;

use super::freedesktop;

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

let license = settings.license().unwrap_or_default();
let name = heck::AsKebabCase(settings.product_name()).to_string();

let compression = settings
.rpm()
.compression
.map(|c| match c {
RpmCompression::Gzip { level } => rpm::CompressionWithLevel::Gzip(level),
RpmCompression::Zstd { level } => rpm::CompressionWithLevel::Zstd(level),
RpmCompression::Xz { level } => rpm::CompressionWithLevel::Xz(level),
RpmCompression::Bzip2 { level } => rpm::CompressionWithLevel::Bzip2(level),
_ => rpm::CompressionWithLevel::None,
})
// 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%.
.unwrap_or(rpm::CompressionWithLevel::Gzip(6));

let mut builder = rpm::PackageBuilder::new(&name, version, &license, arch, summary)
.epoch(epoch)
.release(release)
// 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%.
.compression(rpm::CompressionWithLevel::Gzip(6));
.compression(compression);

if let Some(description) = settings.long_description() {
builder = builder.description(description);
Expand Down
7 changes: 6 additions & 1 deletion crates/tauri-bundler/src/bundle/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use crate::bundle::{common, platform::target_triple};
use anyhow::Context;
pub use tauri_utils::config::WebviewInstallMode;
use tauri_utils::{
config::{BundleType, DeepLinkProtocol, FileAssociation, NSISInstallerMode, NsisCompression},
config::{
BundleType, DeepLinkProtocol, FileAssociation, NSISInstallerMode, NsisCompression,
RpmCompression,
},
resources::{external_binaries, ResourcePaths},
};

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

/// Position coordinates struct.
Expand Down
4 changes: 2 additions & 2 deletions crates/tauri-bundler/src/bundle/windows/nsis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ pub fn bundle_project(settings: &Settings, updater: bool) -> crate::Result<Vec<P

if !mismatched.is_empty() {
log::warn!("NSIS directory contains mis-hashed files. Redownloading them.");
for (path, url, hash, hash_algorithim) in mismatched {
let data = download_and_verify(url, hash, *hash_algorithim)?;
for (path, url, hash, hash_algorithm) in mismatched {
let data = download_and_verify(url, hash, *hash_algorithm)?;
fs::write(nsis_toolset_path.join(path), data)?;
}
}
Expand Down
123 changes: 123 additions & 0 deletions crates/tauri-cli/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2789,10 +2789,133 @@
"string",
"null"
]
},
"compression": {
"description": "Compression algorithm and level. Defaults to `Gzip` with level 6.",
"anyOf": [
{
"$ref": "#/definitions/RpmCompression"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false
},
"RpmCompression": {
"description": "Compression algorithms used when bundling RPM packages.",
"oneOf": [
{
"description": "Gzip compression",
"type": "object",
"required": [
"level",
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"gzip"
]
},
"level": {
"description": "Gzip compression level",
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
},
"additionalProperties": false
},
{
"description": "Zstd compression",
"type": "object",
"required": [
"level",
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"zstd"
]
},
"level": {
"description": "Zstd compression level",
"type": "integer",
"format": "int32"
}
},
"additionalProperties": false
},
{
"description": "Xz compression",
"type": "object",
"required": [
"level",
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"xz"
]
},
"level": {
"description": "Xz compression level",
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
},
"additionalProperties": false
},
{
"description": "Bzip2 compression",
"type": "object",
"required": [
"level",
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"bzip2"
]
},
"level": {
"description": "Bzip2 compression level",
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
},
"additionalProperties": false
},
{
"description": "Disable compression",
"type": "object",
"required": [
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"none"
]
}
},
"additionalProperties": false
}
]
},
"MacConfig": {
"description": "Configuration for the macOS bundles.\n\n See more: <https://v2.tauri.app/reference/config/#macconfig>",
"type": "object",
Expand Down
1 change: 1 addition & 0 deletions crates/tauri-cli/src/interface/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1388,6 +1388,7 @@ fn tauri_config_to_bundle_settings(
post_install_script: config.linux.rpm.post_install_script,
pre_remove_script: config.linux.rpm.pre_remove_script,
post_remove_script: config.linux.rpm.post_remove_script,
compression: config.linux.rpm.compression,
},
dmg: DmgSettings {
background: config.macos.dmg.background,
Expand Down
123 changes: 123 additions & 0 deletions crates/tauri-schema-generator/schemas/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2789,10 +2789,133 @@
"string",
"null"
]
},
"compression": {
"description": "Compression algorithm and level. Defaults to `Gzip` with level 6.",
"anyOf": [
{
"$ref": "#/definitions/RpmCompression"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false
},
"RpmCompression": {
"description": "Compression algorithms used when bundling RPM packages.",
"oneOf": [
{
"description": "Gzip compression",
"type": "object",
"required": [
"level",
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"gzip"
]
},
"level": {
"description": "Gzip compression level",
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
},
"additionalProperties": false
},
{
"description": "Zstd compression",
"type": "object",
"required": [
"level",
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"zstd"
]
},
"level": {
"description": "Zstd compression level",
"type": "integer",
"format": "int32"
}
},
"additionalProperties": false
},
{
"description": "Xz compression",
"type": "object",
"required": [
"level",
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"xz"
]
},
"level": {
"description": "Xz compression level",
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
},
"additionalProperties": false
},
{
"description": "Bzip2 compression",
"type": "object",
"required": [
"level",
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"bzip2"
]
},
"level": {
"description": "Bzip2 compression level",
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
},
"additionalProperties": false
},
{
"description": "Disable compression",
"type": "object",
"required": [
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"none"
]
}
},
"additionalProperties": false
}
]
},
"MacConfig": {
"description": "Configuration for the macOS bundles.\n\n See more: <https://v2.tauri.app/reference/config/#macconfig>",
"type": "object",
Expand Down
Loading

0 comments on commit 058c0db

Please sign in to comment.