Skip to content

Commit 1efa5e7

Browse files
authored
fix(core): rerun build script if platform config changes, closes #10963 (#11099)
1 parent 8f3f010 commit 1efa5e7

6 files changed

Lines changed: 36 additions & 11 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri-utils": patch:bug
3+
"tauri-build": patch:bug
4+
"tauri-codegen": patch:bug
5+
---
6+
7+
Rerun build script if the platform-specific configuration file changes.

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ members = [
3131
# examples
3232
"examples/file-associations/src-tauri",
3333
"examples/api/src-tauri",
34+
"examples/resources/src-tauri",
3435
"examples/api/src-tauri/tauri-plugin-sample",
3536
]
3637
resolver = "2"

crates/tauri-build/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,10 +473,12 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
473473
let target_triple = env::var("TARGET").unwrap();
474474
let target = tauri_utils::platform::Target::from_triple(&target_triple);
475475

476-
let mut config = serde_json::from_value(tauri_utils::config::parse::read_from(
477-
target,
478-
env::current_dir().unwrap(),
479-
)?)?;
476+
let (config, merged_config_path) =
477+
tauri_utils::config::parse::read_from(target, env::current_dir().unwrap())?;
478+
if let Some(merged_config_path) = merged_config_path {
479+
println!("cargo:rerun-if-changed={}", merged_config_path.display());
480+
}
481+
let mut config = serde_json::from_value(config)?;
480482
if let Ok(env) = env::var("TAURI_CONFIG") {
481483
let merge_config: serde_json::Value = serde_json::from_str(&env)?;
482484
json_patch::merge(&mut config, &merge_config);

crates/tauri-codegen/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,8 @@ pub fn get_config(path: &Path) -> Result<(Config, PathBuf), CodegenConfigError>
7979
// it is impossible for the content of two separate configs to get mixed up. The chances are
8080
// already unlikely unless the developer goes out of their way to run the cli on a different
8181
// project than the target crate.
82-
let mut config = serde_json::from_value(tauri_utils::config::parse::read_from(
83-
target,
84-
parent.clone(),
85-
)?)?;
82+
let mut config =
83+
serde_json::from_value(tauri_utils::config::parse::read_from(target, parent.clone())?.0)?;
8684

8785
if let Ok(env) = std::env::var("TAURI_CONFIG") {
8886
let merge_config: serde_json::Value =

crates/tauri-utils/src/config/parse.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,20 @@ pub fn is_configuration_file(target: Target, path: &Path) -> bool {
174174
/// - `tauri.ios.conf.json[5]` or `Tauri.ios.toml` on iOS
175175
/// Merging the configurations using [JSON Merge Patch (RFC 7396)].
176176
///
177+
/// Returns the raw configuration and the platform config path, if any.
178+
///
177179
/// [JSON Merge Patch (RFC 7396)]: https://datatracker.ietf.org/doc/html/rfc7396.
178-
pub fn read_from(target: Target, root_dir: PathBuf) -> Result<Value, ConfigError> {
180+
pub fn read_from(
181+
target: Target,
182+
root_dir: PathBuf,
183+
) -> Result<(Value, Option<PathBuf>), ConfigError> {
179184
let mut config: Value = parse_value(target, root_dir.join("tauri.conf.json"))?.0;
180-
if let Some((platform_config, _)) = read_platform(target, root_dir)? {
185+
if let Some((platform_config, path)) = read_platform(target, root_dir)? {
181186
merge(&mut config, &platform_config);
187+
Ok((config, Some(path)))
188+
} else {
189+
Ok((config, None))
182190
}
183-
Ok(config)
184191
}
185192

186193
/// Reads the platform-specific configuration file from the given root directory if it exists.

0 commit comments

Comments
 (0)