@@ -992,6 +992,11 @@ fn link_natively(
992
992
993
993
match prog {
994
994
Ok ( prog) => {
995
+ let is_msvc_link_exe = sess. target . is_like_msvc
996
+ && flavor == LinkerFlavor :: Msvc ( Lld :: No )
997
+ // Match exactly "link.exe"
998
+ && linker_path. to_str ( ) == Some ( "link.exe" ) ;
999
+
995
1000
if !prog. status . success ( ) {
996
1001
let mut output = prog. stderr . clone ( ) ;
997
1002
output. extend_from_slice ( & prog. stdout ) ;
@@ -1008,16 +1013,9 @@ fn link_natively(
1008
1013
// is not a Microsoft LNK error then suggest a way to fix or
1009
1014
// install the Visual Studio build tools.
1010
1015
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
- {
1016
+ // All Microsoft `link.exe` linking ror codes are
1017
+ // four digit numbers in the range 1000 to 9999 inclusive
1018
+ if is_msvc_link_exe && ( code < 1000 || code > 9999 ) {
1021
1019
let is_vs_installed = windows_registry:: find_vs_version ( ) . is_ok ( ) ;
1022
1020
let has_linker =
1023
1021
windows_registry:: find_tool ( & sess. target . arch , "link.exe" ) . is_some ( ) ;
@@ -1041,10 +1039,29 @@ fn link_natively(
1041
1039
}
1042
1040
1043
1041
let stderr = escape_string ( & prog. stderr ) ;
1044
- let stdout = escape_string ( & prog. stdout ) ;
1042
+ let mut stdout = escape_string ( & prog. stdout ) ;
1045
1043
info ! ( "linker stderr:\n {}" , & stderr) ;
1046
1044
info ! ( "linker stdout:\n {}" , & stdout) ;
1047
1045
1046
+ // Hide some progress messages from link.exe that we don't care about.
1047
+ // See https://github.com/chromium/chromium/blob/bfa41e41145ffc85f041384280caf2949bb7bd72/build/toolchain/win/tool_wrapper.py#L144-L146
1048
+ if is_msvc_link_exe {
1049
+ if let Ok ( str) = str:: from_utf8 ( & prog. stdout ) {
1050
+ let mut output = String :: with_capacity ( str. len ( ) ) ;
1051
+ for line in stdout. lines ( ) {
1052
+ if line. starts_with ( " Creating library" )
1053
+ || line. starts_with ( "Generating code" )
1054
+ || line. starts_with ( "Finished generating code" )
1055
+ {
1056
+ continue ;
1057
+ }
1058
+ output += line;
1059
+ output += "\r \n "
1060
+ }
1061
+ stdout = escape_string ( output. trim ( ) . as_bytes ( ) )
1062
+ }
1063
+ }
1064
+
1048
1065
let ( level, src) = codegen_results. crate_info . lint_levels . linker_messages ;
1049
1066
let lint = |msg| {
1050
1067
lint_level ( sess, LINKER_MESSAGES , level, src, None , |diag| {
@@ -1060,7 +1077,7 @@ fn link_natively(
1060
1077
. replace ( ": warning: " , ": " ) ;
1061
1078
lint ( format ! ( "linker stderr: {stderr}" ) ) ;
1062
1079
}
1063
- if !prog . stdout . is_empty ( ) {
1080
+ if !stdout. is_empty ( ) {
1064
1081
lint ( format ! ( "linker stdout: {}" , stdout) )
1065
1082
}
1066
1083
}
0 commit comments