@@ -98,7 +98,7 @@ impl fmt::Display for VsInstallError {
9898 }
9999}
100100
101- pub ( crate ) fn try_install_msvc ( ) -> Result < ( ) > {
101+ pub ( crate ) fn try_install_msvc ( opts : & InstallOpts < ' _ > ) -> Result < ( ) > {
102102 // download the installer
103103 let visual_studio_url = utils:: parse_url ( "https://aka.ms/vs/17/release/vs_community.exe" ) ?;
104104
@@ -131,16 +131,7 @@ pub(crate) fn try_install_msvc() -> Result<()> {
131131
132132 // It's possible an earlier or later version of the Windows SDK has been
133133 // 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 ( ) {
144135 cmd. args ( [
145136 "--add" ,
146137 "Microsoft.VisualStudio.Component.Windows11SDK.22000" ,
@@ -156,10 +147,34 @@ pub(crate) fn try_install_msvc() -> Result<()> {
156147 if exit_status. success ( ) {
157148 Ok ( ( ) )
158149 } 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+ }
160163 }
161164}
162165
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+
163178/// Run by rustup-gc-$num.exe to delete CARGO_HOME
164179pub fn complete_windows_uninstall ( ) -> Result < utils:: ExitCode > {
165180 use std:: process:: Stdio ;
0 commit comments