@@ -25,7 +25,7 @@ use rustc::ty::layout::{self, Align, TyLayout, LayoutOf, VariantIdx, HasTyCtxt};
25
25
use rustc:: ty:: query:: Providers ;
26
26
use rustc:: middle:: cstore:: { self , LinkagePreference } ;
27
27
use rustc:: util:: common:: { time, print_time_passes_entry} ;
28
- use rustc:: session:: config:: { self , EntryFnType , Lto } ;
28
+ use rustc:: session:: config:: { self , CrateType , EntryFnType , Lto } ;
29
29
use rustc:: session:: Session ;
30
30
use rustc_mir:: monomorphize:: item:: DefPathBasedNames ;
31
31
use rustc_mir:: monomorphize:: Instance ;
@@ -550,12 +550,6 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
550
550
} ) ;
551
551
tcx. sess . profiler ( |p| p. end_activity ( "codegen crate metadata" ) ) ;
552
552
553
- let metadata_module = ModuleCodegen {
554
- name : metadata_cgu_name,
555
- module_llvm : metadata_llvm_module,
556
- kind : ModuleKind :: Metadata ,
557
- } ;
558
-
559
553
// Skip crate items and just output metadata in -Z no-codegen mode.
560
554
if tcx. sess . opts . debugging_opts . no_codegen ||
561
555
!tcx. sess . opts . output_types . should_codegen ( ) {
@@ -566,7 +560,6 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
566
560
rx,
567
561
1 ) ;
568
562
569
- ongoing_codegen. submit_pre_codegened_module_to_llvm ( tcx, metadata_module) ;
570
563
ongoing_codegen. codegen_finished ( tcx) ;
571
564
572
565
assert_and_save_dep_graph ( tcx) ;
@@ -639,7 +632,24 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
639
632
ongoing_codegen. submit_pre_codegened_module_to_llvm ( tcx, allocator_module) ;
640
633
}
641
634
642
- ongoing_codegen. submit_pre_codegened_module_to_llvm ( tcx, metadata_module) ;
635
+ let needs_metadata_module = tcx. sess . crate_types . borrow ( ) . iter ( ) . any ( |ct| {
636
+ match * ct {
637
+ CrateType :: Dylib |
638
+ CrateType :: ProcMacro => true ,
639
+ CrateType :: Executable |
640
+ CrateType :: Rlib |
641
+ CrateType :: Staticlib |
642
+ CrateType :: Cdylib => false ,
643
+ }
644
+ } ) ;
645
+ if needs_metadata_module {
646
+ let metadata_module = ModuleCodegen {
647
+ name : metadata_cgu_name,
648
+ module_llvm : metadata_llvm_module,
649
+ kind : ModuleKind :: Metadata ,
650
+ } ;
651
+ ongoing_codegen. submit_pre_codegened_module_to_llvm ( tcx, metadata_module) ;
652
+ }
643
653
644
654
// We sort the codegen units by size. This way we can schedule work for LLVM
645
655
// a bit more efficiently.
0 commit comments