build.rs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2019-2024 Tauri Programme within The Commons Conservancy
  2. // SPDX-License-Identifier: Apache-2.0
  3. // SPDX-License-Identifier: MIT
  4. use tauri_build::WindowsAttributes;
  5. fn main() {
  6. tauri_build::try_build(
  7. tauri_build::Attributes::new()
  8. .codegen(tauri_build::CodegenContext::new())
  9. .windows_attributes(WindowsAttributes::new_without_app_manifest())
  10. .plugin(
  11. "app-menu",
  12. tauri_build::InlinedPlugin::new().commands(&["toggle", "popup"]),
  13. )
  14. .app_manifest(tauri_build::AppManifest::new().commands(&[
  15. "log_operation",
  16. "perform_request",
  17. "echo",
  18. ])),
  19. )
  20. .expect("failed to run tauri-build");
  21. // workaround needed to prevent `STATUS_ENTRYPOINT_NOT_FOUND` error in tests
  22. // see https://github.com/tauri-apps/tauri/pull/4383#issuecomment-1212221864
  23. let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
  24. let target_env = std::env::var("CARGO_CFG_TARGET_ENV");
  25. let is_tauri_workspace = std::env::var("__TAURI_WORKSPACE__").map_or(false, |v| v == "true");
  26. if is_tauri_workspace && target_os == "windows" && Ok("msvc") == target_env.as_deref() {
  27. embed_manifest_for_tests();
  28. }
  29. }
  30. fn embed_manifest_for_tests() {
  31. static WINDOWS_MANIFEST_FILE: &str = "windows-app-manifest.xml";
  32. let manifest = std::env::current_dir()
  33. .unwrap()
  34. .join("../../../crates/tauri-build/src")
  35. .join(WINDOWS_MANIFEST_FILE);
  36. println!("cargo:rerun-if-changed={}", manifest.display());
  37. // Embed the Windows application manifest file.
  38. println!("cargo:rustc-link-arg=/MANIFEST:EMBED");
  39. println!(
  40. "cargo:rustc-link-arg=/MANIFESTINPUT:{}",
  41. manifest.to_str().unwrap()
  42. );
  43. // Turn linker warnings into errors.
  44. println!("cargo:rustc-link-arg=/WX");
  45. }