@@ -263,11 +263,12 @@ fn run_compiler(
263
263
}
264
264
let should_stop = RustcDefaultCalls :: print_crate_info (
265
265
& * * * compiler. codegen_backend ( ) ,
266
- compiler. session ( ) ,
266
+ & compiler,
267
267
None ,
268
268
& odir,
269
269
& ofile,
270
- ) ;
270
+ )
271
+ . unwrap_or ( Compilation :: Continue ) ;
271
272
272
273
if should_stop == Compilation :: Stop {
273
274
return ;
@@ -319,11 +320,11 @@ fn run_compiler(
319
320
let sess = compiler. session ( ) ;
320
321
let should_stop = RustcDefaultCalls :: print_crate_info (
321
322
& * * * compiler. codegen_backend ( ) ,
322
- sess ,
323
+ compiler ,
323
324
Some ( compiler. input ( ) ) ,
324
325
compiler. output_dir ( ) ,
325
326
compiler. output_file ( ) ,
326
- )
327
+ ) ?
327
328
. and_then ( || {
328
329
RustcDefaultCalls :: list_metadata (
329
330
sess,
@@ -593,7 +594,11 @@ fn handle_explain(registry: Registry, code: &str, output: ErrorOutputType) {
593
594
594
595
fn show_content_with_pager ( content : & str ) {
595
596
let pager_name = env:: var_os ( "PAGER" ) . unwrap_or_else ( || {
596
- if cfg ! ( windows) { OsString :: from ( "more.com" ) } else { OsString :: from ( "less" ) }
597
+ if cfg ! ( windows) {
598
+ OsString :: from ( "more.com" )
599
+ } else {
600
+ OsString :: from ( "less" )
601
+ }
597
602
} ) ;
598
603
599
604
let mut fallback_to_println = false ;
@@ -622,6 +627,60 @@ fn show_content_with_pager(content: &str) {
622
627
}
623
628
}
624
629
630
+ fn relevant_lib ( sess : & Session , lib : & NativeLib ) -> bool {
631
+ match lib. cfg {
632
+ Some ( ref cfg) => rustc_attr:: cfg_matches ( cfg, & sess. parse_sess , None ) ,
633
+ None => true ,
634
+ }
635
+ }
636
+
637
+ use rustc_codegen_ssa:: { CrateInfo , NativeLib } ;
638
+ use rustc_session:: utils:: NativeLibKind ;
639
+
640
+ fn print_native_static_libs ( compiler : & interface:: Compiler ) -> interface:: Result < ( ) > {
641
+ let sess = compiler. session ( ) ;
642
+ compiler. enter ( |queries| {
643
+ use rustc_codegen_ssa:: back:: link:: each_linked_rlib;
644
+ let mut all_native_libs = vec ! [ ] ;
645
+ queries. parse ( ) ?;
646
+ queries. global_ctxt ( ) ?. take ( ) . enter ( |tcx| {
647
+ let crate_info = CrateInfo :: new ( tcx) ;
648
+ let res = each_linked_rlib ( & crate_info, & mut |cnum, _path| {
649
+ all_native_libs. extend ( crate_info. native_libraries [ & cnum] . iter ( ) . cloned ( ) ) ;
650
+ } ) ;
651
+ if let Err ( e) = res {
652
+ sess. fatal ( & e) ;
653
+ }
654
+ let lib_args: Vec < _ > = all_native_libs
655
+ . iter ( )
656
+ . filter ( |l| relevant_lib ( sess, l) )
657
+ . filter_map ( |lib| {
658
+ let name = lib. name ?;
659
+ match lib. kind {
660
+ NativeLibKind :: StaticNoBundle
661
+ | NativeLibKind :: Dylib
662
+ | NativeLibKind :: Unspecified => {
663
+ if sess. target . is_like_msvc {
664
+ Some ( format ! ( "{}.lib" , name) )
665
+ } else {
666
+ Some ( format ! ( "-l{}" , name) )
667
+ }
668
+ }
669
+ NativeLibKind :: Framework => {
670
+ // ld-only syntax, since there are no frameworks in MSVC
671
+ Some ( format ! ( "-framework {}" , name) )
672
+ }
673
+ // These are included, no need to print them
674
+ NativeLibKind :: StaticBundle | NativeLibKind :: RawDylib => None ,
675
+ }
676
+ } )
677
+ . collect ( ) ;
678
+ println ! ( "native-static-libs: {}" , & lib_args. join( " " ) ) ;
679
+ Ok ( ( ) )
680
+ } )
681
+ } )
682
+ }
683
+
625
684
impl RustcDefaultCalls {
626
685
fn process_rlink ( sess : & Session , compiler : & interface:: Compiler ) -> Result < ( ) , ErrorReported > {
627
686
if let Input :: File ( file) = compiler. input ( ) {
@@ -679,16 +738,16 @@ impl RustcDefaultCalls {
679
738
680
739
fn print_crate_info (
681
740
codegen_backend : & dyn CodegenBackend ,
682
- sess : & Session ,
741
+ compiler : & interface :: Compiler ,
683
742
input : Option < & Input > ,
684
743
odir : & Option < PathBuf > ,
685
744
ofile : & Option < PathBuf > ,
686
- ) -> Compilation {
745
+ ) -> interface:: Result < Compilation > {
746
+ let sess = compiler. session ( ) ;
747
+
687
748
use rustc_session:: config:: PrintRequest :: * ;
688
- // PrintRequest::NativeStaticLibs is special - printed during linking
689
- // (empty iterator returns true)
690
- if sess. opts . prints . iter ( ) . all ( |& p| p == PrintRequest :: NativeStaticLibs ) {
691
- return Compilation :: Continue ;
749
+ if sess. opts . prints . is_empty ( ) {
750
+ return Ok ( Compilation :: Continue ) ;
692
751
}
693
752
694
753
let attrs = match input {
@@ -699,7 +758,7 @@ impl RustcDefaultCalls {
699
758
Ok ( attrs) => Some ( attrs) ,
700
759
Err ( mut parse_error) => {
701
760
parse_error. emit ( ) ;
702
- return Compilation :: Stop ;
761
+ return Ok ( Compilation :: Stop ) ;
703
762
}
704
763
}
705
764
}
@@ -776,10 +835,12 @@ impl RustcDefaultCalls {
776
835
codegen_backend. print ( * req, sess) ;
777
836
}
778
837
// Any output here interferes with Cargo's parsing of other printed output
779
- PrintRequest :: NativeStaticLibs => { }
838
+ PrintRequest :: NativeStaticLibs => {
839
+ print_native_static_libs ( compiler) ?;
840
+ }
780
841
}
781
842
}
782
- Compilation :: Stop
843
+ Ok ( Compilation :: Stop )
783
844
}
784
845
}
785
846
@@ -1147,7 +1208,11 @@ fn extra_compiler_flags() -> Option<(Vec<String>, bool)> {
1147
1208
}
1148
1209
}
1149
1210
1150
- if !result. is_empty ( ) { Some ( ( result, excluded_cargo_defaults) ) } else { None }
1211
+ if !result. is_empty ( ) {
1212
+ Some ( ( result, excluded_cargo_defaults) )
1213
+ } else {
1214
+ None
1215
+ }
1151
1216
}
1152
1217
1153
1218
/// Runs a closure and catches unwinds triggered by fatal errors.
0 commit comments