@@ -15,7 +15,7 @@ use super::linker::Linker;
1515use super :: rpath:: RPathConfig ;
1616use super :: rpath;
1717use metadata:: METADATA_FILENAME ;
18- use rustc:: session:: config:: { self , NoDebugInfo , OutputFilenames , OutputType } ;
18+ use rustc:: session:: config:: { self , NoDebugInfo , OutputFilenames , OutputType , PrintRequest } ;
1919use rustc:: session:: filesearch;
2020use rustc:: session:: search_paths:: PathKind ;
2121use rustc:: session:: Session ;
@@ -647,11 +647,20 @@ fn link_staticlib(sess: &Session,
647647 ab. build ( ) ;
648648
649649 if !all_native_libs. is_empty ( ) {
650- sess. note_without_error ( "link against the following native artifacts when linking against \
651- this static library") ;
652- sess. note_without_error ( "the order and any duplication can be significant on some \
653- platforms, and so may need to be preserved") ;
650+ if sess. opts . prints . contains ( & PrintRequest :: NativeStaticLibs ) {
651+ print_native_static_libs ( sess, & all_native_libs) ;
652+ } else {
653+ // Fallback for backwards compatibility only
654+ print_native_static_libs_legacy ( sess, & all_native_libs) ;
655+ }
654656 }
657+ }
658+
659+ fn print_native_static_libs_legacy ( sess : & Session , all_native_libs : & [ NativeLibrary ] ) {
660+ sess. note_without_error ( "link against the following native artifacts when linking against \
661+ this static library") ;
662+ sess. note_without_error ( "This list will not be printed by default. \
663+ Please add --print=native-static-libs if you need this information") ;
655664
656665 for lib in all_native_libs. iter ( ) . filter ( |l| relevant_lib ( sess, l) ) {
657666 let name = match lib. kind {
@@ -665,6 +674,35 @@ fn link_staticlib(sess: &Session,
665674 }
666675}
667676
677+ fn print_native_static_libs ( sess : & Session , all_native_libs : & [ NativeLibrary ] ) {
678+ let lib_args: Vec < _ > = all_native_libs. iter ( )
679+ . filter ( |l| relevant_lib ( sess, l) )
680+ . filter_map ( |lib| match lib. kind {
681+ NativeLibraryKind :: NativeStaticNobundle |
682+ NativeLibraryKind :: NativeUnknown => {
683+ if sess. target . target . options . is_like_msvc {
684+ Some ( format ! ( "{}.lib" , lib. name) )
685+ } else {
686+ Some ( format ! ( "-l{}" , lib. name) )
687+ }
688+ } ,
689+ NativeLibraryKind :: NativeFramework => {
690+ // ld-only syntax, since there are no frameworks in MSVC
691+ Some ( format ! ( "-framework {}" , lib. name) )
692+ } ,
693+ // These are included, no need to print them
694+ NativeLibraryKind :: NativeStatic => None ,
695+ } )
696+ . collect ( ) ;
697+ if !lib_args. is_empty ( ) {
698+ sess. note_without_error ( "Link against the following native artifacts when linking \
699+ against this static library. The order and any duplication \
700+ can be significant on some platforms.") ;
701+ // Prefix for greppability
702+ sess. note_without_error ( & format ! ( "native-static-libs: {}" , & lib_args. join( " " ) ) ) ;
703+ }
704+ }
705+
668706// Create a dynamic library or executable
669707//
670708// This will invoke the system linker/cc to create the resulting file. This
0 commit comments