diff --git a/.changes/rerun-if-platform-conf.changes.md b/.changes/rerun-if-platform-conf.changes.md new file mode 100644 index 000000000..6446daf0f --- /dev/null +++ b/.changes/rerun-if-platform-conf.changes.md @@ -0,0 +1,7 @@ +--- +"tauri-utils": patch:bug +"tauri-build": patch:bug +"tauri-codegen": patch:bug +--- + +Rerun build script if the platform-specific configuration file changes. diff --git a/Cargo.lock b/Cargo.lock index bae344958..3884e115a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5867,6 +5867,16 @@ dependencies = [ "windows-registry", ] +[[package]] +name = "resources" +version = "0.1.0" +dependencies = [ + "serde", + "serde_json", + "tauri", + "tauri-build", +] + [[package]] name = "restart" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index ab37c9898..1d0c790f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,7 @@ members = [ # examples "examples/file-associations/src-tauri", "examples/api/src-tauri", + "examples/resources/src-tauri", "examples/api/src-tauri/tauri-plugin-sample", ] resolver = "2" diff --git a/crates/tauri-build/src/lib.rs b/crates/tauri-build/src/lib.rs index 9919ad648..af0f2af5a 100644 --- a/crates/tauri-build/src/lib.rs +++ b/crates/tauri-build/src/lib.rs @@ -473,10 +473,12 @@ pub fn try_build(attributes: Attributes) -> Result<()> { let target_triple = env::var("TARGET").unwrap(); let target = tauri_utils::platform::Target::from_triple(&target_triple); - let mut config = serde_json::from_value(tauri_utils::config::parse::read_from( - target, - env::current_dir().unwrap(), - )?)?; + let (config, merged_config_path) = + tauri_utils::config::parse::read_from(target, env::current_dir().unwrap())?; + if let Some(merged_config_path) = merged_config_path { + println!("cargo:rerun-if-changed={}", merged_config_path.display()); + } + let mut config = serde_json::from_value(config)?; if let Ok(env) = env::var("TAURI_CONFIG") { let merge_config: serde_json::Value = serde_json::from_str(&env)?; json_patch::merge(&mut config, &merge_config); diff --git a/crates/tauri-codegen/src/lib.rs b/crates/tauri-codegen/src/lib.rs index 93798d803..62af509b5 100644 --- a/crates/tauri-codegen/src/lib.rs +++ b/crates/tauri-codegen/src/lib.rs @@ -79,10 +79,8 @@ pub fn get_config(path: &Path) -> Result<(Config, PathBuf), CodegenConfigError> // it is impossible for the content of two separate configs to get mixed up. The chances are // already unlikely unless the developer goes out of their way to run the cli on a different // project than the target crate. - let mut config = serde_json::from_value(tauri_utils::config::parse::read_from( - target, - parent.clone(), - )?)?; + let mut config = + serde_json::from_value(tauri_utils::config::parse::read_from(target, parent.clone())?.0)?; if let Ok(env) = std::env::var("TAURI_CONFIG") { let merge_config: serde_json::Value = diff --git a/crates/tauri-utils/src/config/parse.rs b/crates/tauri-utils/src/config/parse.rs index 39431a7b0..a8429ddd3 100644 --- a/crates/tauri-utils/src/config/parse.rs +++ b/crates/tauri-utils/src/config/parse.rs @@ -174,13 +174,20 @@ pub fn is_configuration_file(target: Target, path: &Path) -> bool { /// - `tauri.ios.conf.json[5]` or `Tauri.ios.toml` on iOS /// Merging the configurations using [JSON Merge Patch (RFC 7396)]. /// +/// Returns the raw configuration and the platform config path, if any. +/// /// [JSON Merge Patch (RFC 7396)]: https://datatracker.ietf.org/doc/html/rfc7396. -pub fn read_from(target: Target, root_dir: PathBuf) -> Result { +pub fn read_from( + target: Target, + root_dir: PathBuf, +) -> Result<(Value, Option), ConfigError> { let mut config: Value = parse_value(target, root_dir.join("tauri.conf.json"))?.0; - if let Some((platform_config, _)) = read_platform(target, root_dir)? { + if let Some((platform_config, path)) = read_platform(target, root_dir)? { merge(&mut config, &platform_config); + Ok((config, Some(path))) + } else { + Ok((config, None)) } - Ok(config) } /// Reads the platform-specific configuration file from the given root directory if it exists.