diff --git a/.changes/fix-capabilities-rerun-absolute-path.md b/.changes/fix-capabilities-rerun-absolute-path.md new file mode 100644 index 000000000000..2921b74b26aa --- /dev/null +++ b/.changes/fix-capabilities-rerun-absolute-path.md @@ -0,0 +1,5 @@ +--- +'tauri-build': 'patch:bug' +--- + +Emit an absolute path for the capabilities directory `cargo:rerun-if-changed`. Cargo resolves a relative watch path against the package owning the build script, while the capabilities glob is resolved against the process working directory, so callers that change the current directory before `try_build`/`try_build_context` ended up watching a non-existent directory — which is always dirty and re-ran the build script (and recompiled everything downstream) on every build. diff --git a/crates/tauri-build/src/acl.rs b/crates/tauri-build/src/acl.rs index 16f529d6a77b..5fcbe682dc9b 100644 --- a/crates/tauri-build/src/acl.rs +++ b/crates/tauri-build/src/acl.rs @@ -424,7 +424,19 @@ pub fn build(out_dir: &Path, target: Target, attributes: &Attributes) -> super:: let capabilities = if let Some(pattern) = attributes.capabilities_path_pattern { tauri_utils::acl::build::parse_capabilities(pattern)? } else { - println!("cargo:rerun-if-changed=capabilities"); + // Emit an absolute watch path: cargo resolves a relative + // `rerun-if-changed` against the package that owns the build script, while + // the glob below is resolved against the process working directory. + // Callers that `set_current_dir` before `try_build[_context]` (for example + // a crate generating a context byte-identical to the app's) would + // otherwise watch a `/capabilities` that usually does + // not exist — and a missing watched path is dirty on every fingerprint + // check, re-running the build script and recompiling the whole downstream + // chain on every build. + let capabilities_dir = std::env::current_dir() + .context("resolve current dir for capabilities watch path")? + .join("capabilities"); + println!("cargo:rerun-if-changed={}", capabilities_dir.display()); tauri_utils::acl::build::parse_capabilities("./capabilities/**/*")? }; validate_capabilities(&acl_manifests, &capabilities)?;