@@ -86,7 +86,7 @@ impl Sysroot {
86
86
87
87
impl Sysroot {
88
88
/// Attempts to discover the toolchain's sysroot from the given `dir`.
89
- pub fn discover ( dir : & AbsPath , extra_env : & FxHashMap < String , String > ) -> Sysroot {
89
+ pub fn discover ( dir : & AbsPath , extra_env : & FxHashMap < String , Option < String > > ) -> Sysroot {
90
90
let sysroot_dir = discover_sysroot_dir ( dir, extra_env) ;
91
91
let rust_lib_src_dir = sysroot_dir. as_ref ( ) . ok ( ) . map ( |sysroot_dir| {
92
92
discover_rust_lib_src_dir_or_add_component ( sysroot_dir, dir, extra_env)
@@ -96,7 +96,7 @@ impl Sysroot {
96
96
97
97
pub fn discover_with_src_override (
98
98
current_dir : & AbsPath ,
99
- extra_env : & FxHashMap < String , String > ,
99
+ extra_env : & FxHashMap < String , Option < String > > ,
100
100
rust_lib_src_dir : AbsPathBuf ,
101
101
) -> Sysroot {
102
102
let sysroot_dir = discover_sysroot_dir ( current_dir, extra_env) ;
@@ -118,7 +118,12 @@ impl Sysroot {
118
118
}
119
119
120
120
/// Returns a command to run a tool preferring the cargo proxies if the sysroot exists.
121
- pub fn tool ( & self , tool : Tool , current_dir : impl AsRef < Path > ) -> Command {
121
+ pub fn tool (
122
+ & self ,
123
+ tool : Tool ,
124
+ current_dir : impl AsRef < Path > ,
125
+ envs : & FxHashMap < String , Option < String > > ,
126
+ ) -> Command {
122
127
match self . root ( ) {
123
128
Some ( root) => {
124
129
// special case rustc, we can look that up directly in the sysroot's bin folder
@@ -127,15 +132,15 @@ impl Sysroot {
127
132
if let Some ( path) =
128
133
probe_for_binary ( root. join ( "bin" ) . join ( Tool :: Rustc . name ( ) ) . into ( ) )
129
134
{
130
- return toolchain:: command ( path, current_dir) ;
135
+ return toolchain:: command ( path, current_dir, envs ) ;
131
136
}
132
137
}
133
138
134
- let mut cmd = toolchain:: command ( tool. prefer_proxy ( ) , current_dir) ;
139
+ let mut cmd = toolchain:: command ( tool. prefer_proxy ( ) , current_dir, envs ) ;
135
140
cmd. env ( "RUSTUP_TOOLCHAIN" , AsRef :: < std:: path:: Path > :: as_ref ( root) ) ;
136
141
cmd
137
142
}
138
- _ => toolchain:: command ( tool. path ( ) , current_dir) ,
143
+ _ => toolchain:: command ( tool. path ( ) , current_dir, envs ) ,
139
144
}
140
145
}
141
146
@@ -292,7 +297,7 @@ impl Sysroot {
292
297
// the sysroot uses `public-dependency`, so we make cargo think it's a nightly
293
298
cargo_config. extra_env . insert (
294
299
"__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS" . to_owned ( ) ,
295
- "nightly" . to_owned ( ) ,
300
+ Some ( "nightly" . to_owned ( ) ) ,
296
301
) ;
297
302
298
303
let ( mut res, _) = match CargoWorkspace :: fetch_metadata (
@@ -368,10 +373,9 @@ impl Sysroot {
368
373
369
374
fn discover_sysroot_dir (
370
375
current_dir : & AbsPath ,
371
- extra_env : & FxHashMap < String , String > ,
376
+ extra_env : & FxHashMap < String , Option < String > > ,
372
377
) -> Result < AbsPathBuf > {
373
- let mut rustc = toolchain:: command ( Tool :: Rustc . path ( ) , current_dir) ;
374
- rustc. envs ( extra_env) ;
378
+ let mut rustc = toolchain:: command ( Tool :: Rustc . path ( ) , current_dir, extra_env) ;
375
379
rustc. current_dir ( current_dir) . args ( [ "--print" , "sysroot" ] ) ;
376
380
tracing:: debug!( "Discovering sysroot by {:?}" , rustc) ;
377
381
let stdout = utf8_stdout ( & mut rustc) ?;
@@ -398,12 +402,11 @@ fn discover_rust_lib_src_dir(sysroot_path: &AbsPathBuf) -> Option<AbsPathBuf> {
398
402
fn discover_rust_lib_src_dir_or_add_component (
399
403
sysroot_path : & AbsPathBuf ,
400
404
current_dir : & AbsPath ,
401
- extra_env : & FxHashMap < String , String > ,
405
+ extra_env : & FxHashMap < String , Option < String > > ,
402
406
) -> Result < AbsPathBuf > {
403
407
discover_rust_lib_src_dir ( sysroot_path)
404
408
. or_else ( || {
405
- let mut rustup = toolchain:: command ( Tool :: Rustup . prefer_proxy ( ) , current_dir) ;
406
- rustup. envs ( extra_env) ;
409
+ let mut rustup = toolchain:: command ( Tool :: Rustup . prefer_proxy ( ) , current_dir, extra_env) ;
407
410
rustup. args ( [ "component" , "add" , "rust-src" ] ) ;
408
411
tracing:: info!( "adding rust-src component by {:?}" , rustup) ;
409
412
utf8_stdout ( & mut rustup) . ok ( ) ?;
0 commit comments