Cargo appends paths to PATH
while building without checking if those paths already exist
#14194
Labels
A-environment-variables
Area: environment variables
A-rebuild-detection
Area: rebuild detection and fingerprinting
C-bug
Category: bug
S-accepted
Status: Issue or feature is accepted, and has a team member available to help mentor or review
Problem
cargo
appears to be appending paths to thePATH
environment variable without checking if those paths are already present in it, causing unneeded rebuilds in some situations. I would expect cargo to not add to the path if it doesn't have to.Steps
This issue can be reduced to a single file.
main.rs
:PATH
variables. The beginning of the path of the first cargo invocation should be:While the nested cargo invocation should be:
As can be seen, cargo has added the same 3 paths again to the path, making crates that watch the PATH variable for changes be rebuilt.
Possible Solution(s)
I'm not sure where cargo inserts these paths, but perhaps just avoiding adding a path if the path occurs within the first 3 paths is sufficient? Another solution could be a hashset over all paths in the
PATH
, but that seems excessive.Notes
I'm using an xtask setup to run
cargo build
, while running clippy through cargo directly. Switching between xtask and cargo causes a decent number of crates to be rebuilt. This is becausecc
, which a few of my crates use, emits acargo:rerun-if-env-changed
directive forPATH
, which is dirty between cargo and xtask. I would expect acargo build
run from within xtask and acargo build
run outside of xtask to not need to rebuild each other's artifacts.As an alternative, I could just add a new command to my xtask setup for clippy. However, I would prefer if I didn't have to wrap each cargo build-like command and
cargo install
-ed subcommand that I want to use.Version
The text was updated successfully, but these errors were encountered: