Skip to content

Commit d6c7568

Browse files
feat(bundler): Add files option to the AppImage Configuration. (#8720)
* Add `files` option to Appimage * Add .changes file
1 parent 435d751 commit d6c7568

File tree

10 files changed

+98
-31
lines changed

10 files changed

+98
-31
lines changed

.changes/add-files-appimage.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri-bundler": 'patch:enhance'
3+
"tauri-cli": 'patch:enhance'
4+
"@tauri-apps/cli": 'patch:enhance'
5+
---
6+
7+
Add `files` option to the AppImage Configuration.

core/tauri-config-schema/schema.json

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"minSdkVersion": 24
3333
},
3434
"appimage": {
35-
"bundleMediaFramework": false
35+
"bundleMediaFramework": false,
36+
"files": {}
3637
},
3738
"deb": {
3839
"files": {}
@@ -183,7 +184,8 @@
183184
"minSdkVersion": 24
184185
},
185186
"appimage": {
186-
"bundleMediaFramework": false
187+
"bundleMediaFramework": false,
188+
"files": {}
187189
},
188190
"deb": {
189191
"files": {}
@@ -1032,7 +1034,8 @@
10321034
"appimage": {
10331035
"description": "Configuration for the AppImage bundle.",
10341036
"default": {
1035-
"bundleMediaFramework": false
1037+
"bundleMediaFramework": false,
1038+
"files": {}
10361039
},
10371040
"allOf": [
10381041
{
@@ -1373,6 +1376,14 @@
13731376
"description": "Include additional gstreamer dependencies needed for audio and video playback. This increases the bundle size by ~15-35MB depending on your build system.",
13741377
"default": false,
13751378
"type": "boolean"
1379+
},
1380+
"files": {
1381+
"description": "The files to include in the Appimage Binary.",
1382+
"default": {},
1383+
"type": "object",
1384+
"additionalProperties": {
1385+
"type": "string"
1386+
}
13761387
}
13771388
},
13781389
"additionalProperties": false

core/tauri-utils/src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ pub struct AppImageConfig {
292292
/// This increases the bundle size by ~15-35MB depending on your build system.
293293
#[serde(default, alias = "bundle-media-framework")]
294294
pub bundle_media_framework: bool,
295+
/// The files to include in the Appimage Binary.
296+
#[serde(default)]
297+
pub files: HashMap<PathBuf, PathBuf>,
295298
}
296299

297300
/// Configuration for Debian (.deb) bundles.

tooling/bundler/src/bundle.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ use tauri_utils::display_path;
2020
pub use self::{
2121
category::AppCategory,
2222
settings::{
23-
BundleBinary, BundleSettings, DebianSettings, DmgSettings, MacOsSettings, PackageSettings,
24-
PackageType, Position, RpmSettings, Settings, SettingsBuilder, Size, UpdaterSettings,
23+
AppImageSettings, BundleBinary, BundleSettings, DebianSettings, DmgSettings, MacOsSettings,
24+
PackageSettings, PackageType, Position, RpmSettings, Settings, SettingsBuilder, Size,
25+
UpdaterSettings,
2526
},
2627
};
2728
#[cfg(target_os = "macos")]

tooling/bundler/src/bundle/common.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
use log::debug;
77

88
use std::{
9+
collections::HashMap,
910
ffi::OsStr,
1011
fs::{self, File},
1112
io::{self, BufRead, BufReader, BufWriter},
12-
path::Path,
13+
path::{Path, PathBuf},
1314
process::{Command, ExitStatus, Output, Stdio},
1415
sync::{Arc, Mutex},
1516
};
@@ -128,6 +129,32 @@ pub fn copy_dir(from: &Path, to: &Path) -> crate::Result<()> {
128129
Ok(())
129130
}
130131

132+
/// Copies user-defined files specified in the configuration file to the package.
133+
///
134+
/// The configuration object maps the path in the package to the path of the file on the filesystem,
135+
/// relative to the tauri.conf.json file.
136+
///
137+
/// Expects a HashMap of PathBuf entries, representing destination and source paths,
138+
/// and also a path of a directory. The files will be stored with respect to this directory.
139+
pub fn copy_custom_files(
140+
files_map: &HashMap<PathBuf, PathBuf>,
141+
data_dir: &Path,
142+
) -> crate::Result<()> {
143+
for (pkg_path, path) in files_map.iter() {
144+
let pkg_path = if pkg_path.is_absolute() {
145+
pkg_path.strip_prefix("/").unwrap()
146+
} else {
147+
pkg_path
148+
};
149+
if path.is_file() {
150+
copy_file(path, data_dir.join(pkg_path))?;
151+
} else {
152+
copy_dir(path, &data_dir.join(pkg_path))?;
153+
}
154+
}
155+
Ok(())
156+
}
157+
131158
pub trait CommandExt {
132159
// The `pipe` function sets the stdout and stderr to properly
133160
// show the command output in the Node.js wrapper.

tooling/bundler/src/bundle/linux/appimage.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
// SPDX-License-Identifier: MIT
55

66
use super::{
7-
super::{common::CommandExt, path_utils},
7+
super::{
8+
common::{self, CommandExt},
9+
path_utils,
10+
},
811
debian,
912
};
1013
use crate::Settings;
@@ -30,7 +33,10 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
3033
let package_dir = settings.project_out_directory().join("bundle/appimage_deb");
3134

3235
// generate deb_folder structure
33-
let (_, icons) = debian::generate_data(settings, &package_dir)?;
36+
let (data_dir, icons) = debian::generate_data(settings, &package_dir)
37+
.with_context(|| "Failed to build data folders and files")?;
38+
common::copy_custom_files(&settings.deb().files, &data_dir)
39+
.with_context(|| "Failed to copy custom files")?;
3440

3541
let output_path = settings.project_out_directory().join("bundle/appimage");
3642
if output_path.exists() {

tooling/bundler/src/bundle/linux/debian.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
6868

6969
let (data_dir, _) = generate_data(settings, &package_dir)
7070
.with_context(|| "Failed to build data folders and files")?;
71-
copy_custom_files(settings, &data_dir).with_context(|| "Failed to copy custom files")?;
71+
common::copy_custom_files(&settings.deb().files, &data_dir)
72+
.with_context(|| "Failed to copy custom files")?;
7273

7374
// Generate control files.
7475
let control_dir = package_dir.join("control");
@@ -205,23 +206,6 @@ fn copy_resource_files(settings: &Settings, data_dir: &Path) -> crate::Result<()
205206
settings.copy_resources(&resource_dir)
206207
}
207208

208-
/// Copies user-defined files to the deb package.
209-
fn copy_custom_files(settings: &Settings, data_dir: &Path) -> crate::Result<()> {
210-
for (deb_path, path) in settings.deb().files.iter() {
211-
let deb_path = if deb_path.is_absolute() {
212-
deb_path.strip_prefix("/").unwrap()
213-
} else {
214-
deb_path
215-
};
216-
if path.is_file() {
217-
common::copy_file(path, data_dir.join(deb_path))?;
218-
} else {
219-
common::copy_dir(path, &data_dir.join(deb_path))?;
220-
}
221-
}
222-
Ok(())
223-
}
224-
225209
/// Create an empty file at the given path, creating any parent directories as
226210
/// needed, then write `data` into the file.
227211
fn create_file_with_data<P: AsRef<Path>>(path: P, data: &str) -> crate::Result<()> {

tooling/bundler/src/bundle/settings.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ pub struct DebianSettings {
186186
pub desktop_template: Option<PathBuf>,
187187
}
188188

189+
/// The Linux AppImage bundle settings.
190+
#[derive(Clone, Debug, Default)]
191+
pub struct AppImageSettings {
192+
/// The files to include in the Appimage Binary.
193+
pub files: HashMap<PathBuf, PathBuf>,
194+
}
195+
189196
/// The RPM bundle settings.
190197
#[derive(Clone, Debug, Default)]
191198
pub struct RpmSettings {
@@ -482,6 +489,8 @@ pub struct BundleSettings {
482489
pub deep_link_protocols: Option<Vec<DeepLinkProtocol>>,
483490
/// Debian-specific settings.
484491
pub deb: DebianSettings,
492+
/// AppImage-specific settings.
493+
pub appimage: AppImageSettings,
485494
/// Rpm-specific settings.
486495
pub rpm: RpmSettings,
487496
/// DMG-specific settings.
@@ -931,6 +940,11 @@ impl Settings {
931940
&self.bundle_settings.deb
932941
}
933942

943+
/// Returns the appimage settings.
944+
pub fn appimage(&self) -> &AppImageSettings {
945+
&self.bundle_settings.appimage
946+
}
947+
934948
/// Returns the RPM settings.
935949
pub fn rpm(&self) -> &RpmSettings {
936950
&self.bundle_settings.rpm

tooling/cli/schema.json

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"minSdkVersion": 24
3333
},
3434
"appimage": {
35-
"bundleMediaFramework": false
35+
"bundleMediaFramework": false,
36+
"files": {}
3637
},
3738
"deb": {
3839
"files": {}
@@ -183,7 +184,8 @@
183184
"minSdkVersion": 24
184185
},
185186
"appimage": {
186-
"bundleMediaFramework": false
187+
"bundleMediaFramework": false,
188+
"files": {}
187189
},
188190
"deb": {
189191
"files": {}
@@ -1032,7 +1034,8 @@
10321034
"appimage": {
10331035
"description": "Configuration for the AppImage bundle.",
10341036
"default": {
1035-
"bundleMediaFramework": false
1037+
"bundleMediaFramework": false,
1038+
"files": {}
10361039
},
10371040
"allOf": [
10381041
{
@@ -1373,6 +1376,14 @@
13731376
"description": "Include additional gstreamer dependencies needed for audio and video playback. This increases the bundle size by ~15-35MB depending on your build system.",
13741377
"default": false,
13751378
"type": "boolean"
1379+
},
1380+
"files": {
1381+
"description": "The files to include in the Appimage Binary.",
1382+
"default": {},
1383+
"type": "object",
1384+
"additionalProperties": {
1385+
"type": "string"
1386+
}
13761387
}
13771388
},
13781389
"additionalProperties": false

tooling/cli/src/interface/rust.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ use notify::RecursiveMode;
2222
use notify_debouncer_mini::new_debouncer;
2323
use serde::Deserialize;
2424
use tauri_bundler::{
25-
AppCategory, BundleBinary, BundleSettings, DebianSettings, DmgSettings, MacOsSettings,
26-
PackageSettings, Position, RpmSettings, Size, UpdaterSettings, WindowsSettings,
25+
AppCategory, AppImageSettings, BundleBinary, BundleSettings, DebianSettings, DmgSettings,
26+
MacOsSettings, PackageSettings, Position, RpmSettings, Size, UpdaterSettings, WindowsSettings,
2727
};
2828
use tauri_utils::config::{parse::is_configuration_file, DeepLinkProtocol};
2929

@@ -1223,6 +1223,9 @@ fn tauri_config_to_bundle_settings(
12231223
files: config.deb.files,
12241224
desktop_template: config.deb.desktop_template,
12251225
},
1226+
appimage: AppImageSettings {
1227+
files: config.appimage.files,
1228+
},
12261229
rpm: RpmSettings {
12271230
license: config.rpm.license,
12281231
depends: if depends_rpm.is_empty() {

0 commit comments

Comments
 (0)