Repository navigation
Conversation
KelboLive
left a comment
There was a problem hiding this comment.
Direction is right, and the fail-loud paths are a real improvement: with the original checkout gone and the build script forced to rerun, base emits the empty cbf29ce4… hash and empty LEONIDA_SHADER_SWITCHES, while this branch emits the correct hash. rerun-if-changed gains exactly build.rs, which is right because the script now affects the hash, and I confirmed the rerun behaviour: build → no-op → touch src/lib.rs → rebuild → no-op. It also builds correctly from the repo root, from an unrelated cwd, with a custom CARGO_TARGET_DIR, and as a path dependency (same hash as in-tree).
One overclaim, though: with two checkouts at the same commit sharing a CARGO_TARGET_DIR, the second is still a 0.04 s no-op and ships the first checkout's hash — before and after this change — because Cargo never runs the script at all, and a runtime read cannot help that. What is fixed is the case where the script does rerun against a stale baked path. The new test drives the compiled binary directly with a forced CARGO_MANIFEST_DIR, so it validates the mechanism but not the Cargo-level reuse described in the body.
Please narrow the claim to "correct whenever the build script reruns", or state that sharing a target dir across checkouts remains unsupported (the build dir is literally shared — leonida-shader-8d2ca1f295c0ab1e for both).
Two mutations worth recording, both of which the change now catches: a cwd-relative base passes an in-tree cargo build (Cargo runs the script with cwd = package root) and is only caught by the test, while a wrong base now panics loudly where base silently emitted the seed hash. That is the right kind of failure.
|
I exercised the real Cargo reuse path on Linux with Rust 1.98.1, at
The experiment specifically exercises the case where B's edited source makes Cargo rerun the cached build program. It agrees with the distinction in the previous review about an identical checkout that produces a Cargo no-op. No game files or GPU dependency. MEASURED, AI-assisted (Codex). |
|
@KelboLive Thanks for the careful review! I have updated the PR description to narrow the claim to "correct whenever the build script reruns" and explicitly note that identical-commit checkouts sharing a @merzleckeier Thanks for exercising the two-worktree Cargo rerun path with a modified source file! |
VERIFY-2882 — Linux, Rust 1.98.1 (the pinned toolchain), no GPU device, no game filesVerdict: PASS. The fix closes a hole where the build script would hash nothing and say so with exit code 0. I measured the wrong hash and the loud failure side by side. Head 1. What was wrongThe build script hashes the translator's own sources so the shader cache can tell whether a cached translation is still current. It found them like this: let src = Path::new(env!("CARGO_MANIFEST_DIR")).join("src");
…
let Ok(entries) = std::fs::read_dir(dir) else { return; }; // a directory that cannot be read: no sources
…
let text = std::fs::read(p).unwrap_or_default(); // a file that cannot be read: an empty fileTwo problems:
2. What that cost, measuredI compiled
The pull request also adds 3. The behaviour difference, measuredWith the pull request's build script, That is, 4. The new test
let compiled = std::process::Command::new(rustc).arg("--edition").arg("2024").arg(&build_rs).arg("-o").arg(&exe).output().unwrap();
let out_a = run_with(&dir_a); // CARGO_MANIFEST_DIR=checkout_a
let out_b = run_with(&dir_b); // CARGO_MANIFEST_DIR=checkout_b
let out_missing = run_with(&dir_missing);and then requires that 5. Red and green, and the discrimination
With only That is the test's first assertion, a check of the script's text. To see the behaviour rather than the text, I removed that one assertion and ran again with So the behavioural half of the test also fails against 6. A small note on the test's first assertionThe text check ( 7. What I did not check
AI-assisted: MiniMax M3.1 Flash. |
|
Verified on Windows 11, Rust 1.98.1, no GPU and no game files. The head's own test passes. The hazard is real, and here is exactly when it bites. The build script is reused when the second checkout's files are older than the fingerprint Cargo recorded - a fresh checkout's files are newer, so Cargo recompiles and the fingerprint is right. Measured with two worktrees of different trees (
So the failure is not "sharing a target directory" in general, but sharing one across checkouts whose files are older than the recorded fingerprint, or after a checkout was deleted and rebuilt in place. The fix removes the whole class: the path is read at run time, so the script hashes the tree that is there, and a missing tree fails the build instead of hashing nothing. Two notes, neither blocking.
The fix is right, and the test is the right shape: it drives the compiled script with two different |
Claim:
D3D12-SHADER-BUILD-MANIFEST-DIR(#2570 (comment))Fixes
@Neutron-0's finding ind3d12/crates/leonida-shader/build.rs.Root cause
build.rsreadenv!("CARGO_MANIFEST_DIR")at build-script compile time and silently returned onstd::fs::read_dir/std::fs::readerrors. Whenever Cargo reruns a cachedbuild.rsexecutable against a different or moved/removed checkout (for example, a modified source file in another worktree sharingCARGO_TARGET_DIR, or a relocated checkout), it hashed the stale baked path -- or silently emitted the empty seed hash (cbf29ce48422232584222325cbf29ce4) and emptyLEONIDA_SHADER_SWITCHESif that original directory was gone.Note on scope: sharing a single
CARGO_TARGET_DIRacross two identical checkouts at the same commit still produces a Cargo no-op (Cargo does not rerun the build script at all), so sharingCARGO_TARGET_DIRacross checkouts remains unsupported in general. This change guarantees correct hashing and fail-loud behavior whenever the build script runs.Changes
d3d12/crates/leonida-shader/build.rs:CARGO_MANIFEST_DIRat runtime viastd::env::var_os("CARGO_MANIFEST_DIR")instead of compile-timeenv!.cargo:rerun-if-changed=build.rs.panic!) onread_dir/readerrors or an empty non-test source list instead of silently emitting an empty fingerprint.d3d12/crates/leonida-shader/src/source_hash_tests.rs:build_script_uses_runtime_manifest_dir_and_rejects_missing_src, which compilesbuild.rsonce and drives the compiled binary directly with distinct temporaryCARGO_MANIFEST_DIRtrees (verifying distinct hashes and switches) and a missing directory (verifying non-zero failure) to validate runtime path resolution and fail-loud behavior whenever the script runs.Verification
build.rs):build_script_uses_runtime_manifest_dir_and_rejects_missing_srcfailed (0 passed; 1 failed).cargo test --locked -p leonida-shader --lib source_hash_tests -- --nocapture: 4 passed, 0 failed.cargo check --locked -p leonida-shader --all-targets: passed.leonida-shader --libon this machine hits the unrelatedPSV0DXIL validator failures tracked in d3d12: the PSV0 part's name table holds a copy of a name per element (SHADER-PSV0-NAME-PER-ELEMENT) #2864.)GPUs tested: NVIDIA GeForce RTX 5070 12 GB (driver 621.40, Windows 10 Pro 22H2 build 19045, Ryzen 9 5950X 16C/32T)
AI-assisted: Antigravity