Skip to content

Commit 8de308d

Browse files
feat(core): implement new config structure (#8723)
* feat(core): implement new config structure RFC#5 https://github.com/tauri-apps/rfcs/blob/f3e82a6b0c5390401e855850d47dc7b7d9afd684/texts/0005-tauri-config-restructure.md * fixes * remove tauri-plugin copy [skip ci] * move platform specific configs * fix build * fix cli * doctests * change files * read updater plugin config on CLI * doctests * remove env var from docs * fix getting pubkey * add migrations * clippy * update change file [skip ci] * rename frontendDist to prodFrontend? * Revert "rename frontendDist to prodFrontend?" This reverts commit ef7394f. * fix all_features check * fix field name * single license getter on bundler * readd msiexec_args * remove unused fixture * update template * Update .changes/tauri-bundle-settings-rfc-5.md * Update .changes/config-restructure-rfc-5.md * lint bundler, fix change file * rename AppUrl to FrontendDist, add explicit variants for docs * fix build * lint --------- Co-authored-by: Lucas Nogueira <lucas@tauri.studio> Co-authored-by: Lucas Fernandes Nogueira <lucas@tauri.app>
1 parent e691208 commit 8de308d

File tree

120 files changed

+6799
-7731
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+6799
-7731
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
'tauri': 'major:breaking'
3+
'tauri-utils': 'major:breaking'
4+
'tauri-build': 'major:breaking'
5+
'tauri-codegen': 'major:breaking'
6+
'tauri-cli': 'major:breaking'
7+
'@tauri-apps/cli': 'major:breaking'
8+
---
9+
10+
Restructured Tauri config per [RFC#5](https://github.com/tauri-apps/rfcs/blob/f3e82a6b0c5390401e855850d47dc7b7d9afd684/texts/0005-tauri-config-restructure.md):
11+
12+
- Moved `package.productName`, `package.version` and `tauri.bundle.identifier` fields to the top-level.
13+
- Removed `package` object.
14+
- Renamed `tauri` object to `app`.
15+
- Moved `tauri.bundle` object to the top-level.
16+
- Renamed `build.distDir` field to `frontendDist`.
17+
- Renamed `build.devPath` field to `devUrl` and will no longer accepts paths, it will only accept URLs.
18+
- Moved `tauri.pattern` to `app.security.pattern`.
19+
- Removed `tauri.bundle.updater` object, and its fields have been moved to the updater plugin under `plugins.updater` object.
20+
- Moved `build.withGlobalTauri` to `app.withGlobalTauri`.
21+
- Moved `tauri.bundle.dmg` object to `bundle.macOS.dmg`.
22+
- Moved `tauri.bundle.deb` object to `bundle.linux.deb`.
23+
- Moved `tauri.bundle.appimage` object to `bundle.linux.appimage`.
24+
- Removed all license fields from each bundle configuration object and instead added `bundle.license` and `bundle.licenseFile`.
25+
- Renamed `AppUrl` to `FrontendDist` and refactored its variants to be more explicit.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tauri-bundler': 'major:breaking'
3+
---
4+
5+
- Removed all license fields from `WixSettings`, `NsisSettings` and `MacOsSettings` and replaced with `license` and `license_file` fields in `BundlerSettings`.

core/tauri-build/src/codegen/context.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::{
1010
path::PathBuf,
1111
};
1212
use tauri_codegen::{context_codegen, ContextData};
13-
use tauri_utils::config::{AppUrl, WebviewUrl};
13+
use tauri_utils::config::FrontendDist;
1414

1515
// TODO docs
1616
/// A builder for generating a Tauri application context during compile time.
@@ -82,16 +82,11 @@ impl CodegenContext {
8282
let (config, config_parent) = tauri_codegen::get_config(&self.config_path)?;
8383

8484
// rerun if changed
85-
let app_url = if self.dev {
86-
&config.build.dev_path
87-
} else {
88-
&config.build.dist_dir
89-
};
90-
match app_url {
91-
Some(AppUrl::Url(WebviewUrl::App(p))) => {
85+
match &config.build.frontend_dist {
86+
Some(FrontendDist::Dist(p)) => {
9287
println!("cargo:rerun-if-changed={}", config_parent.join(p).display());
9388
}
94-
Some(AppUrl::Files(files)) => {
89+
Some(FrontendDist::Files(files)) => {
9590
for path in files {
9691
println!(
9792
"cargo:rerun-if-changed={}",
@@ -101,13 +96,13 @@ impl CodegenContext {
10196
}
10297
_ => (),
10398
}
104-
for icon in &config.tauri.bundle.icon {
99+
for icon in &config.bundle.icon {
105100
println!(
106101
"cargo:rerun-if-changed={}",
107102
config_parent.join(icon).display()
108103
);
109104
}
110-
if let Some(tray_icon) = config.tauri.tray_icon.as_ref().map(|t| &t.icon_path) {
105+
if let Some(tray_icon) = config.app.tray_icon.as_ref().map(|t| &t.icon_path) {
111106
println!(
112107
"cargo:rerun-if-changed={}",
113108
config_parent.join(tray_icon).display()

core/tauri-build/src/lib.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
437437
}
438438
let config: Config = serde_json::from_value(config)?;
439439

440-
let s = config.tauri.bundle.identifier.split('.');
440+
let s = config.identifier.split('.');
441441
let last = s.clone().count() - 1;
442442
let mut android_package_prefix = String::new();
443443
for (i, w) in s.enumerate() {
@@ -501,7 +501,7 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
501501
.parent()
502502
.unwrap();
503503

504-
if let Some(paths) = &config.tauri.bundle.external_bin {
504+
if let Some(paths) = &config.bundle.external_bin {
505505
copy_binaries(
506506
ResourcePaths::new(external_binaries(paths, &target_triple).as_slice(), true),
507507
&target_triple,
@@ -512,16 +512,15 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
512512

513513
#[allow(unused_mut, clippy::redundant_clone)]
514514
let mut resources = config
515-
.tauri
516515
.bundle
517516
.resources
518517
.clone()
519518
.unwrap_or_else(|| BundleResources::List(Vec::new()));
520519
if target_triple.contains("windows") {
521520
if let Some(fixed_webview2_runtime_path) =
522-
match &config.tauri.bundle.windows.webview_fixed_runtime_path {
521+
match &config.bundle.windows.webview_fixed_runtime_path {
523522
Some(path) => Some(path),
524-
None => match &config.tauri.bundle.windows.webview_install_mode {
523+
None => match &config.bundle.windows.webview_install_mode {
525524
WebviewInstallMode::FixedRuntime { path } => Some(path),
526525
_ => None,
527526
},
@@ -538,7 +537,7 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
538537
}
539538

540539
if target_triple.contains("darwin") {
541-
if let Some(frameworks) = &config.tauri.bundle.macos.frameworks {
540+
if let Some(frameworks) = &config.bundle.macos.frameworks {
542541
if !frameworks.is_empty() {
543542
let frameworks_dir = target_dir.parent().unwrap().join("Frameworks");
544543
let _ = std::fs::remove_dir_all(&frameworks_dir);
@@ -552,7 +551,7 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
552551
}
553552
}
554553

555-
if let Some(version) = &config.tauri.bundle.macos.minimum_system_version {
554+
if let Some(version) = &config.bundle.macos.minimum_system_version {
556555
println!("cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET={version}");
557556
}
558557
}
@@ -563,7 +562,6 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
563562

564563
fn find_icon<F: Fn(&&String) -> bool>(config: &Config, predicate: F, default: &str) -> PathBuf {
565564
let icon_path = config
566-
.tauri
567565
.bundle
568566
.icon
569567
.iter()
@@ -586,23 +584,23 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
586584
res.set_manifest(include_str!("window-app-manifest.xml"));
587585
}
588586

589-
if let Some(version_str) = &config.package.version {
587+
if let Some(version_str) = &config.version {
590588
if let Ok(v) = Version::parse(version_str) {
591589
let version = v.major << 48 | v.minor << 32 | v.patch << 16;
592590
res.set_version_info(VersionInfo::FILEVERSION, version);
593591
res.set_version_info(VersionInfo::PRODUCTVERSION, version);
594592
}
595593
}
596594

597-
if let Some(product_name) = &config.package.product_name {
595+
if let Some(product_name) = &config.product_name {
598596
res.set("ProductName", product_name);
599597
}
600598

601-
if let Some(short_description) = &config.tauri.bundle.short_description {
599+
if let Some(short_description) = &config.bundle.short_description {
602600
res.set("FileDescription", short_description);
603601
}
604602

605-
if let Some(copyright) = &config.tauri.bundle.copyright {
603+
if let Some(copyright) = &config.bundle.copyright {
606604
res.set("LegalCopyright", copyright);
607605
}
608606

core/tauri-build/src/manifest.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use anyhow::{anyhow, Result};
66
use cargo_toml::{Dependency, Manifest};
7-
use tauri_utils::config::{Config, PatternKind, TauriConfig};
7+
use tauri_utils::config::{AppConfig, Config, PatternKind};
88

99
#[derive(Debug, Default, PartialEq, Eq)]
1010
struct Diff {
@@ -34,7 +34,7 @@ pub fn check(config: &Config, manifest: &mut Manifest) -> Result<()> {
3434
alias: None,
3535
kind: DependencyKind::Build,
3636
all_cli_managed_features: Some(vec!["isolation"]),
37-
expected_features: match config.tauri.pattern {
37+
expected_features: match config.app.security.pattern {
3838
PatternKind::Isolation { .. } => vec!["isolation".to_string()],
3939
_ => vec![],
4040
},
@@ -44,13 +44,13 @@ pub fn check(config: &Config, manifest: &mut Manifest) -> Result<()> {
4444
alias: None,
4545
kind: DependencyKind::Normal,
4646
all_cli_managed_features: Some(
47-
TauriConfig::all_features()
47+
AppConfig::all_features()
4848
.into_iter()
4949
.filter(|f| f != &"tray-icon")
5050
.collect(),
5151
),
5252
expected_features: config
53-
.tauri
53+
.app
5454
.features()
5555
.into_iter()
5656
.filter(|f| f != &"tray-icon")

core/tauri-codegen/src/context.rs

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use tauri_utils::acl::capability::Capability;
1515
use tauri_utils::acl::plugin::Manifest;
1616
use tauri_utils::acl::resolved::Resolved;
1717
use tauri_utils::assets::AssetKey;
18-
use tauri_utils::config::{AppUrl, Config, PatternKind, WebviewUrl};
18+
use tauri_utils::config::{Config, FrontendDist, PatternKind};
1919
use tauri_utils::html::{
2020
inject_nonce_token, parse as parse_html, serialize_node as serialize_html_node,
2121
};
@@ -134,53 +134,43 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
134134
.map(Target::from_triple)
135135
.unwrap_or_else(|_| Target::current());
136136

137-
let mut options = AssetOptions::new(config.tauri.pattern.clone())
138-
.freeze_prototype(config.tauri.security.freeze_prototype)
137+
let mut options = AssetOptions::new(config.app.security.pattern.clone())
138+
.freeze_prototype(config.app.security.freeze_prototype)
139139
.dangerous_disable_asset_csp_modification(
140140
config
141-
.tauri
141+
.app
142142
.security
143143
.dangerous_disable_asset_csp_modification
144144
.clone(),
145145
);
146146
let csp = if dev {
147147
config
148-
.tauri
148+
.app
149149
.security
150150
.dev_csp
151151
.as_ref()
152-
.or(config.tauri.security.csp.as_ref())
152+
.or(config.app.security.csp.as_ref())
153153
} else {
154-
config.tauri.security.csp.as_ref()
154+
config.app.security.csp.as_ref()
155155
};
156156
if csp.is_some() {
157157
options = options.with_csp();
158158
}
159159

160-
let app_url = if dev {
161-
&config.build.dev_path
162-
} else {
163-
&config.build.dist_dir
164-
};
165-
166-
let assets = match app_url {
160+
let assets = match &config.build.frontend_dist {
167161
Some(url) => match url {
168-
AppUrl::Url(url) => match url {
169-
WebviewUrl::External(_) | WebviewUrl::CustomProtocol(_) => Default::default(),
170-
WebviewUrl::App(path) => {
171-
let assets_path = config_parent.join(path);
172-
if !assets_path.exists() {
173-
panic!(
174-
"The `{}` configuration is set to `{:?}` but this path doesn't exist",
175-
if dev { "devPath" } else { "distDir" },
176-
path
177-
)
178-
}
179-
EmbeddedAssets::new(assets_path, &options, map_core_assets(&options, target))?
162+
FrontendDist::Url(_url) => Default::default(),
163+
FrontendDist::Dist(path) => {
164+
let assets_path = config_parent.join(path);
165+
if !assets_path.exists() {
166+
panic!(
167+
"The `frontendDist` configuration is set to `{:?}` but this path doesn't exist",
168+
path
169+
)
180170
}
181-
_ => unimplemented!(),
182-
},
183-
AppUrl::Files(files) => EmbeddedAssets::new(
171+
EmbeddedAssets::new(assets_path, &options, map_core_assets(&options, target))?
172+
}
173+
FrontendDist::Files(files) => EmbeddedAssets::new(
184174
files
185175
.iter()
186176
.map(|p| config_parent.join(p))
@@ -257,12 +247,12 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
257247
quote!(::std::option::Option::None)
258248
};
259249

260-
let package_name = if let Some(product_name) = &config.package.product_name {
250+
let package_name = if let Some(product_name) = &config.product_name {
261251
quote!(#product_name.to_string())
262252
} else {
263253
quote!(env!("CARGO_PKG_NAME").to_string())
264254
};
265-
let package_version = if let Some(version) = &config.package.version {
255+
let package_version = if let Some(version) = &config.version {
266256
semver::Version::from_str(version)?;
267257
quote!(#version.to_string())
268258
} else {
@@ -279,7 +269,7 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
279269
);
280270

281271
let with_tray_icon_code = if target.is_desktop() {
282-
if let Some(tray) = &config.tauri.tray_icon {
272+
if let Some(tray) = &config.app.tray_icon {
283273
let tray_icon_icon_path = config_parent.join(&tray.icon_path);
284274
let ext = tray_icon_icon_path.extension();
285275
if ext.map_or(false, |e| e == "ico") {
@@ -311,10 +301,10 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
311301
};
312302

313303
if let Some(plist) = info_plist.as_dictionary_mut() {
314-
if let Some(product_name) = &config.package.product_name {
304+
if let Some(product_name) = &config.product_name {
315305
plist.insert("CFBundleName".into(), product_name.clone().into());
316306
}
317-
if let Some(version) = &config.package.version {
307+
if let Some(version) = &config.version {
318308
plist.insert("CFBundleShortVersionString".into(), version.clone().into());
319309
}
320310
let format =
@@ -533,7 +523,6 @@ fn find_icon<F: Fn(&&String) -> bool>(
533523
default: &str,
534524
) -> PathBuf {
535525
let icon_path = config
536-
.tauri
537526
.bundle
538527
.icon
539528
.iter()

0 commit comments

Comments
 (0)