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.rs | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/crates/project-model/src/sysroot.rs b/crates/project-model/src/sysroot.rs index 6ed030a4c3..c7c1b04318 100644 --- a/crates/project-model/src/sysroot.rs +++ b/crates/project-model/src/sysroot.rs @@ -86,7 +86,7 @@ impl Sysroot { impl Sysroot { /// Attempts to discover the toolchain's sysroot from the given `dir`. - pub fn discover(dir: &AbsPath, extra_env: &FxHashMap<String, String>) -> Sysroot { + pub fn discover(dir: &AbsPath, extra_env: &FxHashMap<String, Option<String>>) -> Sysroot { let sysroot_dir = discover_sysroot_dir(dir, extra_env); let rust_lib_src_dir = sysroot_dir.as_ref().ok().map(|sysroot_dir| { discover_rust_lib_src_dir_or_add_component(sysroot_dir, dir, extra_env) @@ -96,7 +96,7 @@ impl Sysroot { pub fn discover_with_src_override( current_dir: &AbsPath, - extra_env: &FxHashMap<String, String>, + extra_env: &FxHashMap<String, Option<String>>, rust_lib_src_dir: AbsPathBuf, ) -> Sysroot { let sysroot_dir = discover_sysroot_dir(current_dir, extra_env); @@ -118,7 +118,12 @@ impl Sysroot { } /// Returns a command to run a tool preferring the cargo proxies if the sysroot exists. - pub fn tool(&self, tool: Tool, current_dir: impl AsRef<Path>) -> Command { + pub fn tool( + &self, + tool: Tool, + current_dir: impl AsRef<Path>, + envs: &FxHashMap<String, Option<String>>, + ) -> Command { match self.root() { Some(root) => { // special case rustc, we can look that up directly in the sysroot's bin folder @@ -127,15 +132,15 @@ impl Sysroot { if let Some(path) = probe_for_binary(root.join("bin").join(Tool::Rustc.name()).into()) { - return toolchain::command(path, current_dir); + return toolchain::command(path, current_dir, envs); } } - let mut cmd = toolchain::command(tool.prefer_proxy(), current_dir); + let mut cmd = toolchain::command(tool.prefer_proxy(), current_dir, envs); cmd.env("RUSTUP_TOOLCHAIN", AsRef::<std::path::Path>::as_ref(root)); cmd } - _ => toolchain::command(tool.path(), current_dir), + _ => toolchain::command(tool.path(), current_dir, envs), } } @@ -292,7 +297,7 @@ impl Sysroot { // the sysroot uses `public-dependency`, so we make cargo think it's a nightly cargo_config.extra_env.insert( "__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS".to_owned(), - "nightly".to_owned(), + Some("nightly".to_owned()), ); let (mut res, _) = match CargoWorkspace::fetch_metadata( @@ -368,10 +373,9 @@ impl Sysroot { fn discover_sysroot_dir( current_dir: &AbsPath, - extra_env: &FxHashMap<String, String>, + extra_env: &FxHashMap<String, Option<String>>, ) -> Result<AbsPathBuf> { - let mut rustc = toolchain::command(Tool::Rustc.path(), current_dir); - rustc.envs(extra_env); + let mut rustc = toolchain::command(Tool::Rustc.path(), current_dir, extra_env); rustc.current_dir(current_dir).args(["--print", "sysroot"]); tracing::debug!("Discovering sysroot by {:?}", rustc); let stdout = utf8_stdout(&mut rustc)?; @@ -398,12 +402,11 @@ fn discover_rust_lib_src_dir(sysroot_path: &AbsPathBuf) -> Option<AbsPathBuf> { fn discover_rust_lib_src_dir_or_add_component( sysroot_path: &AbsPathBuf, current_dir: &AbsPath, - extra_env: &FxHashMap<String, String>, + extra_env: &FxHashMap<String, Option<String>>, ) -> Result<AbsPathBuf> { discover_rust_lib_src_dir(sysroot_path) .or_else(|| { - let mut rustup = toolchain::command(Tool::Rustup.prefer_proxy(), current_dir); - rustup.envs(extra_env); + let mut rustup = toolchain::command(Tool::Rustup.prefer_proxy(), current_dir, extra_env); rustup.args(["component", "add", "rust-src"]); tracing::info!("adding rust-src component by {:?}", rustup); utf8_stdout(&mut rustup).ok()?; |