Skip to content

Commit 3277323

Browse files
authored
Merge pull request #3008 from ChrisDenton/vs-install-instructions
Visual Studio: Let the user choose install method
2 parents dc93d52 + ab5eb0b commit 3277323

File tree

2 files changed

+76
-22
lines changed

2 files changed

+76
-22
lines changed

src/cli/self_update.rs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ static MSVC_AUTO_INSTALL_MESSAGE: &str = r#"# Rust Visual C++ prerequisites
313313
314314
Rust requires a linker and Windows API libraries but they don't seem to be available.
315315
316-
These components can be acquired by installing Visual Studio.
316+
These components can be acquired through a Visual Studio installer.
317317
318318
"#;
319319

@@ -376,37 +376,38 @@ pub(crate) fn install(
376376
warn!("installing msvc toolchain without its prerequisites");
377377
} else if !quiet && plan == VsInstallPlan::Automatic {
378378
md(&mut term, MSVC_AUTO_INSTALL_MESSAGE);
379-
if common::confirm(
380-
"\nAutomatically download and install Visual Studio 2022 Community edition? (Y/n)",
381-
true,
382-
)? {
383-
match try_install_msvc(&opts) {
384-
Err(e) => {
385-
// Make sure the console doesn't exit before the user can
386-
// see the error and give the option to continue anyway.
387-
report_error(&e);
388-
if !common::confirm("\nContinue installing rustup? (y/N)", false)? {
389-
info!("aborting installation");
379+
match windows::choose_vs_install()? {
380+
Some(VsInstallPlan::Automatic) => {
381+
match try_install_msvc(&opts) {
382+
Err(e) => {
383+
// Make sure the console doesn't exit before the user can
384+
// see the error and give the option to continue anyway.
385+
report_error(&e);
386+
if !common::question_bool("\nContinue?", false)? {
387+
info!("aborting installation");
388+
return Ok(utils::ExitCode(0));
389+
}
390+
}
391+
Ok(ContinueInstall::No) => {
392+
ensure_prompt()?;
390393
return Ok(utils::ExitCode(0));
391394
}
395+
_ => {}
392396
}
393-
Ok(ContinueInstall::No) => {
394-
ensure_prompt()?;
397+
}
398+
Some(VsInstallPlan::Manual) => {
399+
md(&mut term, MSVC_MANUAL_INSTALL_MESSAGE);
400+
if !common::question_bool("\nContinue?", false)? {
401+
info!("aborting installation");
395402
return Ok(utils::ExitCode(0));
396403
}
397-
_ => {}
398-
}
399-
} else {
400-
md(&mut term, MSVC_MANUAL_INSTALL_MESSAGE);
401-
if !common::confirm("\nContinue? (y/N)", false)? {
402-
info!("aborting installation");
403-
return Ok(utils::ExitCode(0));
404404
}
405+
None => {}
405406
}
406407
} else {
407408
md(&mut term, MSVC_MESSAGE);
408409
md(&mut term, MSVC_MANUAL_INSTALL_MESSAGE);
409-
if !common::confirm("\nContinue? (y/N)", false)? {
410+
if !common::question_bool("\nContinue?", false)? {
410411
info!("aborting installation");
411412
return Ok(utils::ExitCode(0));
412413
}

src/cli/self_update/windows.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::cell::RefCell;
22
use std::env::{consts::EXE_SUFFIX, split_paths};
33
use std::ffi::{OsStr, OsString};
44
use std::fmt;
5+
use std::io::Write;
56
use std::os::windows::ffi::{OsStrExt, OsStringExt};
67
use std::path::Path;
78
use std::process::Command;
@@ -27,6 +28,58 @@ pub(crate) fn ensure_prompt() -> Result<()> {
2728
Ok(())
2829
}
2930

31+
fn choice(max: u8) -> Result<Option<u8>> {
32+
write!(process().stdout(), ">")?;
33+
34+
let _ = std::io::stdout().flush();
35+
let input = common::read_line()?;
36+
37+
let r = match str::parse(&input) {
38+
Ok(n) if n <= max => Some(n),
39+
_ => None,
40+
};
41+
42+
writeln!(process().stdout())?;
43+
Ok(r)
44+
}
45+
46+
pub(crate) fn choose_vs_install() -> Result<Option<VsInstallPlan>> {
47+
writeln!(
48+
process().stdout(),
49+
"\n1) Quick install via the Visual Studio Community installer"
50+
)?;
51+
writeln!(
52+
process().stdout(),
53+
" (free for individuals, academic uses, and open source)."
54+
)?;
55+
writeln!(
56+
process().stdout(),
57+
"\n2) Manually install the prerequisites"
58+
)?;
59+
writeln!(
60+
process().stdout(),
61+
" (for enterprise and advanced users)."
62+
)?;
63+
writeln!(process().stdout(), "\n3) Don't install the prerequisites")?;
64+
writeln!(
65+
process().stdout(),
66+
" (if you're targetting the GNU ABI).\n"
67+
)?;
68+
69+
let choice = loop {
70+
if let Some(n) = choice(3)? {
71+
break n;
72+
}
73+
writeln!(process().stdout(), "Select option 1, 2 or 3")?;
74+
};
75+
let plan = match choice {
76+
1 => Some(VsInstallPlan::Automatic),
77+
2 => Some(VsInstallPlan::Manual),
78+
_ => None,
79+
};
80+
Ok(plan)
81+
}
82+
3083
#[derive(PartialEq, Eq)]
3184
pub(crate) enum VsInstallPlan {
3285
Automatic,

0 commit comments

Comments
 (0)