@@ -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,41 @@ impl Config {
140142 ) ;
141143 }
142144 extra_env. extend ( self . cargo_extra_env . clone ( ) ) ;
145+ // Always use the latest stable toolchain, irrespective of any toolchain
146+ // file in the project being extracted.
147+ extra_env. insert ( "RUSTUP_TOOLCHAIN" . to_owned ( ) , Some ( "stable" . to_owned ( ) ) ) ;
143148 extra_env
144149 }
145150
151+ pub ( crate ) fn apply_extra_env ( & self , command : & mut Command ) {
152+ for ( key, value) in self . get_extra_env ( ) {
153+ match value {
154+ Some ( value) => command. env ( key, value) ,
155+ None => command. env_remove ( key) ,
156+ } ;
157+ }
158+ }
159+
160+ pub ( crate ) fn log_effective_toolchain ( & self , dir : & AbsPath ) {
161+ let mut command = Command :: new ( "rustc" ) ;
162+ command
163+ . current_dir ( dir. as_str ( ) )
164+ . args ( [ "--version" , "--verbose" ] ) ;
165+ self . apply_extra_env ( & mut command) ;
166+
167+ match command. output ( ) {
168+ Ok ( output) if output. status . success ( ) => info ! (
169+ "effective Rust toolchain:\n {}" ,
170+ String :: from_utf8_lossy( & output. stdout) . trim( )
171+ ) ,
172+ Ok ( output) => warn ! (
173+ "unable to determine effective Rust toolchain: {}" ,
174+ String :: from_utf8_lossy( & output. stderr) . trim( )
175+ ) ,
176+ Err ( error) => warn ! ( "unable to determine effective Rust toolchain: {error}" ) ,
177+ }
178+ }
179+
146180 fn sysroot ( & self , dir : & AbsPath ) -> Sysroot {
147181 let sysroot_input = self . sysroot . as_ref ( ) . map ( |p| join_path_buf ( dir, p) ) ;
148182 let sysroot_src_input = self . sysroot_src . as_ref ( ) . map ( |p| join_path_buf ( dir, p) ) ;
0 commit comments