@@ -66,7 +66,7 @@ pub(crate) fn do_msvc_check(opts: &InstallOpts<'_>) -> Option<VsInstallPlan> {
66
66
}
67
67
}
68
68
69
- #[ derive( Debug ) ]
69
+ #[ derive( Debug , Eq , PartialEq ) ]
70
70
struct VsInstallError ( i32 ) ;
71
71
impl std:: error:: Error for VsInstallError { }
72
72
impl fmt:: Display for VsInstallError {
@@ -97,8 +97,21 @@ impl fmt::Display for VsInstallError {
97
97
write ! ( f, "{} (exit code {})" , message, self . 0 )
98
98
}
99
99
}
100
+ impl VsInstallError {
101
+ const REBOOTING_NOW : Self = Self ( 1641 ) ;
102
+ const REBOOT_REQUIRED : Self = Self ( 3010 ) ;
103
+ }
104
+
105
+ pub ( crate ) enum ContinueInstall {
106
+ Yes ,
107
+ No ,
108
+ }
100
109
101
- pub ( crate ) fn try_install_msvc ( opts : & InstallOpts < ' _ > ) -> Result < ( ) > {
110
+ /// Tries to install the needed Visual Studio components.
111
+ ///
112
+ /// Returns `Ok(ContinueInstall::No)` if installing Visual Studio was successful
113
+ /// but the rustup install should not be continued at this time.
114
+ pub ( crate ) fn try_install_msvc ( opts : & InstallOpts < ' _ > ) -> Result < ContinueInstall > {
102
115
// download the installer
103
116
let visual_studio_url = utils:: parse_url ( "https://aka.ms/vs/17/release/vs_community.exe" ) ?;
104
117
@@ -145,20 +158,35 @@ pub(crate) fn try_install_msvc(opts: &InstallOpts<'_>) -> Result<()> {
145
158
. context ( "error running Visual Studio installer" ) ?;
146
159
147
160
if exit_status. success ( ) {
148
- Ok ( ( ) )
161
+ Ok ( ContinueInstall :: Yes )
149
162
} else {
150
- let err = VsInstallError ( exit_status. code ( ) . unwrap ( ) ) ;
151
- // It's possible that the installer returned a non-zero exit code
152
- // even though the required components were successfully installed.
153
- // In that case we warn about the error but continue on.
154
- let have_msvc = do_msvc_check ( opts) . is_none ( ) ;
155
- let has_libs = has_windows_sdk_libs ( ) ;
156
- if have_msvc && has_libs {
157
- warn ! ( "Visual Studio is installed but a problem ocurred during installation" ) ;
158
- warn ! ( "{}" , err) ;
159
- Ok ( ( ) )
160
- } else {
161
- Err ( err) . context ( "failed to install Visual Studio" )
163
+ match VsInstallError ( exit_status. code ( ) . unwrap ( ) ) {
164
+ err @ VsInstallError :: REBOOT_REQUIRED => {
165
+ // A reboot is required but the user opted to delay it.
166
+ warn ! ( "{}" , err) ;
167
+ Ok ( ContinueInstall :: Yes )
168
+ }
169
+ err @ VsInstallError :: REBOOTING_NOW => {
170
+ // The user is wanting to reboot right now, so we should
171
+ // not continue the install.
172
+ warn ! ( "{}" , err) ;
173
+ info ! ( "\n Run rustup-init after restart to continue install" ) ;
174
+ Ok ( ContinueInstall :: No )
175
+ }
176
+ err => {
177
+ // It's possible that the installer returned a non-zero exit code
178
+ // even though the required components were successfully installed.
179
+ // In that case we warn about the error but continue on.
180
+ let have_msvc = do_msvc_check ( opts) . is_none ( ) ;
181
+ let has_libs = has_windows_sdk_libs ( ) ;
182
+ if have_msvc && has_libs {
183
+ warn ! ( "Visual Studio is installed but a problem ocurred during installation" ) ;
184
+ warn ! ( "{}" , err) ;
185
+ Ok ( ContinueInstall :: Yes )
186
+ } else {
187
+ Err ( err) . context ( "failed to install Visual Studio" )
188
+ }
189
+ }
162
190
}
163
191
}
164
192
}
0 commit comments