fn main() { // Bake the short commit hash in for the About page. Falls back to "unknown" // in a non-git build (e.g. a source tarball). `logs/HEAD` is the reflog — it // gets a line on every commit/checkout, so watching it re-runs this script // when the hash changes (build.rs output is otherwise cached). let hash = std::process::Command::new("git") .args(["rev-parse", "--short", "HEAD"]) .output() .ok() .filter(|o| o.status.success()) .map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string()) .filter(|s| !s.is_empty()) .unwrap_or_else(|| "unknown".to_string()); println!("cargo:rustc-env=WA_GIT_HASH={hash}"); println!("cargo:rerun-if-changed=../.git/logs/HEAD"); // The `vulkan` build links `vulkan-1.dll` at load time, so the exe won't // launch on a machine that lacks the Vulkan loader (no GPU driver / bare VM). // Bundling the redistributable loader (Apache-2.0) next to the exe makes the // single universal installer start everywhere — with no GPU it simply reports // zero devices and we fall back to CPU. Copied both next to the built exe (so // `tauri dev`/`cargo run` work) and into the crate dir where the bundler picks // it up as a resource (see tauri.vulkan.conf.json). if std::env::var_os("CARGO_FEATURE_VULKAN").is_some() { stage_vulkan_loader(); } tauri_build::build(); } /// Locate `vulkan-1.dll` (Vulkan SDK first, then System32) and copy it beside /// the compiled exe and into the crate dir for bundling. Warns rather than fails /// so a dev build on a machine with the loader already on PATH still succeeds. fn stage_vulkan_loader() { use std::path::{Path, PathBuf}; let source = std::env::var_os("VULKAN_SDK") .map(|sdk| Path::new(&sdk).join("Bin").join("vulkan-1.dll")) .filter(|p| p.exists()) .or_else(|| { let sys = PathBuf::from(r"C:\Windows\System32\vulkan-1.dll"); sys.exists().then_some(sys) }); let Some(source) = source else { println!( "cargo:warning=vulkan feature is on but vulkan-1.dll wasn't found \ (set VULKAN_SDK); the installer won't bundle the Vulkan loader" ); return; }; // Beside the exe: OUT_DIR is target//build/-/out, so three // parents up is target/ (correct even under CARGO_TARGET_DIR=C:\wt). if let Some(out_dir) = std::env::var_os("OUT_DIR") { if let Some(exe_dir) = Path::new(&out_dir).ancestors().nth(3) { let _ = std::fs::copy(&source, exe_dir.join("vulkan-1.dll")); } } // Into the crate dir for the bundler resource. let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR"); if let Err(e) = std::fs::copy(&source, Path::new(&manifest_dir).join("vulkan-1.dll")) { println!("cargo:warning=failed to stage vulkan-1.dll for bundling: {e}"); } }