Skip to content

Commit 27bad32

Browse files
feat: Add files field in macos build config, closes #3290 (#7798)
* Add appContents field in macos tauri config. * Change MacConfig::appContents to MacConfig::files to make it similar to DebConfig::files. * Change appContents to files in helloworld/tauri.conf.json * use common::copy_dir helper * add change files [skip ci] --------- Co-authored-by: Lucas Nogueira <lucas@tauri.app>
1 parent 4f73057 commit 27bad32

File tree

11 files changed

+67
-9
lines changed

11 files changed

+67
-9
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri-bundler": patch:feat
3+
"tauri-cli": patch:feat
4+
"@tauri-apps/cli": patch:feat
5+
---
6+
7+
Add `files` object on the `tauri > bundle > macOS` configuration option.

.changes/app-bundle-files.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-bundler": patch:feat
3+
---
4+
5+
Add `files` map on the `MacOsSettings` struct to add custom files to the `.app` bundle.

core/tauri-config-schema/schema.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"icon": [],
5656
"identifier": "",
5757
"macOS": {
58+
"files": {},
5859
"minimumSystemVersion": "10.13"
5960
},
6061
"rpm": {
@@ -208,6 +209,7 @@
208209
"icon": [],
209210
"identifier": "",
210211
"macOS": {
212+
"files": {},
211213
"minimumSystemVersion": "10.13"
212214
},
213215
"rpm": {
@@ -1079,6 +1081,7 @@
10791081
"macOS": {
10801082
"description": "Configuration for the macOS bundles.",
10811083
"default": {
1084+
"files": {},
10821085
"minimumSystemVersion": "10.13"
10831086
},
10841087
"allOf": [
@@ -1570,6 +1573,14 @@
15701573
"type": "string"
15711574
}
15721575
},
1576+
"files": {
1577+
"description": "The files to include in the application relative to the Contents directory.",
1578+
"default": {},
1579+
"type": "object",
1580+
"additionalProperties": {
1581+
"type": "string"
1582+
}
1583+
},
15731584
"minimumSystemVersion": {
15741585
"description": "A version string indicating the minimum macOS X version that the bundled application supports. Defaults to `10.13`.\n\nSetting it to `null` completely removes the `LSMinimumSystemVersion` field on the bundle's `Info.plist` and the `MACOSX_DEPLOYMENT_TARGET` environment variable.\n\nAn empty string is considered an invalid value so the default value is used.",
15751586
"default": "10.13",

core/tauri-utils/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,9 @@ pub struct MacConfig {
427427
///
428428
/// If a name is used, ".framework" must be omitted and it will look for standard install locations. You may also use a path to a specific framework.
429429
pub frameworks: Option<Vec<String>>,
430+
/// The files to include in the application relative to the Contents directory.
431+
#[serde(default)]
432+
pub files: HashMap<PathBuf, PathBuf>,
430433
/// A version string indicating the minimum macOS X version that the bundled application supports. Defaults to `10.13`.
431434
///
432435
/// Setting it to `null` completely removes the `LSMinimumSystemVersion` field on the bundle's `Info.plist`
@@ -459,6 +462,7 @@ impl Default for MacConfig {
459462
fn default() -> Self {
460463
Self {
461464
frameworks: None,
465+
files: HashMap::new(),
462466
minimum_system_version: minimum_system_version(),
463467
exception_domain: None,
464468
license: None,

examples/helloworld/tauri.conf.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
},
3838
"macOS": {
3939
"frameworks": [],
40+
"files": {},
4041
"exceptionDomain": ""
4142
}
4243
},
@@ -53,4 +54,4 @@
5354
"csp": "default-src 'self'; connect-src ipc: http://ipc.localhost"
5455
}
5556
}
56-
}
57+
}

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,7 @@ fn copy_custom_files(settings: &Settings, data_dir: &Path) -> crate::Result<()>
216216
if path.is_file() {
217217
common::copy_file(path, data_dir.join(deb_path))?;
218218
} else {
219-
let out_dir = data_dir.join(deb_path);
220-
for entry in walkdir::WalkDir::new(path) {
221-
let entry_path = entry?.into_path();
222-
if entry_path.is_file() {
223-
let without_prefix = entry_path.strip_prefix(path).unwrap();
224-
common::copy_file(&entry_path, out_dir.join(without_prefix))?;
225-
}
226-
}
219+
common::copy_dir(path, &data_dir.join(deb_path))?;
227220
}
228221
}
229222
Ok(())

