@@ -23,6 +23,8 @@ use std::collections::HashSet;
2323use std:: fmt:: Debug ;
2424use std:: ops:: Not ;
2525use std:: path:: { Path , PathBuf } ;
26+ use std:: process:: Command ;
27+ use tracing:: { info, warn} ;
2628
2729#[ derive( Debug , PartialEq , Eq , Default , Serialize , Deserialize , Clone , Copy , clap:: ValueEnum ) ]
2830#[ serde( rename_all = "lowercase" ) ]
@@ -140,9 +142,42 @@ impl Config {
140142 ) ;
141143 }
142144 extra_env. extend ( self . cargo_extra_env . clone ( ) ) ;
145+ extra_env. insert (
146+ "RUSTUP_TOOLCHAIN" . to_owned ( ) ,
147+ Some ( crate :: select_toolchain ( ) . to_owned ( ) ) ,
148+ ) ;
143149 extra_env
144150 }
145151
152+ pub ( crate ) fn apply_extra_env ( & self , command : & mut Command ) {
153+ for ( key, value) in self . get_extra_env ( ) {
154+ match value {
155+ Some ( value) => command. env ( key, value) ,
156+ None => command. env_remove ( key) ,
157+ } ;
158+ }
159+ }
160+
161+ pub ( crate ) fn log_effective_toolchain ( & self , dir : & AbsPath ) {
162+ let mut command = Command :: new ( "rustc" ) ;
163+ command
164+ . current_dir ( dir. as_str ( ) )
165+ . args ( [ "--version" , "--verbose" ] ) ;
166+ self . apply_extra_env ( & mut command) ;
167+
168+ match command. output ( ) {
169+ Ok ( output) if output. status . success ( ) => info ! (
170+ "effective Rust toolchain:\n {}" ,
171+ String :: from_utf8_lossy( & output. stdout) . trim( )
172+ ) ,
173+ Ok ( output) => warn ! (
174+ "unable to determine effective Rust toolchain: {}" ,
175+ String :: from_utf8_lossy( & output. stderr) . trim( )
176+ ) ,
177+ Err ( error) => warn ! ( "unable to determine effective Rust toolchain: {error}" ) ,
178+ }
179+ }
180+
146181 fn sysroot ( & self , dir : & AbsPath ) -> Sysroot {
147182 let sysroot_input = self . sysroot . as_ref ( ) . map ( |p| join_path_buf ( dir, p) ) ;
148183 let sysroot_src_input = self . sysroot_src . as_ref ( ) . map ( |p| join_path_buf ( dir, p) ) ;
@@ -186,6 +221,7 @@ impl Config {
186221
187222 pub fn to_cargo_config ( & self , dir : & AbsPath ) -> ( CargoConfig , LoadCargoConfig ) {
188223 let sysroot = self . sysroot ( dir) ;
224+ info ! ( "Using sysroot: {:?}" , sysroot. root( ) ) ;
189225 (
190226 CargoConfig {
191227 all_targets : self . cargo_all_targets ,
0 commit comments