mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-17 01:17:59 +00:00
Embedded the Windows app manifest into the Rust test programs (#1071)
This commit is contained in:
1 parent
940d214429
commit
2b7d03f3c8
2 files changed
+59
-1
No files matched your search
+40
-1
@@ -1,7 +1,24 @@
|
||||
use std::path::{PathBuf};
|
||||
|
||||
fn main() {
|
||||
tauri_build::build();
|
||||
//
|
||||
// On Windows, the dialogs need version 6 of the common controls, which
|
||||
// the application manifest requests. Tauri's build helper embeds its
|
||||
// manifest into the app only, not into the test programs, and Windows
|
||||
// stops a test program without it before the first test runs. Hence,
|
||||
// we embed the manifest ourselves wherever MSVC links, and Tauri's
|
||||
// build helper must not add its own one as well:
|
||||
//
|
||||
let windows_attributes = if embed_windows_manifest() {
|
||||
tauri_build::WindowsAttributes::new_without_app_manifest()
|
||||
} else {
|
||||
tauri_build::WindowsAttributes::new()
|
||||
};
|
||||
|
||||
let tauri_attributes = tauri_build::Attributes::new().windows_attributes(windows_attributes);
|
||||
if let Err(error) = tauri_build::try_build(tauri_attributes) {
|
||||
panic!("Tauri's build helper failed: {error:#}");
|
||||
}
|
||||
|
||||
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
|
||||
println!("cargo:rustc-env=OUT_DIR={}", out_dir.to_str().unwrap());
|
||||
@@ -44,6 +61,28 @@ fn main() {
|
||||
update_tauri_conf("tauri.conf.json", version);
|
||||
}
|
||||
|
||||
/// Lets the linker embed our Windows application manifest into every program
|
||||
/// it links: the app as well as the test programs. Tauri's build helper adds
|
||||
/// its manifest only to the app. Tauri works around the same problem for its
|
||||
/// own tests, see https://github.com/tauri-apps/tauri/pull/4383#issuecomment-1212221864
|
||||
///
|
||||
/// Returns false for all targets other than Windows with MSVC, where Tauri's
|
||||
/// build helper keeps embedding its manifest. We read the target from Cargo,
|
||||
/// since it differs from the building machine when we cross-compile.
|
||||
fn embed_windows_manifest() -> bool {
|
||||
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
|
||||
let target_env = std::env::var("CARGO_CFG_TARGET_ENV").unwrap();
|
||||
if target_os != "windows" || target_env != "msvc" {
|
||||
return false;
|
||||
}
|
||||
|
||||
let manifest = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()).join("windows-app-manifest.xml");
|
||||
println!("cargo:rerun-if-changed={}", manifest.to_str().unwrap());
|
||||
println!("cargo:rustc-link-arg=/MANIFEST:EMBED");
|
||||
println!("cargo:rustc-link-arg=/MANIFESTINPUT:{}", manifest.to_str().unwrap());
|
||||
true
|
||||
}
|
||||
|
||||
fn update_cargo_toml(cargo_path: &str, version: &str) {
|
||||
let cargo_toml = std::fs::read_to_string(cargo_path).unwrap();
|
||||
let cargo_toml_lines = cargo_toml.lines();
|
||||
|
||||
Reference in new issue
Block a user