Skip to content

Commit 096a517

Browse files
committed
Move windows-only self_update code into windows module
1 parent 615424b commit 096a517

File tree

2 files changed

+88
-84
lines changed

2 files changed

+88
-84
lines changed

src/cli/self_update.rs

Lines changed: 1 addition & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -454,44 +454,6 @@ This will uninstall all Rust toolchains and data, and remove
454454
};
455455
}
456456

457-
#[cfg(windows)]
458-
static MSVC_MESSAGE: &str = r#"# Rust Visual C++ prerequisites
459-
460-
Rust requires the Microsoft C++ build tools for Visual Studio 2017 or
461-
later, but they don't seem to be installed.
462-
463-
"#;
464-
465-
#[cfg(windows)]
466-
static MSVC_MANUAL_INSTALL_MESSAGE: &str = r#"
467-
You can acquire the build tools by installing Microsoft Visual Studio.
468-
469-
https://visualstudio.microsoft.com/downloads/
470-
471-
Check the box for "Desktop development with C++" which will ensure that the
472-
needed components are installed. If your locale language is not English,
473-
then additionally check the box for English under Language packs.
474-
475-
For more details see:
476-
477-
https://rust-lang.github.io/rustup/installation/windows-msvc.html
478-
479-
_Install the C++ build tools before proceeding_.
480-
481-
If you will be targeting the GNU ABI or otherwise know what you are
482-
doing then it is fine to continue installation without the build
483-
tools, but otherwise, install the C++ build tools before proceeding.
484-
"#;
485-
486-
#[cfg(windows)]
487-
static MSVC_AUTO_INSTALL_MESSAGE: &str = r#"# Rust Visual C++ prerequisites
488-
489-
Rust requires a linker and Windows API libraries but they don't seem to be available.
490-
491-
These components can be acquired through a Visual Studio installer.
492-
493-
"#;
494-
495457
static DEFAULT_UPDATE_ROOT: &str = "https://static.rust-lang.org/rustup";
496458

