@@ -51,6 +51,7 @@ use std::fs;
51
51
use std:: path:: { Component , Path , PathBuf , MAIN_SEPARATOR } ;
52
52
use std:: process:: Command ;
53
53
54
+ use cfg_if:: cfg_if;
54
55
use same_file:: Handle ;
55
56
56
57
use super :: common:: { self , ignorable_error, Confirm } ;
@@ -65,7 +66,9 @@ use crate::utils::Notification;
65
66
use crate :: { Cfg , UpdateStatus } ;
66
67
use crate :: { DUP_TOOLS , TOOLS } ;
67
68
use os:: * ;
68
- pub use os:: { complete_windows_uninstall, delete_rustup_and_cargo_home, run_update, self_replace} ;
69
+ pub use os:: { delete_rustup_and_cargo_home, run_update, self_replace} ;
70
+ #[ cfg( windows) ]
71
+ pub use windows:: complete_windows_uninstall;
69
72
70
73
pub struct InstallOpts < ' a > {
71
74
pub default_host_triple : Option < String > ,
@@ -123,7 +126,7 @@ these changes will be reverted.
123
126
} ;
124
127
}
125
128
126
- #[ cfg( unix ) ]
129
+ #[ cfg( not ( windows ) ) ]
127
130
macro_rules! pre_install_msg_unix {
128
131
( ) => {
129
132
pre_install_msg_template!(
@@ -154,6 +157,7 @@ but will not be added automatically."
154
157
} ;
155
158
}
156
159
160
+ #[ cfg( not( windows) ) ]
157
161
macro_rules! post_install_msg_unix {
158
162
( ) => {
159
163
r"# Rust is installed now. Great!
@@ -167,6 +171,7 @@ To configure your current shell run `source {cargo_home}/env`
167
171
} ;
168
172
}
169
173
174
+ #[ cfg( windows) ]
170
175
macro_rules! post_install_msg_win {
171
176
( ) => {
172
177
r"# Rust is installed now. Great!
@@ -178,6 +183,7 @@ correct environment, but you may need to restart your current shell.
178
183
} ;
179
184
}
180
185
186
+ #[ cfg( not( windows) ) ]
181
187
macro_rules! post_install_msg_unix_no_modify_path {
182
188
( ) => {
183
189
r"# Rust is installed now. Great!
@@ -190,6 +196,7 @@ To configure your current shell run `source {cargo_home}/env`
190
196
} ;
191
197
}
192
198
199
+ #[ cfg( windows) ]
193
200
macro_rules! post_install_msg_win_no_modify_path {
194
201
( ) => {
195
202
r"# Rust is installed now. Great!
@@ -211,6 +218,7 @@ This will uninstall all Rust toolchains and data, and remove
211
218
} ;
212
219
}
213
220
221
+ #[ cfg( windows) ]
214
222
static MSVC_MESSAGE : & str = r#"# Rust Visual C++ prerequisites
215
223
216
224
Rust requires the Microsoft C++ build tools for Visual Studio 2013 or
@@ -249,10 +257,12 @@ fn canonical_cargo_home() -> Result<Cow<'static, str>> {
249
257
. unwrap_or_else ( || PathBuf :: from ( "." ) )
250
258
. join ( ".cargo" ) ;
251
259
Ok ( if default_cargo_home == path {
252
- if cfg ! ( unix) {
253
- "$HOME/.cargo" . into ( )
254
- } else {
255
- r"%USERPROFILE%\.cargo" . into ( )
260
+ cfg_if ! {
261
+ if #[ cfg( windows) ] {
262
+ r"%USERPROFILE%\.cargo" . into( )
263
+ } else {
264
+ "$HOME/.cargo" . into( )
265
+ }
256
266
}
257
267
} else {
258
268
path. to_string_lossy ( ) . into_owned ( ) . into ( )
@@ -288,6 +298,8 @@ pub fn install(
288
298
do_anti_sudo_check ( no_prompt) ?;
289
299
290
300
let mut term = term2:: stdout ( ) ;
301
+
302
+ #[ cfg( windows) ]
291
303
if !do_msvc_check ( & opts) ? {
292
304
if no_prompt {
293
305
warn ! ( "installing msvc toolchain without its prerequisites" ) ;
@@ -349,10 +361,9 @@ pub fn install(
349
361
// that may have opened just for this purpose, give
350
362
// the user an opportunity to see the error before the
351
363
// window closes.
352
- if cfg ! ( windows) && !no_prompt {
353
- writeln ! ( process( ) . stdout( ) , ) ?;
354
- writeln ! ( process( ) . stdout( ) , "Press the Enter key to continue." ) ?;
355
- common:: read_line ( ) ?;
364
+ #[ cfg( windows) ]
365
+ if !no_prompt {
366
+ ensure_prompt ( ) ?;
356
367
}
357
368
358
369
return Ok ( utils:: ExitCode ( 1 ) ) ;
@@ -361,29 +372,32 @@ pub fn install(
361
372
let cargo_home = canonical_cargo_home ( ) ?;
362
373
#[ cfg( windows) ]
363
374
let cargo_home = cargo_home. replace ( '\\' , r"\\" ) ;
364
- let msg = match ( opts. no_modify_path , cfg ! ( unix) ) {
365
- ( false , true ) => format ! ( post_install_msg_unix!( ) , cargo_home = cargo_home) ,
366
- ( false , false ) => format ! ( post_install_msg_win!( ) , cargo_home = cargo_home) ,
367
- ( true , true ) => format ! (
368
- post_install_msg_unix_no_modify_path!( ) ,
369
- cargo_home = cargo_home
370
- ) ,
371
- ( true , false ) => format ! (
375
+ #[ cfg( windows) ]
376
+ let msg = if opts. no_modify_path {
377
+ format ! (
372
378
post_install_msg_win_no_modify_path!( ) ,
373
379
cargo_home = cargo_home
374
- ) ,
380
+ )
381
+ } else {
382
+ format ! ( post_install_msg_win!( ) , cargo_home = cargo_home)
383
+ } ;
384
+ #[ cfg( not( windows) ) ]
385
+ let msg = if opts. no_modify_path {
386
+ format ! (
387
+ post_install_msg_unix_no_modify_path!( ) ,
388
+ cargo_home = cargo_home
389
+ )
390
+ } else {
391
+ format ! ( post_install_msg_unix!( ) , cargo_home = cargo_home)
375
392
} ;
376
393
md ( & mut term, msg) ;
377
394
395
+ #[ cfg( windows) ]
378
396
if !no_prompt {
379
397
// On windows, where installation happens in a console
380
398
// that may have opened just for this purpose, require
381
399
// the user to press a key to continue.
382
- if cfg ! ( windows) {
383
- writeln ! ( process( ) . stdout( ) ) ?;
384
- writeln ! ( process( ) . stdout( ) , "Press the Enter key to continue." ) ?;
385
- common:: read_line ( ) ?;
386
- }
400
+ ensure_prompt ( ) ?;
387
401
}
388
402
389
403
Ok ( utils:: ExitCode ( 0 ) )
@@ -503,11 +517,6 @@ fn do_pre_install_options_sanity_checks(opts: &InstallOpts<'_>) -> Result<()> {
503
517
Ok ( ( ) )
504
518
}
505
519
506
- #[ cfg( not( windows) ) ]
507
- fn do_msvc_check ( _opts : & InstallOpts < ' _ > ) -> Result < bool > {
508
- Ok ( true )
509
- }
510
-
511
520
fn pre_install_msg ( no_modify_path : bool ) -> Result < String > {
512
521
let cargo_home = utils:: cargo_home ( ) ?;
513
522
let cargo_home_bin = cargo_home. join ( "bin" ) ;
@@ -988,19 +997,16 @@ pub fn prepare_update() -> Result<Option<PathBuf>> {
988
997
}
989
998
990
999
// Get build triple
991
- let build_triple = dist:: TargetTriple :: from_build ( ) ;
992
- let triple = if cfg ! ( windows) {
993
- // For windows x86 builds seem slow when used with windows defender.
994
- // The website defaulted to i686-windows-gnu builds for a long time.
995
- // This ensures that we update to a version thats appropriate for users
996
- // and also works around if the website messed up the detection.
997
- // If someone really wants to use another version, he still can enforce
998
- // that using the environment variable RUSTUP_OVERRIDE_HOST_TRIPLE.
999
-
1000
- dist:: TargetTriple :: from_host ( ) . unwrap_or ( build_triple)
1001
- } else {
1002
- build_triple
1003
- } ;
1000
+ let triple = dist:: TargetTriple :: from_build ( ) ;
1001
+
1002
+ // For windows x86 builds seem slow when used with windows defender.
1003
+ // The website defaulted to i686-windows-gnu builds for a long time.
1004
+ // This ensures that we update to a version thats appropriate for users
1005
+ // and also works around if the website messed up the detection.
1006
+ // If someone really wants to use another version, they still can enforce
1007
+ // that using the environment variable RUSTUP_OVERRIDE_HOST_TRIPLE.
1008
+ #[ cfg( windows) ]
1009
+ let triple = dist:: TargetTriple :: from_host ( ) . unwrap_or ( triple) ;
1004
1010
1005
1011
let update_root = process ( )
1006
1012
. var ( "RUSTUP_UPDATE_ROOT" )
0 commit comments