From 6907989cec8cab807d8207f6cc05fe4d210dedee Mon Sep 17 00:00:00 2001 From: vycdev Date: Thu, 19 Nov 2026 23:23:22 +0200 Subject: [PATCH 1/3] Embed the Windows app manifest into Rust test executables tauri-build links its app manifest into binaries only, so on Windows the lib unit test executable starts without the Common Controls v6 dependency and dies with STATUS_ENTRYPOINT_NOT_FOUND before any test runs. On MSVC, hand the same manifest to the linker for every target instead, without the default UAC section, so the app's embedded manifest keeps its content. Co-Authored-By: Claude Opus 5.5 --- src-tauri/build.rs | 21 ++++++++++++++++++++- src-tauri/windows/app-manifest.xml | 14 ++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src-tauri/windows/app-manifest.xml diff --git a/src-tauri/build.rs b/src-tauri/build.rs index d860e1e6..e9e50718 100644 --- a/src-tauri/build.rs +++ b/src-tauri/build.rs @@ -1,3 +1,22 @@ fn main() { - tauri_build::build() + let mut attributes = tauri_build::Attributes::new(); + // tauri-build embeds its Windows app manifest only into binaries, but the unit test + // executable links the same Tauri and dialog code. Without the manifest's Common Controls v6 + // dependency it fails to start with STATUS_ENTRYPOINT_NOT_FOUND. So hand the same manifest + // (copied from tauri-build) to the MSVC linker, which embeds it into every target. + let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default(); + let target_env = std::env::var("CARGO_CFG_TARGET_ENV").unwrap_or_default(); + if target_os == "windows" && target_env == "msvc" { + attributes = attributes + .windows_attributes(tauri_build::WindowsAttributes::new_without_app_manifest()); + let manifest = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) + .join("windows") + .join("app-manifest.xml"); + println!("cargo:rerun-if-changed={}", manifest.display()); + println!("cargo:rustc-link-arg=/MANIFEST:EMBED"); + println!("cargo:rustc-link-arg=/MANIFESTINPUT:{}", manifest.display()); + // Without this the linker adds a UAC section that tauri-build's manifest does not have. + println!("cargo:rustc-link-arg=/MANIFESTUAC:NO"); + } + tauri_build::try_build(attributes).expect("failed to run tauri-build"); } diff --git a/src-tauri/windows/app-manifest.xml b/src-tauri/windows/app-manifest.xml new file mode 100644 index 00000000..2d510ed3 --- /dev/null +++ b/src-tauri/windows/app-manifest.xml @@ -0,0 +1,14 @@ + + + + + + + From a95afc67978c198ff1150c48cc4df6e83dec1d54 Mon Sep 17 00:00:00 2001 From: vycdev Date: Thu, 19 Nov 2026 23:40:34 +0200 Subject: [PATCH 2/3] Embed the manifest with tauri-winres' bytes and fix the Windows app-data check The linker-generated manifest dropped tauri-winres' whitespace, so the app's embedded manifest bytes changed. Compile the same resource script tauri-winres writes, but for every target, so the binary's manifest is byte-identical. Running the safe save tests on Windows also showed the app-data guard comparing a missing folder in plain form against an existing one in `\\?\` form; canonicalize the deepest existing folder on both sides instead. Co-Authored-By: Claude Opus 5.5 --- src-tauri/Cargo.lock | 1 + src-tauri/Cargo.toml | 1 + src-tauri/build.rs | 34 ++++++++++++++++++++++------------ src-tauri/src/safe_save.rs | 12 ++++++++++-- 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index de77aa71..6c8ee8b4 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2128,6 +2128,7 @@ dependencies = [ name = "kromacut" version = "4.2.0" dependencies = [ + "embed-resource", "gio", "log", "percent-encoding", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 3f3555fe..b10313cd 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -16,6 +16,7 @@ crate-type = ["staticlib", "cdylib", "rlib"] [build-dependencies] tauri-build = { version = "2.6.0", features = [] } +embed-resource = "3" [dependencies] serde_json = "1.0" diff --git a/src-tauri/build.rs b/src-tauri/build.rs index e9e50718..444814ab 100644 --- a/src-tauri/build.rs +++ b/src-tauri/build.rs @@ -1,22 +1,32 @@ fn main() { let mut attributes = tauri_build::Attributes::new(); - // tauri-build embeds its Windows app manifest only into binaries, but the unit test - // executable links the same Tauri and dialog code. Without the manifest's Common Controls v6 - // dependency it fails to start with STATUS_ENTRYPOINT_NOT_FOUND. So hand the same manifest - // (copied from tauri-build) to the MSVC linker, which embeds it into every target. + // tauri-build links its Windows app manifest into binaries only, but the unit test executable + // links the same Tauri and dialog code. Without the manifest's Common Controls v6 dependency it + // fails to start with STATUS_ENTRYPOINT_NOT_FOUND. So embed the manifest ourselves, in every + // target. let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default(); let target_env = std::env::var("CARGO_CFG_TARGET_ENV").unwrap_or_default(); if target_os == "windows" && target_env == "msvc" { attributes = attributes .windows_attributes(tauri_build::WindowsAttributes::new_without_app_manifest()); - let manifest = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) - .join("windows") - .join("app-manifest.xml"); - println!("cargo:rerun-if-changed={}", manifest.display()); - println!("cargo:rustc-link-arg=/MANIFEST:EMBED"); - println!("cargo:rustc-link-arg=/MANIFESTINPUT:{}", manifest.display()); - // Without this the linker adds a UAC section that tauri-build's manifest does not have. - println!("cargo:rustc-link-arg=/MANIFESTUAC:NO"); + embed_manifest_in_every_target(); } tauri_build::try_build(attributes).expect("failed to run tauri-build"); } + +/// Writes tauri-build's default manifest (copied to `windows/app-manifest.xml`) into a resource +/// script exactly as tauri-winres does, so the app's embedded manifest bytes do not change, then +/// links it into tests and libraries as well as binaries. +fn embed_manifest_in_every_target() { + let manifest = include_str!("windows/app-manifest.xml"); + let mut script = String::from("#pragma code_page(65001)\n1 24\n{\n"); + for line in manifest.lines() { + script.push_str(&format!("\" {} \"\n", line.trim().replace('"', "\"\""))); + } + script.push_str("}\n"); + let path = std::path::Path::new(&std::env::var("OUT_DIR").unwrap()).join("app-manifest.rc"); + std::fs::write(&path, script).expect("failed to write the manifest resource script"); + embed_resource::compile_for_everything(&path, embed_resource::NONE) + .manifest_required() + .expect("failed to compile the manifest resource"); +} diff --git a/src-tauri/src/safe_save.rs b/src-tauri/src/safe_save.rs index 5e9ac333..cfcffab4 100644 --- a/src-tauri/src/safe_save.rs +++ b/src-tauri/src/safe_save.rs @@ -87,8 +87,16 @@ fn commit_temp(temp: &Path, destination: &Path) -> Result<(), String> { /// Whether the path is in the app's local data folder, which holds the webview data that the fs /// plugin denies the webview by default. fn is_in_app_local_data(app: &AppHandle, path: &Path) -> bool { - let canonical = - |path: &Path| std::fs::canonicalize(path).unwrap_or_else(|_| path.to_path_buf()); + // Canonicalize the deepest folder that exists, so both sides compare in the same form even + // when one is missing (on Windows, canonical paths gain a `\\?\` prefix). + let canonical = |path: &Path| { + path.ancestors() + .find_map(|ancestor| { + let rest = path.strip_prefix(ancestor).ok()?; + Some(std::fs::canonicalize(ancestor).ok()?.join(rest)) + }) + .unwrap_or_else(|| path.to_path_buf()) + }; match (app.path().app_local_data_dir(), path.parent()) { (Ok(data), Some(directory)) => canonical(directory).starts_with(canonical(&data)), _ => false, From 4b0a8b86083bbc6cf7c0f8be397845d9a3a3fb40 Mon Sep 17 00:00:00 2001 From: vycdev Date: Thu, 19 Nov 2026 23:56:44 +0200 Subject: [PATCH 3/3] Note where the Windows manifest copy comes from Co-Authored-By: Claude Opus 5.5 --- src-tauri/build.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src-tauri/build.rs b/src-tauri/build.rs index 444814ab..c083ea5f 100644 --- a/src-tauri/build.rs +++ b/src-tauri/build.rs @@ -14,9 +14,11 @@ fn main() { tauri_build::try_build(attributes).expect("failed to run tauri-build"); } -/// Writes tauri-build's default manifest (copied to `windows/app-manifest.xml`) into a resource -/// script exactly as tauri-winres does, so the app's embedded manifest bytes do not change, then -/// links it into tests and libraries as well as binaries. +/// Writes tauri-build's default manifest into a resource script in tauri-winres' format, so the +/// app's embedded manifest bytes do not change, then links it into tests and libraries as well as +/// binaries. `windows/app-manifest.xml` is a verbatim copy of tauri-build 2.6.3's +/// `windows-app-manifest.xml`; re-diff it when upgrading tauri-build. Only `"` is escaped, the +/// one character tauri-winres escapes that the manifest contains. fn embed_manifest_in_every_target() { let manifest = include_str!("windows/app-manifest.xml"); let mut script = String::from("#pragma code_page(65001)\n1 24\n{\n");