Skip to content

Commit

Permalink
feat(core): implement new config structure (#8723)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people committed Feb 3, 2024
1 parent e691208 commit 8de308d
Show file tree
Hide file tree
Showing 120 changed files with 6,799 additions and 7,731 deletions.
25 changes: 25 additions & 0 deletions .changes/config-restructure-rfc-5.md
@@ -0,0 +1,25 @@
---
'tauri': 'major:breaking'
'tauri-utils': 'major:breaking'
'tauri-build': 'major:breaking'
'tauri-codegen': 'major:breaking'
'tauri-cli': 'major:breaking'
'@tauri-apps/cli': 'major:breaking'
---

Restructured Tauri config per [RFC#5](https://github.com/tauri-apps/rfcs/blob/f3e82a6b0c5390401e855850d47dc7b7d9afd684/texts/0005-tauri-config-restructure.md):

- Moved `package.productName`, `package.version` and `tauri.bundle.identifier` fields to the top-level.
- Removed `package` object.
- Renamed `tauri` object to `app`.
- Moved `tauri.bundle` object to the top-level.
- Renamed `build.distDir` field to `frontendDist`.
- Renamed `build.devPath` field to `devUrl` and will no longer accepts paths, it will only accept URLs.
- Moved `tauri.pattern` to `app.security.pattern`.
- Removed `tauri.bundle.updater` object, and its fields have been moved to the updater plugin under `plugins.updater` object.
- Moved `build.withGlobalTauri` to `app.withGlobalTauri`.
- Moved `tauri.bundle.dmg` object to `bundle.macOS.dmg`.
- Moved `tauri.bundle.deb` object to `bundle.linux.deb`.
- Moved `tauri.bundle.appimage` object to `bundle.linux.appimage`.
- Removed all license fields from each bundle configuration object and instead added `bundle.license` and `bundle.licenseFile`.
- Renamed `AppUrl` to `FrontendDist` and refactored its variants to be more explicit.
5 changes: 5 additions & 0 deletions .changes/tauri-bundle-settings-rfc-5.md
@@ -0,0 +1,5 @@
---
'tauri-bundler': 'major:breaking'
---

- Removed all license fields from `WixSettings`, `NsisSettings` and `MacOsSettings` and replaced with `license` and `license_file` fields in `BundlerSettings`.
17 changes: 6 additions & 11 deletions core/tauri-build/src/codegen/context.rs
Expand Up @@ -10,7 +10,7 @@ use std::{
path::PathBuf,
};
use tauri_codegen::{context_codegen, ContextData};
use tauri_utils::config::{AppUrl, WebviewUrl};
use tauri_utils::config::FrontendDist;

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

// rerun if changed
let app_url = if self.dev {
&config.build.dev_path
} else {
&config.build.dist_dir
};
match app_url {
Some(AppUrl::Url(WebviewUrl::App(p))) => {
match &config.build.frontend_dist {
Some(FrontendDist::Dist(p)) => {
println!("cargo:rerun-if-changed={}", config_parent.join(p).display());
}
Some(AppUrl::Files(files)) => {
Some(FrontendDist::Files(files)) => {
for path in files {
println!(
"cargo:rerun-if-changed={}",
Expand All @@ -101,13 +96,13 @@ impl CodegenContext {
}
_ => (),
}
for icon in &config.tauri.bundle.icon {
for icon in &config.bundle.icon {
println!(
"cargo:rerun-if-changed={}",
config_parent.join(icon).display()
);
}
if let Some(tray_icon) = config.tauri.tray_icon.as_ref().map(|t| &t.icon_path) {
if let Some(tray_icon) = config.app.tray_icon.as_ref().map(|t| &t.icon_path) {
println!(
"cargo:rerun-if-changed={}",
config_parent.join(tray_icon).display()
Expand Down
22 changes: 10 additions & 12 deletions core/tauri-build/src/lib.rs
Expand Up @@ -437,7 +437,7 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
}
let config: Config = serde_json::from_value(config)?;

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

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

#[allow(unused_mut, clippy::redundant_clone)]
let mut resources = config
.tauri
.bundle
.resources
.clone()
.unwrap_or_else(|| BundleResources::List(Vec::new()));
if target_triple.contains("windows") {
if let Some(fixed_webview2_runtime_path) =
match &config.tauri.bundle.windows.webview_fixed_runtime_path {
match &config.bundle.windows.webview_fixed_runtime_path {
Some(path) => Some(path),
None => match &config.tauri.bundle.windows.webview_install_mode {
None => match &config.bundle.windows.webview_install_mode {
WebviewInstallMode::FixedRuntime { path } => Some(path),
_ => None,
},
Expand All @@ -538,7 +537,7 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
}

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

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

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

if let Some(version_str) = &config.package.version {
if let Some(version_str) = &config.version {
if let Ok(v) = Version::parse(version_str) {
let version = v.major << 48 | v.minor << 32 | v.patch << 16;
res.set_version_info(VersionInfo::FILEVERSION, version);
res.set_version_info(VersionInfo::PRODUCTVERSION, version);
}
}

if let Some(product_name) = &config.package.product_name {
if let Some(product_name) = &config.product_name {
res.set("ProductName", product_name);
}

if let Some(short_description) = &config.tauri.bundle.short_description {
if let Some(short_description) = &config.bundle.short_description {
res.set("FileDescription", short_description);
}

if let Some(copyright) = &config.tauri.bundle.copyright {
if let Some(copyright) = &config.bundle.copyright {
res.set("LegalCopyright", copyright);
}

Expand Down
8 changes: 4 additions & 4 deletions core/tauri-build/src/manifest.rs
Expand Up @@ -4,7 +4,7 @@

use anyhow::{anyhow, Result};
use cargo_toml::{Dependency, Manifest};
use tauri_utils::config::{Config, PatternKind, TauriConfig};
use tauri_utils::config::{AppConfig, Config, PatternKind};

#[derive(Debug, Default, PartialEq, Eq)]
struct Diff {
Expand Down Expand Up @@ -34,7 +34,7 @@ pub fn check(config: &Config, manifest: &mut Manifest) -> Result<()> {
alias: None,
kind: DependencyKind::Build,
all_cli_managed_features: Some(vec!["isolation"]),
expected_features: match config.tauri.pattern {
expected_features: match config.app.security.pattern {
PatternKind::Isolation { .. } => vec!["isolation".to_string()],
_ => vec![],
},
Expand All @@ -44,13 +44,13 @@ pub fn check(config: &Config, manifest: &mut Manifest) -> Result<()> {
alias: None,
kind: DependencyKind::Normal,
all_cli_managed_features: Some(
TauriConfig::all_features()
AppConfig::all_features()
.into_iter()
.filter(|f| f != &"tray-icon")
.collect(),
),
expected_features: config
.tauri
.app
.features()
.into_iter()
.filter(|f| f != &"tray-icon")
Expand Down
59 changes: 24 additions & 35 deletions core/tauri-codegen/src/context.rs
Expand Up @@ -15,7 +15,7 @@ use tauri_utils::acl::capability::Capability;
use tauri_utils::acl::plugin::Manifest;
use tauri_utils::acl::resolved::Resolved;
use tauri_utils::assets::AssetKey;
use tauri_utils::config::{AppUrl, Config, PatternKind, WebviewUrl};
use tauri_utils::config::{Config, FrontendDist, PatternKind};
use tauri_utils::html::{
inject_nonce_token, parse as parse_html, serialize_node as serialize_html_node,
};
Expand Down Expand Up @@ -134,53 +134,43 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
.map(Target::from_triple)
.unwrap_or_else(|_| Target::current());

let mut options = AssetOptions::new(config.tauri.pattern.clone())
.freeze_prototype(config.tauri.security.freeze_prototype)
let mut options = AssetOptions::new(config.app.security.pattern.clone())
.freeze_prototype(config.app.security.freeze_prototype)
.dangerous_disable_asset_csp_modification(
config
.tauri
.app
.security
.dangerous_disable_asset_csp_modification
.clone(),
);
let csp = if dev {
config
.tauri
.app
.security
.dev_csp
.as_ref()
.or(config.tauri.security.csp.as_ref())
.or(config.app.security.csp.as_ref())
} else {
config.tauri.security.csp.as_ref()
config.app.security.csp.as_ref()
};
if csp.is_some() {
options = options.with_csp();
}

let app_url = if dev {
&config.build.dev_path
} else {
&config.build.dist_dir
};

let assets = match app_url {
let assets = match &config.build.frontend_dist {
Some(url) => match url {
AppUrl::Url(url) => match url {
WebviewUrl::External(_) | WebviewUrl::CustomProtocol(_) => Default::default(),
WebviewUrl::App(path) => {
let assets_path = config_parent.join(path);
if !assets_path.exists() {
panic!(
"The `{}` configuration is set to `{:?}` but this path doesn't exist",
if dev { "devPath" } else { "distDir" },
path
)
}
EmbeddedAssets::new(assets_path, &options, map_core_assets(&options, target))?
FrontendDist::Url(_url) => Default::default(),
FrontendDist::Dist(path) => {
let assets_path = config_parent.join(path);
if !assets_path.exists() {
panic!(
"The `frontendDist` configuration is set to `{:?}` but this path doesn't exist",
path
)
}
_ => unimplemented!(),
},
AppUrl::Files(files) => EmbeddedAssets::new(
EmbeddedAssets::new(assets_path, &options, map_core_assets(&options, target))?
}
FrontendDist::Files(files) => EmbeddedAssets::new(
files
.iter()
.map(|p| config_parent.join(p))
Expand Down Expand Up @@ -257,12 +247,12 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
quote!(::std::option::Option::None)
};

let package_name = if let Some(product_name) = &config.package.product_name {
let package_name = if let Some(product_name) = &config.product_name {
quote!(#product_name.to_string())
} else {
quote!(env!("CARGO_PKG_NAME").to_string())
};
let package_version = if let Some(version) = &config.package.version {
let package_version = if let Some(version) = &config.version {
semver::Version::from_str(version)?;
quote!(#version.to_string())
} else {
Expand All @@ -279,7 +269,7 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
);

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

if let Some(plist) = info_plist.as_dictionary_mut() {
if let Some(product_name) = &config.package.product_name {
if let Some(product_name) = &config.product_name {
plist.insert("CFBundleName".into(), product_name.clone().into());
}
if let Some(version) = &config.package.version {
if let Some(version) = &config.version {
plist.insert("CFBundleShortVersionString".into(), version.clone().into());
}
let format =
Expand Down Expand Up @@ -533,7 +523,6 @@ fn find_icon<F: Fn(&&String) -> bool>(
default: &str,
) -> PathBuf {
let icon_path = config
.tauri
.bundle
.icon
.iter()
Expand Down

0 comments on commit 8de308d

Please sign in to comment.