@@ -992,6 +992,20 @@ fn link_natively(
992
992
993
993
match prog {
994
994
Ok ( prog) => {
995
+ let is_msvc_link_exe = if let Some ( code) = prog. status . code ( ) {
996
+ sess. target . is_like_msvc
997
+ && flavor == LinkerFlavor :: Msvc ( Lld :: No )
998
+ // Respect the command line override
999
+ && sess. opts . cg . linker . is_none ( )
1000
+ // Match exactly "link.exe"
1001
+ && linker_path. to_str ( ) == Some ( "link.exe" )
1002
+ // All Microsoft `link.exe` linking error codes are
1003
+ // four digit numbers in the range 1000 to 9999 inclusive
1004
+ && ( code < 1000 || code > 9999 )
1005
+ } else {
1006
+ false
1007
+ } ;
1008
+
995
1009
if !prog. status . success ( ) {
996
1010
let mut output = prog. stderr . clone ( ) ;
997
1011
output. extend_from_slice ( & prog. stdout ) ;
@@ -1007,44 +1021,52 @@ fn link_natively(
1007
1021
// If MSVC's `link.exe` was expected but the return code
1008
1022
// is not a Microsoft LNK error then suggest a way to fix or
1009
1023
// install the Visual Studio build tools.
1010
- if let Some ( code) = prog. status . code ( ) {
1011
- if sess. target . is_like_msvc
1012
- && flavor == LinkerFlavor :: Msvc ( Lld :: No )
1013
- // Respect the command line override
1014
- && sess. opts . cg . linker . is_none ( )
1015
- // Match exactly "link.exe"
1016
- && linker_path. to_str ( ) == Some ( "link.exe" )
1017
- // All Microsoft `link.exe` linking error codes are
1018
- // four digit numbers in the range 1000 to 9999 inclusive
1019
- && ( code < 1000 || code > 9999 )
1020
- {
1021
- let is_vs_installed = windows_registry:: find_vs_version ( ) . is_ok ( ) ;
1022
- let has_linker =
1023
- windows_registry:: find_tool ( & sess. target . arch , "link.exe" ) . is_some ( ) ;
1024
-
1025
- sess. dcx ( ) . emit_note ( errors:: LinkExeUnexpectedError ) ;
1026
- if is_vs_installed && has_linker {
1027
- // the linker is broken
1028
- sess. dcx ( ) . emit_note ( errors:: RepairVSBuildTools ) ;
1029
- sess. dcx ( ) . emit_note ( errors:: MissingCppBuildToolComponent ) ;
1030
- } else if is_vs_installed {
1031
- // the linker is not installed
1032
- sess. dcx ( ) . emit_note ( errors:: SelectCppBuildToolWorkload ) ;
1033
- } else {
1034
- // visual studio is not installed
1035
- sess. dcx ( ) . emit_note ( errors:: VisualStudioNotInstalled ) ;
1036
- }
1024
+ if is_msvc_link_exe {
1025
+ let is_vs_installed = windows_registry:: find_vs_version ( ) . is_ok ( ) ;
1026
+ let has_linker =
1027
+ windows_registry:: find_tool ( & sess. target . arch , "link.exe" ) . is_some ( ) ;
1028
+
1029
+ sess. dcx ( ) . emit_note ( errors:: LinkExeUnexpectedError ) ;
1030
+ if is_vs_installed && has_linker {
1031
+ // the linker is broken
1032
+ sess. dcx ( ) . emit_note ( errors:: RepairVSBuildTools ) ;
1033
+ sess. dcx ( ) . emit_note ( errors:: MissingCppBuildToolComponent ) ;
1034
+ } else if is_vs_installed {
1035
+ // the linker is not installed
1036
+ sess. dcx ( ) . emit_note ( errors:: SelectCppBuildToolWorkload ) ;
1037
+ } else {
1038
+ // visual studio is not installed
1039
+ sess. dcx ( ) . emit_note ( errors:: VisualStudioNotInstalled ) ;
1037
1040
}
1038
1041
}
1039
1042
1040
1043
sess. dcx ( ) . abort_if_errors ( ) ;
1041
1044
}
1042
1045
1043
1046
let stderr = escape_string ( & prog. stderr ) ;
1044
- let stdout = escape_string ( & prog. stdout ) ;
1047
+ let mut stdout = escape_string ( & prog. stdout ) ;
1045
1048
info ! ( "linker stderr:\n {}" , & stderr) ;
1046
1049
info ! ( "linker stdout:\n {}" , & stdout) ;
1047
1050
1051
+ // Hide some progress messages from link.exe that we don't care about.
1052
+ // See https://github.com/chromium/chromium/blob/bfa41e41145ffc85f041384280caf2949bb7bd72/build/toolchain/win/tool_wrapper.py#L144-L146
1053
+ if is_msvc_link_exe {
1054
+ if let Ok ( str) = str:: from_utf8 ( & prog. stdout ) {
1055
+ let mut output = String :: with_capacity ( str. len ( ) ) ;
1056
+ for line in stdout. lines ( ) {
1057
+ if line. starts_with ( " Creating library" )
1058
+ || line. starts_with ( "Generating code" )
1059
+ || line. starts_with ( "Finished generating code" )
1060
+ {
1061
+ continue ;
1062
+ }
1063
+ output += line;
1064
+ output += "\r \n "
1065
+ }
1066
+ stdout = escape_string ( output. trim ( ) . as_bytes ( ) )
1067
+ }
1068
+ }
1069
+
1048
1070
let ( level, src) = codegen_results. crate_info . lint_levels . linker_messages ;
1049
1071
let lint = |msg| {
1050
1072
lint_level ( sess, LINKER_MESSAGES , level, src, None , |diag| {
@@ -1060,7 +1082,7 @@ fn link_natively(
1060
1082
. replace ( ": warning: " , ": " ) ;
1061
1083
lint ( format ! ( "linker stderr: {stderr}" ) ) ;
1062
1084
}
1063
- if !prog . stdout . is_empty ( ) {
1085
+ if !stdout. is_empty ( ) {
1064
1086
lint ( format ! ( "linker stdout: {}" , stdout) )
1065
1087
}
1066
1088
}
0 commit comments