Description
openedon Oct 25, 2024
I'm building rust code in a CI environment, setting -Cincremental to a shared location. CI allocates a new working directory for each build. To prevent leaking that info to the debug info, we set --remap_path_prefix=${PWD}=
to eliminate the unwanted prefix from the debug info.
rustc src/lib.rs \
--crate-name=xxx \
--crate-type=rlib \
--error-format=human \
--out-dir=${OUTDIR} \
--remap-path-prefix=${PWD}= \
--emit=dep-info,link \
-Ccodegen-units=256 \
-Zincremental_info \
-Cincremental=${CACHEDIR}
I expected this will reuse the incremental build cache, but it's not:
[incremental] session directory: 259 files hard-linked
[incremental] session directory: 0 files copied
[incremental] completely ignoring cache because of differing commandline arguments
Further inspection of how the hash being generated, I found:
rust/compiler/rustc_session/src/options.rs
Lines 195 to 222 in 017ae1b
for our case, working_dir
always uses remapped_path ""
, which is stable over build. but the remap_path_prefix
is different everytime. and the logic for populating working_dir
is at:
rust/compiler/rustc_session/src/config.rs
Lines 2690 to 2695 in 017ae1b
So to get correct remapped working_dir
, I must set --remap-path-prefix
, but setting it will change remap_path_prefix
and causing hash mismatch:
rust/compiler/rustc_incremental/src/persist/load.rs
Lines 159 to 164 in 017ae1b
Meta
rustc --version --verbose
:
rustc 1.82.0-nightly (f6e511eec 2024-10-15)
binary: rustc
commit-hash: f6e511eec7342f59a25f7c0534f1dbea00d01b14
commit-date: 2024-10-15
host: aarch64-apple-darwin
release: 1.82.0-nightly
LLVM version: 19.1.1