497459
fn update_root(process: &Process) -> String {
@@ -563,49 +525,7 @@ pub(crate) async fn install(
563525
let mut term = process.stdout().terminal(process);
564526

565527
#[cfg(windows)]
566-
if let Some(plan) = windows::do_msvc_check(&opts, process) {
567-
use windows::{VsInstallPlan, ContinueInstall};
568-
if no_prompt {
569-
warn!("installing msvc toolchain without its prerequisites");
570-
} else if !quiet && plan == VsInstallPlan::Automatic {
571-
md(&mut term, MSVC_AUTO_INSTALL_MESSAGE);
572-
match windows::choose_vs_install(process)? {
573-
Some(VsInstallPlan::Automatic) => {
574-
match windows::try_install_msvc(&opts, process).await {
575-
Err(e) => {
576-
// Make sure the console doesn't exit before the user can
577-
// see the error and give the option to continue anyway.
578-
report_error(&e, process);
579-
if !common::question_bool("\nContinue?", false, process)? {
580-
info!("aborting installation");
581-
return Ok(utils::ExitCode(0));
582-
}
583-
}
584-
Ok(ContinueInstall::No) => {
585-
windows::ensure_prompt(process)?;
586-
return Ok(utils::ExitCode(0));
587-
}
588-
_ => {}
589-
}
590-
}
591-
Some(VsInstallPlan::Manual) => {
592-
md(&mut term, MSVC_MANUAL_INSTALL_MESSAGE);
593-
if !common::question_bool("\nContinue?", false, process)? {
594-
info!("aborting installation");
595-
return Ok(utils::ExitCode(0));
596-
}
597-
}
598-
None => {}
599-
}
600-
} else {
601-
md(&mut term, MSVC_MESSAGE);
602-
md(&mut term, MSVC_MANUAL_INSTALL_MESSAGE);
603-
if !common::question_bool("\nContinue?", false, process)? {
604-
info!("aborting installation");
605-
return Ok(utils::ExitCode(0));
606-
}
607-
}
608-
}
528+
windows::maybe_install_msvc(&mut term, no_prompt, quiet, &opts, process).await?;
609529

610530
if !no_prompt {
611531
let msg = pre_install_msg(opts.no_modify_path, process)?;

src/cli/self_update/windows.rs

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use tracing::{info, warn};
1212

1313
use super::super::errors::*;
1414
use super::common;
15-
use super::{install_bins, InstallOpts};
16-
use crate::cli::download_tracker::DownloadTracker;
17-
use crate::currentprocess::Process;
15+
use super::{install_bins, report_error, InstallOpts};
16+
use crate::cli::{download_tracker::DownloadTracker, markdown::md};
17+
use crate::currentprocess::{terminalsource::ColorableTerminal, Process};
1818
use crate::dist::TargetTriple;
1919
use crate::utils::utils;
2020
use crate::utils::Notification;
@@ -84,6 +84,90 @@ pub(crate) fn choose_vs_install(process: &Process) -> Result<Option<VsInstallPla
8484
Ok(plan)
8585
}
8686

87+
pub(super) async fn maybe_install_msvc(
88+
term: &mut ColorableTerminal,
89+
no_prompt: bool,
90+
quiet: bool,
91+
opts: &InstallOpts<'_>,
92+
process: &Process,
93+
) -> Result<()> {
94+
let Some(plan) = do_msvc_check(opts, process) else {
95+
return Ok(());
96+
};
97+
98+
if no_prompt {
99+
warn!("installing msvc toolchain without its prerequisites");
100+
} else if !quiet && plan == VsInstallPlan::Automatic {
101+
md(term, MSVC_AUTO_INSTALL_MESSAGE);
102+
match choose_vs_install(process)? {
103+
Some(VsInstallPlan::Automatic) => {
104+
match try_install_msvc(opts, process).await {
105+
Err(e) => {
106+
// Make sure the console doesn't exit before the user can
107+
// see the error and give the option to continue anyway.
108+
report_error(&e, process);
109+
if !common::question_bool("\nContinue?", false, process)? {
110+
info!("aborting installation");
111+
}
112+
}
113+
Ok(ContinueInstall::No) => ensure_prompt(process)?,
114+
_ => {}
115+
}
116+
}
117+
Some(VsInstallPlan::Manual) => {
118+
md(term, MSVC_MANUAL_INSTALL_MESSAGE);
119+
if !common::question_bool("\nContinue?", false, process)? {
120+
info!("aborting installation");
121+
}
122+
}
123+
None => {}
124+
}
125+
} else {
126+
md(term, MSVC_MESSAGE);
127+
md(term, MSVC_MANUAL_INSTALL_MESSAGE);
128+
if !common::question_bool("\nContinue?", false, process)? {
129+
info!("aborting installation");
130+
}
131+
}
132+
133+
Ok(())
134+
}
135+
136+
static MSVC_MESSAGE: &str = r#"# Rust Visual C++ prerequisites
137+
138+
Rust requires the Microsoft C++ build tools for Visual Studio 2017 or
139+
later, but they don't seem to be installed.
140+
141+
"#;
142+
143+
static MSVC_MANUAL_INSTALL_MESSAGE: &str = r#"
144+
You can acquire the build tools by installing Microsoft Visual Studio.
145+
146+
https://visualstudio.microsoft.com/downloads/
147+
148+
Check the box for "Desktop development with C++" which will ensure that the
149+
needed components are installed. If your locale language is not English,
150+
then additionally check the box for English under Language packs.
151+
152+
For more details see:
153+
154+
https://rust-lang.github.io/rustup/installation/windows-msvc.html
155+
156+
_Install the C++ build tools before proceeding_.
157+
158+
If you will be targeting the GNU ABI or otherwise know what you are
159+
doing then it is fine to continue installation without the build
160+
tools, but otherwise, install the C++ build tools before proceeding.
161+
"#;
162+
163+
static MSVC_AUTO_INSTALL_MESSAGE: &str = r#"# Rust Visual C++ prerequisites
164+
165+
Rust requires a linker and Windows API libraries but they don't seem to be available.
166+
167+
These components can be acquired through a Visual Studio installer.
168+
169+
"#;
170+
87171
#[derive(PartialEq, Eq)]
88172
pub(crate) enum VsInstallPlan {
89173
Automatic,

0 commit comments

Comments
 (0)