@@ -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" ) ]
@@ -135,9 +137,41 @@ impl Config {
135137 extra_env. insert ( "RUSTFLAGS" . to_owned ( ) , Some ( "-Awarnings" . to_owned ( ) ) ) ;
136138 }
137139 extra_env. extend ( self . cargo_extra_env . clone ( ) ) ;
140+ // Always use the latest stable toolchain, irrespective of any toolchain
141+ // file in the project being extracted.
142+ extra_env. insert ( "RUSTUP_TOOLCHAIN" . to_owned ( ) , Some ( "stable" . to_owned ( ) ) ) ;
138143 extra_env
139144 }
140145
146+ pub ( crate ) fn apply_extra_env ( & self , command : & mut Command ) {
147+ for ( key, value) in self . get_extra_env ( ) {
148+ match value {
149+ Some ( value) => command. env ( key, value) ,
150+ None => command. env_remove ( key) ,
151+ } ;
152+ }
153+ }
154+
155+ pub ( crate ) fn log_effective_toolchain ( & self , dir : & AbsPath ) {
156+ let mut command = Command :: new ( "rustc" ) ;
157+ command
158+ . current_dir ( dir. as_str ( ) )
159+ . args ( [ "--version" , "--verbose" ] ) ;
160+ self . apply_extra_env ( & mut command) ;
161+
162+ match command. output ( ) {
163+ Ok ( output) if output. status . success ( ) => info ! (
164+ "effective Rust toolchain:\n {}" ,
165+ String :: from_utf8_lossy( & output. stdout) . trim( )
166+ ) ,
167+ Ok ( output) => warn ! (
168+ "unable to determine effective Rust toolchain: {}" ,
169+ String :: from_utf8_lossy( & output. stderr) . trim( )
170+ ) ,
171+ Err ( error) => warn ! ( "unable to determine effective Rust toolchain: {error}" ) ,
172+ }
173+ }
174+
141175 fn sysroot ( & self , dir : & AbsPath ) -> Sysroot {
142176 let sysroot_input = self . sysroot . as_ref ( ) . map ( |p| join_path_buf ( dir, p) ) ;
143177 let sysroot_src_input = self . sysroot_src . as_ref ( ) . map ( |p| join_path_buf ( dir, p) ) ;
0 commit comments