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 head:

xcl-smoke v1
commit: 68a284a596bd558b6bd9db6eedda6d6aa178c360
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1442 (PresentX 1442)
presents per 2 s (last 3): 47 8 0
device removals: 0
crashes: 0
peak commit: 20951 MB
xcl-smoke v1
commit: c9dccc9a1e64b58e3b6accf03727efc4aed9fe43
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1514 (PresentX 1514)
presents per 2 s (last 3): 52 12 2
device removals: 0
crashes: 0
peak commit: 21327 MB

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

…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>
@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.

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.

3 participants