Skip to content

Recompiler: the build script reads its sources from the checkout being built - #2411

Open
Anon64 wants to merge 1 commit into
xcl-dev:mainfrom
Anon64:build/manifest-dir-at-run
Open

Anon64 wants to merge 1 commit into
xcl-dev:mainfrom
Anon64:build/manifest-dir-at-run

Conversation

@Anon64

@Anon64 Anon64 commented Nov 25, 2026 •

Copy link
Copy Markdown

crates/xcl/build.rs took the crate's directory from env!("CARGO_MANIFEST_DIR"), which is fixed when the build script is compiled. Cargo reuses a compiled build script in another checkout that shares the target directory: the script's dep-info lists only workspace-relative paths, so a git worktree with the same build.rs gets the same script binary. That script then reads and hashes the first checkout's translator sources. While both checkouts exist, XCL_TRANSLATOR_SOURCE_ID is made from the wrong tree. Once the first one is removed, every build of the other that reruns the script fails:

thread 'main' panicked at crates\xcl\build.rs:70:64:
read shader translator source: Os { code: 3, kind: NotFound, message: "The system cannot find the path specified." }

The script now reads CARGO_MANIFEST_DIR when it runs, as Cargo documents for build scripts.

What is in it

  • crates/xcl/build.rs: root comes from std::env::var_os("CARGO_MANIFEST_DIR") at run time instead of env!. Nothing else changes.

Tested

  • RTX 3060 12 GB (driver 581.80), Windows 11 26200, Rust 1.100.0, DXC 1.8.2502.11, debug and release.
  • Reproduction on main 68a284a: worktree A builds -p xcl with CARGO_TARGET_DIR set to checkout B's target. Worktree A is moved away (git worktree move). In B, touch crates/xcl/src/gpu/dxbc.rs and cargo build -p xcl fail with the panic above. The script binary in target/debug/build/xcl/<hash>/out/ contains worktree A's path.
  • On this branch, the same steps build; the compiled script contains no checkout path.
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 1289 passed, 1 failed, 46 ignored. The failure is gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier, which fails on main 68a284a too (1219 passed, 1 failed, 26 ignored in the lib tests on both) and was fixed on main by Tests: check divergent block barriers in a_bridged_mask_write #2420 after this run.
  • SKIPPED on this adapter (no wave64, no heap windows): 16 GPU tests, among them f16_programs_on_the_gpu, f32_programs_on_the_gpu, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu and heap_window_out_of_memory_falls_back_to_the_switch_form.
  • In one earlier full run on this branch, the lib test binary ended with STATUS_ACCESS_VIOLATION after that failure. It did not recur in two lib-only reruns or the full run above, and does not involve the build script.

Regression run

scripts/smoke.ps1 of a retail title, 60 s each, main and this branch's current head (warm caches, A presses scripted):

xcl-smoke v1
commit: 623d02e465a17497a757a4ce867f482b0a6c8f3b
gpu: NVIDIA GeForce RTX 3060
title: retail-1
seconds: 60
exit: 0x0
frames shown: 1339 (PresentX 1339)
presents per 2 s (last 3): 3 2 3
device removals: 0
crashes: 0
peak commit: 25957 MB
xcl-smoke v1
commit: 8e2455097ea29f1c410e688b01ffd20fd5e74f72
gpu: NVIDIA GeForce RTX 3060
title: retail-1
seconds: 60
exit: 0x0
frames shown: 1657 (PresentX 1657)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16656 MB

(The main run went further into world loading inside its 60 s, hence its higher commit and lower present rate at the end. The change itself is build-time only.)

Not tested

  • AMD; Linux / Wine (a gnu target).
  • cargo with --remap-path-prefix or a vendored build.

AI use

  • Claude Code (Claude Opus 5.5) found the failure, made the change, ran the reproduction, tests and smoke runs, and wrote this description.

🤖 Generated with Claude Code

@emirduran707

Copy link
Copy Markdown
Contributor

Independent AMD RDNA4 (native wave64) test report on exact head c9dccc9a1e64b58e3b6accf03727efc4aed9fe43 (clean detached checkout, no local changes).

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64, driver 32.0.31044.16), Ryzen 5 5600, 32 GB RAM, Windows 11 Pro 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17; tests debug, smoke release.
  • Built and tested from a separate git worktree (D:\xcl-verify) sharing CARGO_TARGET_DIR (D:\xcl\target) with the main checkout: cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 1287 passed, 3 failed, 46 ignored; 8 SKIPPED (6 in lower_dxil::tests::{f16,f32}_programs_on_the_gpu refused by per-lane form; heap_window_out_of_memory_falls_back_to_the_switch_form; pso_measurement_compiles_an_exact_synthetic_record).

