Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/project-model/src/sysroot.rs')
-rw-r--r--crates/project-model/src/sysroot.rs39
1 files changed, 21 insertions, 18 deletions
diff --git a/crates/project-model/src/sysroot.rs b/crates/project-model/src/sysroot.rs
index ea24393ed8..3127bae8b0 100644
--- a/crates/project-model/src/sysroot.rs
+++ b/crates/project-model/src/sysroot.rs
@@ -12,7 +12,7 @@ use itertools::Itertools;
use la_arena::{Arena, Idx};
use paths::{AbsPath, AbsPathBuf};
use rustc_hash::FxHashMap;
-use toolchain::probe_for_binary;
+use toolchain::{probe_for_binary, Tool};
use crate::{utf8_stdout, CargoConfig, CargoWorkspace, ManifestPath};
@@ -193,23 +193,26 @@ impl Sysroot {
Ok(Sysroot::load(sysroot_dir, Some(sysroot_src_dir), metadata))
}
- pub fn set_rustup_toolchain_env(cmd: &mut Command, sysroot: Option<&Self>) {
- if let Some(sysroot) = sysroot {
- cmd.env("RUSTUP_TOOLCHAIN", AsRef::<std::path::Path>::as_ref(&sysroot.root));
- }
- }
-
- /// Returns a `Command` that is configured to run `rustc` from the sysroot if it exists,
- /// otherwise returns what [toolchain::Tool::Rustc] returns.
- pub fn rustc(sysroot: Option<&Self>) -> Command {
- let mut cmd = Command::new(match sysroot {
+ /// Returns a command to run a tool preferring the cargo proxies if the sysroot exists.
+ pub fn tool(sysroot: Option<&Self>, tool: Tool) -> Command {
+ match sysroot {
Some(sysroot) => {
- toolchain::Tool::Rustc.path_in_or_discover(sysroot.root.join("bin").as_ref())
+ // special case rustc, we can look that up directly in the sysroot's bin folder
+ // as it should never invoke another cargo binary
+ if let Tool::Rustc = tool {
+ if let Some(path) =
+ probe_for_binary(sysroot.root.join("bin").join(Tool::Rustc.name()).into())
+ {
+ return Command::new(path);
+ }
+ }
+
+ let mut cmd = Command::new(tool.prefer_proxy());
+ cmd.env("RUSTUP_TOOLCHAIN", AsRef::<std::path::Path>::as_ref(&sysroot.root));
+ cmd
}
- None => toolchain::Tool::Rustc.path(),
- });
- Self::set_rustup_toolchain_env(&mut cmd, sysroot);
- cmd
+ _ => Command::new(tool.path()),
+ }
}
pub fn discover_proc_macro_srv(&self) -> anyhow::Result<AbsPathBuf> {
@@ -411,7 +414,7 @@ fn discover_sysroot_dir(
current_dir: &AbsPath,
extra_env: &FxHashMap<String, String>,
) -> Result<AbsPathBuf> {
- let mut rustc = Command::new(toolchain::rustc());
+ let mut rustc = Command::new(Tool::Rustc.path());
rustc.envs(extra_env);
rustc.current_dir(current_dir).args(["--print", "sysroot"]);
tracing::debug!("Discovering sysroot by {:?}", rustc);
@@ -443,7 +446,7 @@ fn discover_sysroot_src_dir_or_add_component(
) -> Result<AbsPathBuf> {
discover_sysroot_src_dir(sysroot_path)
.or_else(|| {
- let mut rustup = Command::new(toolchain::rustup());
+ let mut rustup = Command::new(Tool::Rustup.prefer_proxy());
rustup.envs(extra_env);
rustup.current_dir(current_dir).args(["component", "add", "rust-src"]);
tracing::info!("adding rust-src component by {:?}", rustup);