@@ -12,7 +12,7 @@ use itertools::Itertools;
12
12
use la_arena:: { Arena , Idx } ;
13
13
use paths:: { AbsPath , AbsPathBuf } ;
14
14
use rustc_hash:: FxHashMap ;
15
- use toolchain:: probe_for_binary;
15
+ use toolchain:: { probe_for_binary, Tool } ;
16
16
17
17
use crate :: { utf8_stdout, CargoConfig , CargoWorkspace , ManifestPath } ;
18
18
@@ -193,23 +193,26 @@ impl Sysroot {
193
193
Ok ( Sysroot :: load ( sysroot_dir, Some ( sysroot_src_dir) , metadata) )
194
194
}
195
195
196
- pub fn set_rustup_toolchain_env ( cmd : & mut Command , sysroot : Option < & Self > ) {
197
- if let Some ( sysroot) = sysroot {
198
- cmd. env ( "RUSTUP_TOOLCHAIN" , AsRef :: < std:: path:: Path > :: as_ref ( & sysroot. root ) ) ;
199
- }
200
- }
201
-
202
- /// Returns a `Command` that is configured to run `rustc` from the sysroot if it exists,
203
- /// otherwise returns what [toolchain::Tool::Rustc] returns.
204
- pub fn rustc ( sysroot : Option < & Self > ) -> Command {
205
- let mut cmd = Command :: new ( match sysroot {
196
+ /// Returns a command to run a tool preferring the cargo proxies if the sysroot exists.
197
+ pub fn tool ( sysroot : Option < & Self > , tool : Tool ) -> Command {
198
+ match sysroot {
206
199
Some ( sysroot) => {
207
- toolchain:: Tool :: Rustc . path_in_or_discover ( sysroot. root . join ( "bin" ) . as_ref ( ) )
200
+ // special case rustc, we can look that up directly in the sysroot's bin folder
201
+ // as it should never invoke another cargo binary
202
+ if let Tool :: Rustc = tool {
203
+ if let Some ( path) =
204
+ probe_for_binary ( sysroot. root . join ( "bin" ) . join ( Tool :: Rustc . name ( ) ) . into ( ) )
205
+ {
206
+ return Command :: new ( path) ;
207
+ }
208
+ }
209
+
210
+ let mut cmd = Command :: new ( tool. prefer_proxy ( ) ) ;
211
+ cmd. env ( "RUSTUP_TOOLCHAIN" , AsRef :: < std:: path:: Path > :: as_ref ( & sysroot. root ) ) ;
212
+ cmd
208
213
}
209
- None => toolchain:: Tool :: Rustc . path ( ) ,
210
- } ) ;
211
- Self :: set_rustup_toolchain_env ( & mut cmd, sysroot) ;
212
- cmd
214
+ _ => Command :: new ( tool. path ( ) ) ,
215
+ }
213
216
}
214
217
215
218
pub fn discover_proc_macro_srv ( & self ) -> anyhow:: Result < AbsPathBuf > {
@@ -411,7 +414,7 @@ fn discover_sysroot_dir(
411
414
current_dir : & AbsPath ,
412
415
extra_env : & FxHashMap < String , String > ,
413
416
) -> Result < AbsPathBuf > {
414
- let mut rustc = Command :: new ( toolchain :: rustc ( ) ) ;
417
+ let mut rustc = Command :: new ( Tool :: Rustc . path ( ) ) ;
415
418
rustc. envs ( extra_env) ;
416
419
rustc. current_dir ( current_dir) . args ( [ "--print" , "sysroot" ] ) ;
417
420
tracing:: debug!( "Discovering sysroot by {:?}" , rustc) ;
@@ -443,7 +446,7 @@ fn discover_sysroot_src_dir_or_add_component(
443
446
) -> Result < AbsPathBuf > {
444
447
discover_sysroot_src_dir ( sysroot_path)
445
448
. or_else ( || {
446
- let mut rustup = Command :: new ( toolchain :: rustup ( ) ) ;
449
+ let mut rustup = Command :: new ( Tool :: Rustup . prefer_proxy ( ) ) ;
447
450
rustup. envs ( extra_env) ;
448
451
rustup. current_dir ( current_dir) . args ( [ "component" , "add" , "rust-src" ] ) ;
449
452
tracing:: info!( "adding rust-src component by {:?}" , rustup) ;
0 commit comments