build.rs: rerun-if-env-changed
should mean "changed compared to last execution of the same kind" (check vs build/run)
#7432
Labels
A-build-scripts
Area: build.rs scripts
A-rebuild-detection
Area: rebuild detection and fingerprinting
C-bug
Category: bug
Command-check
S-needs-info
Status: Needs more info, such as a reproduction or more background for a feature request.
Currently, it seems that build.rs scripts share the same environment when run by
cargo build
/cargo run
andcargo check
.This is a problem which leads to unnecessary rebuilds of
libsqlite3-sys
whenever I havecargo watch -x run
running in cmd.exe, when I then docargo check
in my editor (so that I can jump to errors/warnings easily).This causes a rebuild of
libsqlite3-sys
and all its dependent crates in my workspace for every switch betweencargo check
and thecargo run
started bycargo watch
.Because:
libsqlite3-sys
usesrerun-if-env-changed=PATH
AND apparentlycargo watch
gives a differentPATH
tocargo run
than cmd.exe has [1]. Because if I runcargo run
normally (not throughcargo watch
) this doesn't happen.The same happens when I run
cargo run
normally (not throughcargo watch
) but in Cmder instead of in cmd.exe, and here I know that it has a different PATH than my editor. In Sublime Text and in Cmder I ran the python commandimport os; os.environ['PATH']
to check, and indeed, Cmder adds some of his own folders toPATH
, which is why I switched to using the bare cmd.exe (to avoid the recompilations oflibsqlite3-sys
and its dependent crates in my workspace, which takes several minutes every time). But in bare cmd.exe, the same unnecessary recompilations happen when usingcargo watch -x run
and doingcargo check
in Sublime Text.So currently, it seems that
rerun-if-env-changed
means, "changed, regardless of whether we also switched between check and build/run".I suggest that
rerun-if-env-changed
should mean "changed compared to last execution of the same kind": If the build.rs script is currently being executed because ofcargo check
, compare the env var to the last time it was also executed bycargo check
, NOT bycargo build
.And similarly for
cargo build/run
.build
andrun
are treated the same, becauserun
impliesbuild
. Butcheck
doesn't implybuild
, they also produce separate artifacts in the target dir. So in a similar vein, their env's should be kept separate with respect torerun-if-env-changed
![1]: Btw, it's not
cargo-watch
's fault that thePATH
for its spawned process is different, it'scargo
's: #7431The text was updated successfully, but these errors were encountered: