@@ -98,7 +98,7 @@ impl fmt::Display for VsInstallError {
98
98
}
99
99
}
100
100
101
- pub ( crate ) fn try_install_msvc ( ) -> Result < ( ) > {
101
+ pub ( crate ) fn try_install_msvc ( opts : & InstallOpts < ' _ > ) -> Result < ( ) > {
102
102
// download the installer
103
103
let visual_studio_url = utils:: parse_url ( "https://aka.ms/vs/17/release/vs_community.exe" ) ?;
104
104
@@ -131,16 +131,7 @@ pub(crate) fn try_install_msvc() -> Result<()> {
131
131
132
132
// It's possible an earlier or later version of the Windows SDK has been
133
133
// installed separately from Visual Studio so installing it can be skipped.
134
- let mut has_libs = false ;
135
- if let Some ( paths) = process ( ) . var_os ( "lib" ) {
136
- for mut path in split_paths ( & paths) {
137
- path. push ( "kernel32.lib" ) ;
138
- if path. exists ( ) {
139
- has_libs = true ;
140
- }
141
- }
142
- } ;
143
- if !has_libs {
134
+ if !has_windows_sdk_libs ( ) {
144
135
cmd. args ( [
145
136
"--add" ,
146
137
"Microsoft.VisualStudio.Component.Windows11SDK.22000" ,
@@ -156,10 +147,34 @@ pub(crate) fn try_install_msvc() -> Result<()> {
156
147
if exit_status. success ( ) {
157
148
Ok ( ( ) )
158
149
} else {
159
- Err ( VsInstallError ( exit_status. code ( ) . unwrap ( ) ) ) . context ( "failed to install Visual Studio" )
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" )
162
+ }
160
163
}
161
164
}
162
165
166
+ fn has_windows_sdk_libs ( ) -> bool {
167
+ if let Some ( paths) = process ( ) . var_os ( "lib" ) {
168
+ for mut path in split_paths ( & paths) {
169
+ path. push ( "kernel32.lib" ) ;
170
+ if path. exists ( ) {
171
+ return true ;
172
+ }
173
+ }
174
+ } ;
175
+ false
176
+ }
177
+
163
178
/// Run by rustup-gc-$num.exe to delete CARGO_HOME
164
179
pub fn complete_windows_uninstall ( ) -> Result < utils:: ExitCode > {
165
180
use std:: process:: Stdio ;
0 commit comments