@@ -15,7 +15,7 @@ use super::linker::Linker;
15
15
use super :: rpath:: RPathConfig ;
16
16
use super :: rpath;
17
17
use metadata:: METADATA_FILENAME ;
18
- use rustc:: session:: config:: { self , NoDebugInfo , OutputFilenames , OutputType } ;
18
+ use rustc:: session:: config:: { self , NoDebugInfo , OutputFilenames , OutputType , PrintRequest } ;
19
19
use rustc:: session:: filesearch;
20
20
use rustc:: session:: search_paths:: PathKind ;
21
21
use rustc:: session:: Session ;
@@ -647,11 +647,20 @@ fn link_staticlib(sess: &Session,
647
647
ab. build ( ) ;
648
648
649
649
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
+ }
654
656
}
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") ;
655
664
656
665
for lib in all_native_libs. iter ( ) . filter ( |l| relevant_lib ( sess, l) ) {
657
666
let name = match lib. kind {
@@ -665,6 +674,35 @@ fn link_staticlib(sess: &Session,
665
674
}
666
675
}
667
676
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
+
668
706
// Create a dynamic library or executable
669
707
//
670
708
// This will invoke the system linker/cc to create the resulting file. This
0 commit comments