From ed13531a2869626a89d0b4b8755fa15c33b0d928 Mon Sep 17 00:00:00 2001 From: Kalmarv <59708937+Kalmarv@users.noreply.github.com> Date: Wed, 25 Nov 2026 22:40:09 -0500 Subject: [PATCH] Build: hash the translator sources of the tree being built build.rs took the source root from env!("CARGO_MANIFEST_DIR"), fixed when the script is compiled. Worktrees that share a CARGO_TARGET_DIR share that binary (cargo names it by the package's path relative to its workspace), so the XCL_*_SOURCE_ID values hashed the first tree's sources, and a cached translation of one tree could load in another. Read CARGO_MANIFEST_DIR at run time instead. Co-Authored-By: Claude Opus 5.5 --- crates/xcl/build.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/xcl/build.rs b/crates/xcl/build.rs index 22b136da8e..c9082f5f6f 100644 --- a/crates/xcl/build.rs +++ b/crates/xcl/build.rs @@ -58,7 +58,10 @@ fn main() { Ok("gnu") => println!("cargo:rustc-link-arg-bin=xcl=-Wl,--disable-high-entropy-va"), _ => {} } - let root = Path::new(env!("CARGO_MANIFEST_DIR")); + // the tree this run builds, read at run time: `env!` would keep the tree that compiled this + // script, and worktrees sharing a target dir share its binary (then their source ids hash + // the first tree's files) + let root = PathBuf::from(std::env::var_os("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR is set for build scripts")); let mut h = 0xcbf2_9ce4_8422_2325u64; add(&mut h, b"xcl-translator-source-v1\0"); add(&mut h, TRANSLATION_GLUE_REVISION.as_bytes()); @@ -87,7 +90,7 @@ fn main() { sources.sort(); let mut d = 0xcbf2_9ce4_8422_2325u64; for path in &sources { - add(&mut d, path.strip_prefix(root).unwrap_or(path).to_string_lossy().replace('\\', "/").as_bytes()); + add(&mut d, path.strip_prefix(&root).unwrap_or(path).to_string_lossy().replace('\\', "/").as_bytes()); add(&mut d, &[0]); add_source(&mut d, &std::fs::read(path).expect("read direct DXIL source")); add(&mut d, &[0]);