44//! but we can't process `.rlib` and need source code instead. The source code
55//! is typically installed with `rustup component add rust-src` command.
66
7- use std:: { env, fs, ops, process:: Command } ;
7+ use std:: { env, fs, ops, path :: Path , process:: Command } ;
88
99use anyhow:: { format_err, Result } ;
1010use base_db:: CrateName ;
@@ -170,7 +170,7 @@ impl Sysroot {
170170 }
171171
172172 /// Returns a command to run a tool preferring the cargo proxies if the sysroot exists.
173- pub fn tool ( & self , tool : Tool ) -> Command {
173+ pub fn tool ( & self , tool : Tool , current_dir : impl AsRef < Path > ) -> Command {
174174 match self . root ( ) {
175175 Some ( root) => {
176176 // special case rustc, we can look that up directly in the sysroot's bin folder
@@ -179,15 +179,15 @@ impl Sysroot {
179179 if let Some ( path) =
180180 probe_for_binary ( root. join ( "bin" ) . join ( Tool :: Rustc . name ( ) ) . into ( ) )
181181 {
182- return Command :: new ( path) ;
182+ return toolchain :: command ( path, current_dir ) ;
183183 }
184184 }
185185
186- let mut cmd = Command :: new ( tool. prefer_proxy ( ) ) ;
186+ let mut cmd = toolchain :: command ( tool. prefer_proxy ( ) , current_dir ) ;
187187 cmd. env ( "RUSTUP_TOOLCHAIN" , AsRef :: < std:: path:: Path > :: as_ref ( root) ) ;
188188 cmd
189189 }
190- _ => Command :: new ( tool. path ( ) ) ,
190+ _ => toolchain :: command ( tool. path ( ) , current_dir ) ,
191191 }
192192 }
193193
@@ -436,7 +436,7 @@ fn discover_sysroot_dir(
436436 current_dir : & AbsPath ,
437437 extra_env : & FxHashMap < String , String > ,
438438) -> Result < AbsPathBuf > {
439- let mut rustc = Command :: new ( Tool :: Rustc . path ( ) ) ;
439+ let mut rustc = toolchain :: command ( Tool :: Rustc . path ( ) , current_dir ) ;
440440 rustc. envs ( extra_env) ;
441441 rustc. current_dir ( current_dir) . args ( [ "--print" , "sysroot" ] ) ;
442442 tracing:: debug!( "Discovering sysroot by {:?}" , rustc) ;
@@ -468,9 +468,9 @@ fn discover_sysroot_src_dir_or_add_component(
468468) -> Result < AbsPathBuf > {
469469 discover_sysroot_src_dir ( sysroot_path)
470470 . or_else ( || {
471- let mut rustup = Command :: new ( Tool :: Rustup . prefer_proxy ( ) ) ;
471+ let mut rustup = toolchain :: command ( Tool :: Rustup . prefer_proxy ( ) , current_dir ) ;
472472 rustup. envs ( extra_env) ;
473- rustup. current_dir ( current_dir ) . args ( [ "component" , "add" , "rust-src" ] ) ;
473+ rustup. args ( [ "component" , "add" , "rust-src" ] ) ;
474474 tracing:: info!( "adding rust-src component by {:?}" , rustup) ;
475475 utf8_stdout ( & mut rustup) . ok ( ) ?;
476476 get_rust_src ( sysroot_path)
0 commit comments