Regression run (60 s retail-title smoke, XCL_NETWORK=0, release)

xcl-smoke v1
commit: c9dccc9a1e64b58e3b6accf03727efc4aed9fe43
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1612 (PresentX 1612)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13920 MB

(Matched main 68a284a baseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)

Not tested

  • D3D12 debug layer; Intel GPUs.

AI use

  • Antigravity with Gemini 4 Neon ran the build, test suite, and smoke run and drafted this report.

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No code-level defect found: reading CARGO_MANIFEST_DIR at build-script runtime correctly makes a reused build-script binary resolve the active checkout. This bug fix still lacks the repository-required regression test: add a shared CARGO_TARGET_DIR/two-worktree case that fails without the change where feasible. The current Windows build/test check also failed with generic exit-code metadata, so please provide a green rerun before merge.

…g built

build.rs took the crate's directory from env!("CARGO_MANIFEST_DIR"), which
is fixed when the script is compiled. Cargo reuses a compiled build script
in another checkout that shares the target directory: its dep-info records
only workspace-relative paths, so a git worktree with the same sources
gets the same script. That script then hashes (and reads) the first
checkout's files. Once that checkout is removed, every build of the other
one fails with "read shader translator source: ... cannot find the path
specified", and while both exist the translator source id is made from
the wrong tree.

The script now reads CARGO_MANIFEST_DIR when it runs, as Cargo documents
for build scripts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Anon64

Anon64 commented Nov 26, 2026

Copy link
Copy Markdown
Author

@bmjask thanks, added and rebased onto main (8b957bec); head is now 8e245509.

Test: the hashing moved from build.rs into source_hash::source_ids(root, watch), which build.rs calls with the runtime CARGO_MANIFEST_DIR. source_hash::tests::built_ids_are_this_checkouts_sources recomputes the three IDs from the tested checkout and compares them with env!("XCL_TRANSLATOR_SOURCE_ID"), XCL_PER_LANE_SOURCE_ID and XCL_DIRECT_DXIL_SOURCE_ID. It fails when a build script reused from another worktree hashed that worktree's sources. In a single checkout it passes with or without the fix; I did not set up the two-worktree case to show it failing without it.

CI: the earlier failure was lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier on the old base, unrelated to this change; it passes after the rebase.

Tested

  • NVIDIA GeForce RTX 3060, i9-14900KF, Windows 11 26200, debug
  • cargo test --workspace -- --test-threads=4: 1399 passed, 0 failed, 31 ignored, 25 SKIPPED (the e2e tests rerun once after cargo build --workspace, which I had skipped)

AI use: Claude Code with Claude Opus 5.5 wrote the change, ran the tests and wrote this reply.

@Anon64
Anon64 force-pushed the build/manifest-dir-at-run branch from c9dccc9 to 8e24550 Compare November 26, 2026 21:16
@JJAutoCompare

Copy link
Copy Markdown

Tested

Clean 8e2455097ea29f1c410e688b01ffd20fd5e74f72, Windows 11 build 26200, AMD Ryzen 7 3800X, Rust/Cargo 1.100.0 MSVC debug. CPU-only, with dedicated target and temp.

  • cargo test --locked -j 2 -p xcl --lib source_hash::tests:: -- --nocapture: 3 passed, 0 failed, 0 ignored, 0 skipped.
  • A scratch Node.js harness ran cargo test --offline -j 2 -vv --lib source_hash::tests::built_ids_are_this_checkouts_sources -- --exact --nocapture across synthetic checkouts A, B, and B after moving A. Three passes, zero failures, ignores or skips. Cargo reused the build script executable and checkout B's IDs matched its sources on both runs. Replacing the runtime manifest path with the compile-time path caused the expected stale-ID test failure on B and the expected missing-source error when A had moved. The unchanged control on A passed.
  • Invoked the compiled build script from outside the source root with a Windows manifest path containing spaces and non-ASCII characters. Exit 0. All three IDs matched an independent calculation and all 18 watch paths were relative.

Not tested

Full workspace suite, GPU, retail-title smoke.

AI use

Codex in T3 Code (gpt-6.2-sol for the worker run) wrote the scratch harness, ran the checks and drafted this report. The coordinator reran the checked-in group and scratch harness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants