@@ -12,9 +12,9 @@ use tracing::{info, warn};
12
12
13
13
use super :: super :: errors:: * ;
14
14
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 } ;
18
18
use crate :: dist:: TargetTriple ;
19
19
use crate :: utils:: utils;
20
20
use crate :: utils:: Notification ;
@@ -84,6 +84,90 @@ pub(crate) fn choose_vs_install(process: &Process) -> Result<Option<VsInstallPla
84
84
Ok ( plan)
85
85
}
86
86
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 ( "\n Continue?" , 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 ( "\n Continue?" , 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 ( "\n Continue?" , 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
+
87
171
#[ derive( PartialEq , Eq ) ]
88
172
pub ( crate ) enum VsInstallPlan {
89
173
Automatic ,
0 commit comments