From 778ee4aa3766f9afa71875e52629bd1630d4ee8d Mon Sep 17 00:00:00 2001 From: amrbashir Date: Sat, 24 Aug 2024 09:59:18 +0300 Subject: [PATCH 1/4] fix(core): embed app manifest on Windows direclty See https://github.com/tauri-apps/tauri/pull/10743#issuecomment-2307055443 and https://github.com/tauri-apps/tauri/pull/4383#issuecomment-1212221864 --- .../tauri-build-windows-app-manifest-path.md | 6 ++ core/tauri-build/src/lib.rs | 93 +++++++++++++++++-- ...-manifest.xml => windows-app-manifest.xml} | 0 core/tauri/build.rs | 8 +- 4 files changed, 95 insertions(+), 12 deletions(-) create mode 100644 .changes/tauri-build-windows-app-manifest-path.md rename core/tauri-build/src/{window-app-manifest.xml => windows-app-manifest.xml} (100%) diff --git a/.changes/tauri-build-windows-app-manifest-path.md b/.changes/tauri-build-windows-app-manifest-path.md new file mode 100644 index 00000000000..3d1c4ef9c68 --- /dev/null +++ b/.changes/tauri-build-windows-app-manifest-path.md @@ -0,0 +1,6 @@ +--- +"tauri-build": "patch" +--- + +Add `WindowsAttributes::app_manifest_path` to specify a path to a Windows app manifest file. + diff --git a/core/tauri-build/src/lib.rs b/core/tauri-build/src/lib.rs index 4a5cf663121..969d297c41a 100644 --- a/core/tauri-build/src/lib.rs +++ b/core/tauri-build/src/lib.rs @@ -230,7 +230,7 @@ pub struct WindowsAttributes { /// /// Defaults to: /// ```text - #[doc = include_str!("window-app-manifest.xml")] + #[doc = include_str!("windows-app-manifest.xml")] /// ``` /// /// ## Warning @@ -253,6 +253,11 @@ pub struct WindowsAttributes { /// /// [application manifest]: https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests app_manifest: Option, + + /// Path to an [application manifest] file to be included with the application on Windows. + /// + /// [application manifest]: https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests + app_manifest_path: Option, } impl WindowsAttributes { @@ -273,9 +278,11 @@ impl WindowsAttributes { /// Sets the [application manifest] to be included with the application on Windows. /// + /// This options conflicts with [WindowsAttributes::app_manifest_path] + /// /// Defaults to: /// ```text - #[doc = include_str!("window-app-manifest.xml")] + #[doc = include_str!("windows-app-manifest.xml")] /// ``` /// /// ## Warning @@ -327,6 +334,52 @@ impl WindowsAttributes { self.app_manifest = Some(manifest.as_ref().to_string()); self } + + /// Path to an [application manifest] file to be included with the application on Windows. + /// + /// This options conflicts with [WindowsAttributes::app_manifest] + /// + /// Defaults to: + /// ```text + #[doc = include_str!("windows-app-manifest.xml")] + /// ``` + /// + /// ## Warning + /// + /// if you are using tauri's dialog APIs, you need to specify a dependency on Common Control v6 by adding the following to your custom manifest: + /// ```text + /// + /// + /// + /// + /// + /// ``` + /// + /// # Example + /// + /// The following manifest will brand the exe as requesting administrator privileges. + /// Thus, every time it is executed, a Windows UAC dialog will appear. + /// + /// ```rust,no_run + /// let mut windows = tauri_build::WindowsAttributes::new(); + /// windows = windows.app_manifest_file("./path/to/app-manifest.xml"); + /// let attrs = tauri_build::Attributes::new().windows_attributes(windows); + /// tauri_build::try_build(attrs).expect("failed to run build script"); + /// ``` + /// + /// [application manifest]: https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests + #[must_use] + pub fn app_manifest_path>(mut self, file: P) -> Self { + self.app_manifest_path = Some(file.as_ref().to_path_buf()); + self + } } /// The attributes used on the build. @@ -626,6 +679,36 @@ pub fn try_build(attributes: Attributes) -> Result<()> { use semver::Version; use tauri_winres::{VersionInfo, WindowsResource}; + // Embed the Windows application manifest file directly instead of using a resource file. + // See https://github.com/tauri-apps/tauri/pull/10743#issuecomment-2307055443 + // and https://github.com/tauri-apps/tauri/pull/4383#issuecomment-1212221864 + let manifest_path = match ( + attributes.windows_attributes.app_manifest, + attributes.windows_attributes.app_manifest_path, + ) { + (Some(manifest), None) => { + let path = out_dir.join("windows-app-manifest.xml"); + std::fs::write(&path, manifest).context("failed to write windows-app-manifest.xml")?; + path + } + (None, None) => { + let path = out_dir.join("windows-app-manifest.xml"); + let manifest = include_str!("windows-app-manifest.xml"); + std::fs::write(&path, manifest).context("failed to write windows-app-manifest.xml")?; + path + } + (None, Some(manifest_path)) => manifest_path, + (Some(_), Some(_)) => { + unreachable!("app_manifest and app_manifest_file can't be set at the same time") + } + }; + + println!("cargo:rustc-link-arg=/MANIFEST:EMBED"); + println!( + "cargo:rustc-link-arg=/MANIFESTINPUT:{}", + manifest_path.display() + ); + fn find_icon bool>(config: &Config, predicate: F, default: &str) -> PathBuf { let icon_path = config .bundle @@ -644,12 +727,6 @@ pub fn try_build(attributes: Attributes) -> Result<()> { let mut res = WindowsResource::new(); - if let Some(manifest) = attributes.windows_attributes.app_manifest { - res.set_manifest(&manifest); - } else { - res.set_manifest(include_str!("window-app-manifest.xml")); - } - 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; diff --git a/core/tauri-build/src/window-app-manifest.xml b/core/tauri-build/src/windows-app-manifest.xml similarity index 100% rename from core/tauri-build/src/window-app-manifest.xml rename to core/tauri-build/src/windows-app-manifest.xml diff --git a/core/tauri/build.rs b/core/tauri/build.rs index 84dd0291d3a..882555fd649 100644 --- a/core/tauri/build.rs +++ b/core/tauri/build.rs @@ -249,12 +249,12 @@ fn main() { ) .expect("failed to write checked_features file"); - // workaround needed to prevent `STATUS_ENTRYPOINT_NOT_FOUND` error + // workaround needed to prevent `STATUS_ENTRYPOINT_NOT_FOUND` error on tests // see https://github.com/tauri-apps/tauri/pull/4383#issuecomment-1212221864 let target_env = std::env::var("CARGO_CFG_TARGET_ENV"); let is_tauri_workspace = std::env::var("__TAURI_WORKSPACE__").map_or(false, |v| v == "true"); if is_tauri_workspace && target_os == "windows" && Ok("msvc") == target_env.as_deref() { - add_manifest(); + embed_windows_manifest_for_tests(); } if target_os == "android" { @@ -394,8 +394,8 @@ permissions = [{default_permissions}] } } -fn add_manifest() { - static WINDOWS_MANIFEST_FILE: &str = "window-app-manifest.xml"; +fn embed_windows_manifest_for_tests() { + const WINDOWS_MANIFEST_FILE: &str = "windows-app-manifest.xml"; let manifest = std::env::current_dir() .unwrap() From a80b2125c6cc03e6ce0eb53c4f4cd8e4b073eaac Mon Sep 17 00:00:00 2001 From: amrbashir Date: Sat, 24 Aug 2024 10:00:20 +0300 Subject: [PATCH 2/4] change tag --- .changes/tauri-build-windows-app-manifest-path.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changes/tauri-build-windows-app-manifest-path.md b/.changes/tauri-build-windows-app-manifest-path.md index 3d1c4ef9c68..357361246b1 100644 --- a/.changes/tauri-build-windows-app-manifest-path.md +++ b/.changes/tauri-build-windows-app-manifest-path.md @@ -1,5 +1,5 @@ --- -"tauri-build": "patch" +"tauri-build": "patch:feat" --- Add `WindowsAttributes::app_manifest_path` to specify a path to a Windows app manifest file. From 503e26c5208c71780ce599d701930faf30ef2714 Mon Sep 17 00:00:00 2001 From: amrbashir Date: Sat, 24 Aug 2024 10:02:51 +0300 Subject: [PATCH 3/4] fix doctest --- core/tauri-build/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/tauri-build/src/lib.rs b/core/tauri-build/src/lib.rs index 969d297c41a..2d370cc31d6 100644 --- a/core/tauri-build/src/lib.rs +++ b/core/tauri-build/src/lib.rs @@ -369,7 +369,7 @@ impl WindowsAttributes { /// /// ```rust,no_run /// let mut windows = tauri_build::WindowsAttributes::new(); - /// windows = windows.app_manifest_file("./path/to/app-manifest.xml"); + /// windows = windows.app_manifest_path("./path/to/app-manifest.xml"); /// let attrs = tauri_build::Attributes::new().windows_attributes(windows); /// tauri_build::try_build(attrs).expect("failed to run build script"); /// ``` From eea3989a988fc6c551bf5dbdad70d71d40a97ef3 Mon Sep 17 00:00:00 2001 From: amrbashir Date: Sat, 24 Aug 2024 10:07:28 +0300 Subject: [PATCH 4/4] fix js audit --- package.json | 8 +++----- pnpm-lock.yaml | 26 +++++++++++++------------- tooling/api/package.json | 1 - 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index e60835a9140..8ea2486ec45 100644 --- a/package.json +++ b/package.json @@ -17,14 +17,12 @@ "ts:check": "pnpm run -r ts:check" }, "devDependencies": { - "prettier": "^3.3.2" + "prettier": "^3.3.3" }, "packageManager": "pnpm@9.7.1", "pnpm": { - "auditConfig": { - "ignoreCves": [ - "CVE-2024-4067" - ] + "overrides": { + "micromatch@<4.0.8": ">=4.0.8" } } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2071db51c67..69ddc13c8e9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,12 +4,15 @@ settings: autoInstallPeers: true excludeLinksFromLockfile: false +overrides: + micromatch@<4.0.8: '>=4.0.8' + importers: .: devDependencies: prettier: - specifier: ^3.3.2 + specifier: ^3.3.3 version: 3.3.3 examples/api: @@ -79,9 +82,6 @@ importers: globals: specifier: ^15.4.0 version: 15.9.0 - prettier: - specifier: 3.3.3 - version: 3.3.3 rollup: specifier: 4.21.0 version: 4.21.0 @@ -2060,8 +2060,8 @@ packages: resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==} engines: {node: '>= 8'} - micromatch@4.0.7: - resolution: {integrity: sha512-LPP/3KorzCwBxfeUuZmaR6bG2kdeHSbe0P2tY3FLRU4vYrjYz5hI4QZwV0njUx3jeuKe67YukQ1LSPZBKDqO/Q==} + micromatch@4.0.8: + resolution: {integrity: sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==} engines: {node: '>=8.6'} mimic-fn@2.1.0: @@ -3138,7 +3138,7 @@ snapshots: jest-util: 29.7.0 jest-validate: 29.7.0 jest-watcher: 29.7.0 - micromatch: 4.0.7 + micromatch: 4.0.8 pretty-format: 29.7.0 slash: 3.0.0 strip-ansi: 6.0.1 @@ -3249,7 +3249,7 @@ snapshots: jest-haste-map: 29.7.0 jest-regex-util: 29.6.3 jest-util: 29.7.0 - micromatch: 4.0.7 + micromatch: 4.0.8 pirates: 4.0.6 slash: 3.0.0 write-file-atomic: 4.0.2 @@ -4220,7 +4220,7 @@ snapshots: '@nodelib/fs.walk': 1.2.8 glob-parent: 5.1.2 merge2: 1.4.1 - micromatch: 4.0.7 + micromatch: 4.0.8 fast-json-stable-stringify@2.1.0: {} @@ -4516,7 +4516,7 @@ snapshots: jest-runner: 29.7.0 jest-util: 29.7.0 jest-validate: 29.7.0 - micromatch: 4.0.7 + micromatch: 4.0.8 parse-json: 5.2.0 pretty-format: 29.7.0 slash: 3.0.0 @@ -4568,7 +4568,7 @@ snapshots: jest-regex-util: 29.6.3 jest-util: 29.7.0 jest-worker: 29.7.0 - micromatch: 4.0.7 + micromatch: 4.0.8 walker: 1.0.8 optionalDependencies: fsevents: 2.3.3 @@ -4592,7 +4592,7 @@ snapshots: '@types/stack-utils': 2.0.3 chalk: 4.1.2 graceful-fs: 4.2.11 - micromatch: 4.0.7 + micromatch: 4.0.8 pretty-format: 29.7.0 slash: 3.0.0 stack-utils: 2.0.6 @@ -4851,7 +4851,7 @@ snapshots: merge2@1.4.1: {} - micromatch@4.0.7: + micromatch@4.0.8: dependencies: braces: 3.0.3 picomatch: 2.3.1 diff --git a/tooling/api/package.json b/tooling/api/package.json index 005ad019124..593c01ee22c 100644 --- a/tooling/api/package.json +++ b/tooling/api/package.json @@ -54,7 +54,6 @@ "eslint-plugin-security": "3.0.1", "fast-glob": "3.3.2", "globals": "^15.4.0", - "prettier": "3.3.3", "rollup": "4.21.0", "tslib": "^2.6.3", "typescript": "^5.4.5",