Skip to content

Commit

Permalink
feat(bundler): Add files option to the AppImage Configuration. (#8720)
Browse files Browse the repository at this point in the history
* Add `files` option to Appimage

* Add .changes file
  • Loading branch information
naman-crabnebula committed Feb 1, 2024
1 parent 435d751 commit d6c7568
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 31 deletions.
7 changes: 7 additions & 0 deletions .changes/add-files-appimage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri-bundler": 'patch:enhance'
"tauri-cli": 'patch:enhance'
"@tauri-apps/cli": 'patch:enhance'
---

Add `files` option to the AppImage Configuration.
17 changes: 14 additions & 3 deletions core/tauri-config-schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"minSdkVersion": 24
},
"appimage": {
"bundleMediaFramework": false
"bundleMediaFramework": false,
"files": {}
},
"deb": {
"files": {}
Expand Down Expand Up @@ -183,7 +184,8 @@
"minSdkVersion": 24
},
"appimage": {
"bundleMediaFramework": false
"bundleMediaFramework": false,
"files": {}
},
"deb": {
"files": {}
Expand Down Expand Up @@ -1032,7 +1034,8 @@
"appimage": {
"description": "Configuration for the AppImage bundle.",
"default": {
"bundleMediaFramework": false
"bundleMediaFramework": false,
"files": {}
},
"allOf": [
{
Expand Down Expand Up @@ -1373,6 +1376,14 @@
"description": "Include additional gstreamer dependencies needed for audio and video playback. This increases the bundle size by ~15-35MB depending on your build system.",
"default": false,
"type": "boolean"
},
"files": {
"description": "The files to include in the Appimage Binary.",
"default": {},
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"additionalProperties": false
Expand Down
3 changes: 3 additions & 0 deletions core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ pub struct AppImageConfig {
/// This increases the bundle size by ~15-35MB depending on your build system.
#[serde(default, alias = "bundle-media-framework")]
pub bundle_media_framework: bool,
/// The files to include in the Appimage Binary.
#[serde(default)]
pub files: HashMap<PathBuf, PathBuf>,
}

/// Configuration for Debian (.deb) bundles.
Expand Down
5 changes: 3 additions & 2 deletions tooling/bundler/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ use tauri_utils::display_path;
pub use self::{
category::AppCategory,
settings::{
BundleBinary, BundleSettings, DebianSettings, DmgSettings, MacOsSettings, PackageSettings,
PackageType, Position, RpmSettings, Settings, SettingsBuilder, Size, UpdaterSettings,
AppImageSettings, BundleBinary, BundleSettings, DebianSettings, DmgSettings, MacOsSettings,
PackageSettings, PackageType, Position, RpmSettings, Settings, SettingsBuilder, Size,
UpdaterSettings,
},
};
#[cfg(target_os = "macos")]
Expand Down
29 changes: 28 additions & 1 deletion tooling/bundler/src/bundle/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
use log::debug;

use std::{
collections::HashMap,
ffi::OsStr,
fs::{self, File},
io::{self, BufRead, BufReader, BufWriter},
path::Path,
path::{Path, PathBuf},
process::{Command, ExitStatus, Output, Stdio},
sync::{Arc, Mutex},
};
Expand Down Expand Up @@ -128,6 +129,32 @@ pub fn copy_dir(from: &Path, to: &Path) -> crate::Result<()> {
Ok(())
}

/// Copies user-defined files specified in the configuration file to the package.
///
/// The configuration object maps the path in the package to the path of the file on the filesystem,
/// relative to the tauri.conf.json file.
///
/// Expects a HashMap of PathBuf entries, representing destination and source paths,
/// and also a path of a directory. The files will be stored with respect to this directory.
pub fn copy_custom_files(
files_map: &HashMap<PathBuf, PathBuf>,
data_dir: &Path,
) -> crate::Result<()> {
for (pkg_path, path) in files_map.iter() {
let pkg_path = if pkg_path.is_absolute() {
pkg_path.strip_prefix("/").unwrap()
} else {
pkg_path
};
if path.is_file() {
copy_file(path, data_dir.join(pkg_path))?;
} else {
copy_dir(path, &data_dir.join(pkg_path))?;
}
}
Ok(())
}

pub trait CommandExt {
// The `pipe` function sets the stdout and stderr to properly
// show the command output in the Node.js wrapper.
Expand Down
10 changes: 8 additions & 2 deletions tooling/bundler/src/bundle/linux/appimage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
// SPDX-License-Identifier: MIT

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

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

let output_path = settings.project_out_directory().join("bundle/appimage");
if output_path.exists() {
Expand Down
20 changes: 2 additions & 18 deletions tooling/bundler/src/bundle/linux/debian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {

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

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

/// Copies user-defined files to the deb package.
fn copy_custom_files(settings: &Settings, data_dir: &Path) -> crate::Result<()> {
for (deb_path, path) in settings.deb().files.iter() {
let deb_path = if deb_path.is_absolute() {
deb_path.strip_prefix("/").unwrap()
} else {
deb_path
};
if path.is_file() {
common::copy_file(path, data_dir.join(deb_path))?;
} else {
common::copy_dir(path, &data_dir.join(deb_path))?;
}
}
Ok(())
}

/// Create an empty file at the given path, creating any parent directories as
/// needed, then write `data` into the file.
fn create_file_with_data<P: AsRef<Path>>(path: P, data: &str) -> crate::Result<()> {
Expand Down
14 changes: 14 additions & 0 deletions tooling/bundler/src/bundle/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ pub struct DebianSettings {
pub desktop_template: Option<PathBuf>,
}

/// The Linux AppImage bundle settings.
#[derive(Clone, Debug, Default)]
pub struct AppImageSettings {
/// The files to include in the Appimage Binary.
pub files: HashMap<PathBuf, PathBuf>,
}

/// The RPM bundle settings.
#[derive(Clone, Debug, Default)]
pub struct RpmSettings {
Expand Down Expand Up @@ -482,6 +489,8 @@ pub struct BundleSettings {
pub deep_link_protocols: Option<Vec<DeepLinkProtocol>>,
/// Debian-specific settings.
pub deb: DebianSettings,
/// AppImage-specific settings.
pub appimage: AppImageSettings,
/// Rpm-specific settings.
pub rpm: RpmSettings,
/// DMG-specific settings.
Expand Down Expand Up @@ -931,6 +940,11 @@ impl Settings {
&self.bundle_settings.deb
}

/// Returns the appimage settings.
pub fn appimage(&self) -> &AppImageSettings {
&self.bundle_settings.appimage
}

/// Returns the RPM settings.
pub fn rpm(&self) -> &RpmSettings {
&self.bundle_settings.rpm
Expand Down
17 changes: 14 additions & 3 deletions tooling/cli/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"minSdkVersion": 24
},
"appimage": {
"bundleMediaFramework": false
"bundleMediaFramework": false,
"files": {}
},
"deb": {
"files": {}
Expand Down Expand Up @@ -183,7 +184,8 @@
"minSdkVersion": 24
},
"appimage": {
"bundleMediaFramework": false
"bundleMediaFramework": false,
"files": {}
},
"deb": {
"files": {}
Expand Down Expand Up @@ -1032,7 +1034,8 @@
"appimage": {
"description": "Configuration for the AppImage bundle.",
"default": {
"bundleMediaFramework": false
"bundleMediaFramework": false,
"files": {}
},
"allOf": [
{
Expand Down Expand Up @@ -1373,6 +1376,14 @@
"description": "Include additional gstreamer dependencies needed for audio and video playback. This increases the bundle size by ~15-35MB depending on your build system.",
"default": false,
"type": "boolean"
},
"files": {
"description": "The files to include in the Appimage Binary.",
"default": {},
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"additionalProperties": false
Expand Down
7 changes: 5 additions & 2 deletions tooling/cli/src/interface/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use notify::RecursiveMode;
use notify_debouncer_mini::new_debouncer;
use serde::Deserialize;
use tauri_bundler::{
AppCategory, BundleBinary, BundleSettings, DebianSettings, DmgSettings, MacOsSettings,
PackageSettings, Position, RpmSettings, Size, UpdaterSettings, WindowsSettings,
AppCategory, AppImageSettings, BundleBinary, BundleSettings, DebianSettings, DmgSettings,
MacOsSettings, PackageSettings, Position, RpmSettings, Size, UpdaterSettings, WindowsSettings,
};
use tauri_utils::config::{parse::is_configuration_file, DeepLinkProtocol};

Expand Down Expand Up @@ -1223,6 +1223,9 @@ fn tauri_config_to_bundle_settings(
files: config.deb.files,
desktop_template: config.deb.desktop_template,
},
appimage: AppImageSettings {
files: config.appimage.files,
},
rpm: RpmSettings {
license: config.rpm.license,
depends: if depends_rpm.is_empty() {
Expand Down

0 comments on commit d6c7568

Please sign in to comment.