Skip to content

Commit 9f1d4aa

Browse files
committed
prioritise rustup sysroots over system ones
`get_path_for_executable` will now first check `$CARGO_HOME` before falling back to searching `$PATH`. rustup is the recommended way to manage rust toolchains, therefore should be picked before the system toolchain.
1 parent 4a8d0f7 commit 9f1d4aa

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

crates/toolchain/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,17 @@ fn get_path_for_executable(executable_name: &'static str) -> PathBuf {
6363
// The current implementation checks three places for an executable to use:
6464
// 1) Appropriate environment variable (erroring if this is set but not a usable executable)
6565
// example: for cargo, this checks $CARGO environment variable; for rustc, $RUSTC; etc
66-
// 2) `<executable_name>`
67-
// example: for cargo, this tries just `cargo`, which will succeed if `cargo` is on the $PATH
68-
// 3) `$CARGO_HOME/bin/<executable_name>`
66+
// 2) `$CARGO_HOME/bin/<executable_name>`
6967
// where $CARGO_HOME defaults to ~/.cargo (see https://doc.rust-lang.org/cargo/guide/cargo-home.html)
7068
// example: for cargo, this tries $CARGO_HOME/bin/cargo, or ~/.cargo/bin/cargo if $CARGO_HOME is unset.
7169
// It seems that this is a reasonable place to try for cargo, rustc, and rustup
70+
// 3) `<executable_name>`
71+
// example: for cargo, this tries just `cargo`, which will succeed if `cargo` is on the $PATH
7272
let env_var = executable_name.to_ascii_uppercase();
7373
if let Some(path) = env::var_os(env_var) {
7474
return path.into();
7575
}
7676

77-
if lookup_in_path(executable_name) {
78-
return executable_name.into();
79-
}
80-
8177
if let Some(mut path) = get_cargo_home() {
8278
path.push("bin");
8379
path.push(executable_name);
@@ -86,6 +82,10 @@ fn get_path_for_executable(executable_name: &'static str) -> PathBuf {
8682
}
8783
}
8884

85+
if lookup_in_path(executable_name) {
86+
return executable_name.into();
87+
}
88+
8989
executable_name.into()
9090
}
9191

0 commit comments

Comments
 (0)