@@ -7,7 +7,7 @@ use rustc::session::config::{
77} ;
88use rustc:: session:: search_paths:: PathKind ;
99use rustc:: middle:: dependency_format:: Linkage ;
10- use rustc:: middle:: cstore:: { LibSource , NativeLibrary , NativeLibraryKind } ;
10+ use rustc:: middle:: cstore:: { EncodedMetadata , LibSource , NativeLibrary , NativeLibraryKind } ;
1111use rustc:: util:: common:: { time, time_ext} ;
1212use rustc:: hir:: def_id:: CrateNum ;
1313use rustc_data_structures:: fx:: FxHashSet ;
@@ -50,9 +50,9 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(sess: &'a Session,
5050 outputs : & OutputFilenames ,
5151 crate_name : & str ,
5252 target_cpu : & str ) {
53+ let output_metadata = sess. opts . output_types . contains_key ( & OutputType :: Metadata ) ;
5354 for & crate_type in sess. crate_types . borrow ( ) . iter ( ) {
5455 // Ignore executable crates if we have -Z no-codegen, as they will error.
55- let output_metadata = sess. opts . output_types . contains_key ( & OutputType :: Metadata ) ;
5656 if ( sess. opts . debugging_opts . no_codegen || !sess. opts . output_types . should_codegen ( ) ) &&
5757 !output_metadata &&
5858 crate_type == config:: CrateType :: Executable {
@@ -68,29 +68,6 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(sess: &'a Session,
6868 check_file_is_writeable ( obj, sess) ;
6969 }
7070
71- if outputs. outputs . contains_key ( & OutputType :: Metadata ) {
72- let out_filename = filename_for_metadata ( sess, crate_name, outputs) ;
73- // To avoid races with another rustc process scanning the output directory,
74- // we need to write the file somewhere else and atomically move it to its
75- // final destination, with a `fs::rename` call. In order for the rename to
76- // always succeed, the temporary file needs to be on the same filesystem,
77- // which is why we create it inside the output directory specifically.
78- let metadata_tmpdir = TempFileBuilder :: new ( )
79- . prefix ( "rmeta" )
80- . tempdir_in ( out_filename. parent ( ) . unwrap ( ) )
81- . unwrap_or_else ( |err| sess. fatal ( & format ! ( "couldn't create a temp dir: {}" , err) ) ) ;
82- let metadata = emit_metadata ( sess, codegen_results, & metadata_tmpdir) ;
83- match fs:: rename ( & metadata, & out_filename) {
84- Ok ( _) => {
85- if sess. opts . debugging_opts . emit_directives {
86- sess. parse_sess . span_diagnostic . maybe_emit_json_directive (
87- format ! ( "metadata file written: {}" , out_filename. display( ) ) ) ;
88- }
89- }
90- Err ( e) => sess. fatal ( & format ! ( "failed to write {}: {}" , out_filename. display( ) , e) ) ,
91- }
92- }
93-
9471 let tmpdir = TempFileBuilder :: new ( ) . prefix ( "rustc" ) . tempdir ( ) . unwrap_or_else ( |err|
9572 sess. fatal ( & format ! ( "couldn't create a temp dir: {}" , err) ) ) ;
9673
@@ -248,13 +225,13 @@ pub fn each_linked_rlib(sess: &Session,
248225/// building an `.rlib` (stomping over one another), or writing an `.rmeta` into a
249226/// directory being searched for `extern crate` (observing an incomplete file).
250227/// The returned path is the temporary file containing the complete metadata.
251- fn emit_metadata < ' a > (
228+ pub fn emit_metadata < ' a > (
252229 sess : & ' a Session ,
253- codegen_results : & CodegenResults ,
230+ metadata : & EncodedMetadata ,
254231 tmpdir : & TempDir
255232) -> PathBuf {
256233 let out_filename = tmpdir. path ( ) . join ( METADATA_FILENAME ) ;
257- let result = fs:: write ( & out_filename, & codegen_results . metadata . raw_data ) ;
234+ let result = fs:: write ( & out_filename, & metadata. raw_data ) ;
258235
259236 if let Err ( e) = result {
260237 sess. fatal ( & format ! ( "failed to write {}: {}" , out_filename. display( ) , e) ) ;
@@ -338,7 +315,7 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(sess: &'a Session,
338315 RlibFlavor :: Normal => {
339316 // Instead of putting the metadata in an object file section, rlibs
340317 // contain the metadata in a separate file.
341- ab. add_file ( & emit_metadata ( sess, codegen_results, tmpdir) ) ;
318+ ab. add_file ( & emit_metadata ( sess, & codegen_results. metadata , tmpdir) ) ;
342319
343320 // For LTO purposes, the bytecode of this library is also inserted
344321 // into the archive.
0 commit comments