@@ -992,6 +992,11 @@ fn link_natively(
992992
993993 match prog {
994994 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+
9951000 if !prog. status . success ( ) {
9961001 let mut output = prog. stderr . clone ( ) ;
9971002 output. extend_from_slice ( & prog. stdout ) ;
@@ -1008,16 +1013,9 @@ fn link_natively(
10081013 // is not a Microsoft LNK error then suggest a way to fix or
10091014 // install the Visual Studio build tools.
10101015 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 ) {
10211019 let is_vs_installed = windows_registry:: find_vs_version ( ) . is_ok ( ) ;
10221020 let has_linker =
10231021 windows_registry:: find_tool ( & sess. target . arch , "link.exe" ) . is_some ( ) ;
@@ -1041,10 +1039,29 @@ fn link_natively(
10411039 }
10421040
10431041 let stderr = escape_string ( & prog. stderr ) ;
1044- let stdout = escape_string ( & prog. stdout ) ;
1042+ let mut stdout = escape_string ( & prog. stdout ) ;
10451043 info ! ( "linker stderr:\n {}" , & stderr) ;
10461044 info ! ( "linker stdout:\n {}" , & stdout) ;
10471045
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+
10481065 let ( level, src) = codegen_results. crate_info . lint_levels . linker_messages ;
10491066 let lint = |msg| {
10501067 lint_level ( sess, LINKER_MESSAGES , level, src, None , |diag| {
@@ -1060,7 +1077,7 @@ fn link_natively(
10601077 . replace ( ": warning: " , ": " ) ;
10611078 lint ( format ! ( "linker stderr: {stderr}" ) ) ;
10621079 }
1063- if !prog . stdout . is_empty ( ) {
1080+ if !stdout. is_empty ( ) {
10641081 lint ( format ! ( "linker stdout: {}" , stdout) )
10651082 }
10661083 }
0 commit comments