@@ -55,9 +55,10 @@ impl RustToolingEnvironmentInfo {
55
55
// To display appropriate versions preventing `rustc` from downloading toolchains, we have to
56
56
// check
57
57
// 1. `$RUSTUP_TOOLCHAIN`
58
- // 2. `rustup override list`
58
+ // 2. The override list from ~/.rustup/settings.toml (like `rustup override list`)
59
59
// 3. `rust-toolchain` or `rust-toolchain.toml` in `.` or parent directories
60
- // 4. `rustup default`
60
+ // 4. The `default_toolchain` from ~/.rustup/settings.toml (like `rustup default`)
61
+ // 5. `rustup default` (in addition to the above, this also looks at global fallback config files)
61
62
// as `rustup` does.
62
63
// https://github.com/rust-lang/rustup.rs/tree/eb694fcada7becc5d9d160bf7c623abe84f8971d#override-precedence
63
64
//
@@ -74,6 +75,11 @@ impl RustToolingEnvironmentInfo {
74
75
. lookup_override ( context. current_dir . as_path ( ) )
75
76
} )
76
77
. or_else ( || find_rust_toolchain_file ( context) )
78
+ . or_else ( || {
79
+ self . get_rustup_settings ( context)
80
+ . default_toolchain ( )
81
+ . map ( std:: string:: ToString :: to_string)
82
+ } )
77
83
. or_else ( || execute_rustup_default ( context) ) ;
78
84
79
85
log:: debug!( "Environmental toolchain override is {:?}" , out) ;
@@ -87,12 +93,32 @@ impl RustToolingEnvironmentInfo {
87
93
fn get_rustup_rustc_version ( & self , context : & Context ) -> & RustupRunRustcVersionOutcome {
88
94
self . rustup_rustc_output . get_or_init ( || {
89
95
let out = if let Some ( toolchain) = self . get_env_toolchain_override ( context) {
90
- create_command ( "rustup" )
91
- . and_then ( |mut cmd| {
92
- cmd. args ( & [ "run" , toolchain, "rustc" , "--version" ] )
93
- . current_dir ( & context. current_dir )
94
- . output ( )
96
+ // First try runnig ~/.rustup/toolchains/<toolchain>/bin/rustc --version
97
+ rustup_home ( )
98
+ . map ( |rustup_folder| {
99
+ rustup_folder
100
+ . join ( "toolchains" )
101
+ . join ( toolchain)
102
+ . join ( "bin" )
103
+ . join ( "rustc" )
104
+ } )
105
+ . and_then ( |rustc| {
106
+ log:: trace!( "Running rustc --version directly with {:?}" , rustc) ;
107
+ create_command ( rustc) . map ( |mut cmd| {
108
+ cmd. arg ( "--version" ) ;
109
+ cmd
110
+ } )
111
+ } )
112
+ . or_else ( |_| {
113
+ // If that fails, try running rustup rustup run <toolchain> rustc --version
114
+ // Depending on the source of the toolchain override, it might not have been a full toolchain name ("stable" or "nightly").
115
+ log:: trace!( "Running rustup {toolchain} rustc --version" ) ;
116
+ create_command ( "rustup" ) . map ( |mut cmd| {
117
+ cmd. args ( & [ "run" , toolchain, "rustc" , "--version" ] ) ;
118
+ cmd
119
+ } )
95
120
} )
121
+ . and_then ( |mut cmd| cmd. current_dir ( & context. current_dir ) . output ( ) )
96
122
. map ( extract_toolchain_from_rustup_run_rustc_version)
97
123
. unwrap_or ( RustupRunRustcVersionOutcome :: RustupNotWorking )
98
124
} else {
0 commit comments