tooling/bundler/src/bundle/macos/app.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
106106
is_an_executable: true,
107107
}));
108108

109+
copy_custom_files_to_bundle(&bundle_directory, settings)?;
110+
109111
if let Some(identity) = &settings.macos().signing_identity {
110112
// Sign frameworks and sidecar binaries first, per apple, signing must be done inside out
111113
// https://developer.apple.com/forums/thread/701514
@@ -165,6 +167,25 @@ fn copy_binaries_to_bundle(
165167
Ok(paths)
166168
}
167169

170+
/// Copies user-defined files to the app under Contents.
171+
fn copy_custom_files_to_bundle(bundle_directory: &Path, settings: &Settings) -> crate::Result<()> {
172+
for (contents_path, path) in settings.macos().files.iter() {
173+
let contents_path = if contents_path.is_absolute() {
174+
contents_path.strip_prefix("/").unwrap()
175+
} else {
176+
contents_path
177+
};
178+
if path.is_file() {
179+
common::copy_file(path, bundle_directory.join(contents_path))
180+
.with_context(|| format!("Failed to copy file {:?} to {:?}", path, contents_path))?;
181+
} else {
182+
common::copy_dir(path, &bundle_directory.join(contents_path))
183+
.with_context(|| format!("Failed to copy directory {:?} to {:?}", path, contents_path))?;
184+
}
185+
}
186+
Ok(())
187+
}
188+
168189
// Creates the Info.plist file.
169190
fn create_info_plist(
170191
bundle_dir: &Path,

tooling/bundler/src/bundle/settings.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ pub struct MacOsSettings {
258258
///
259259
/// - embedding the correct rpath in your binary (e.g. by running `install_name_tool -add_rpath "@executable_path/../Frameworks" path/to/binary` after compiling)
260260
pub frameworks: Option<Vec<String>>,
261+
/// List of custom files to add to the application bundle.
262+
/// Maps the path in the Contents directory in the app to the path of the file to include (relative to the current working directory).
263+
pub files: HashMap<PathBuf, PathBuf>,
261264
/// A version string indicating the minimum MacOS version that the bundled app supports (e.g. `"10.11"`).
262265
/// If you are using this config field, you may also want have your `build.rs` script emit `cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET=10.11`.
263266
pub minimum_system_version: Option<String>,

tooling/cli/schema.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"icon": [],
5656
"identifier": "",
5757
"macOS": {
58+
"files": {},
5859
"minimumSystemVersion": "10.13"
5960
},
6061
"rpm": {
@@ -208,6 +209,7 @@
208209
"icon": [],
209210
"identifier": "",
210211
"macOS": {
212+
"files": {},
211213
"minimumSystemVersion": "10.13"
212214
},
213215
"rpm": {
@@ -1079,6 +1081,7 @@
10791081
"macOS": {
10801082
"description": "Configuration for the macOS bundles.",
10811083
"default": {
1084+
"files": {},
10821085
"minimumSystemVersion": "10.13"
10831086
},
10841087
"allOf": [
@@ -1570,6 +1573,14 @@
15701573
"type": "string"
15711574
}
15721575
},
1576+
"files": {
1577+
"description": "The files to include in the application relative to the Contents directory.",
1578+
"default": {},
1579+
"type": "object",
1580+
"additionalProperties": {
1581+
"type": "string"
1582+
}
1583+
},
15731584
"minimumSystemVersion": {
15741585
"description": "A version string indicating the minimum macOS X version that the bundled application supports. Defaults to `10.13`.\n\nSetting it to `null` completely removes the `LSMinimumSystemVersion` field on the bundle's `Info.plist` and the `MACOSX_DEPLOYMENT_TARGET` environment variable.\n\nAn empty string is considered an invalid value so the default value is used.",
15751586
"default": "10.13",

tooling/cli/src/interface/rust.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,7 @@ fn tauri_config_to_bundle_settings(
12241224
},
12251225
macos: MacOsSettings {
12261226
frameworks: config.macos.frameworks,
1227+
files: config.macos.files,
12271228
minimum_system_version: config.macos.minimum_system_version,
12281229
license: config.macos.license,
12291230
exception_domain: config.macos.exception_domain,

0 commit comments

Comments
 (0)