@@ -7,7 +7,7 @@ use rustc::session::config::{
7
7
} ;
8
8
use rustc:: session:: search_paths:: PathKind ;
9
9
use rustc:: middle:: dependency_format:: Linkage ;
10
- use rustc:: middle:: cstore:: { LibSource , NativeLibrary , NativeLibraryKind } ;
10
+ use rustc:: middle:: cstore:: { EncodedMetadata , LibSource , NativeLibrary , NativeLibraryKind } ;
11
11
use rustc:: util:: common:: { time, time_ext} ;
12
12
use rustc:: hir:: def_id:: CrateNum ;
13
13
use rustc_data_structures:: fx:: FxHashSet ;
@@ -50,9 +50,9 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(sess: &'a Session,
50
50
outputs : & OutputFilenames ,
51
51
crate_name : & str ,
52
52
target_cpu : & str ) {
53
+ let output_metadata = sess. opts . output_types . contains_key ( & OutputType :: Metadata ) ;
53
54
for & crate_type in sess. crate_types . borrow ( ) . iter ( ) {
54
55
// 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 ) ;
56
56
if ( sess. opts . debugging_opts . no_codegen || !sess. opts . output_types . should_codegen ( ) ) &&
57
57
!output_metadata &&
58
58
crate_type == config:: CrateType :: Executable {
@@ -68,29 +68,6 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(sess: &'a Session,
68
68
check_file_is_writeable ( obj, sess) ;
69
69
}
70
70
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
-
94
71
let tmpdir = TempFileBuilder :: new ( ) . prefix ( "rustc" ) . tempdir ( ) . unwrap_or_else ( |err|
95
72
sess. fatal ( & format ! ( "couldn't create a temp dir: {}" , err) ) ) ;
96
73
@@ -248,13 +225,13 @@ pub fn each_linked_rlib(sess: &Session,
248
225
/// building an `.rlib` (stomping over one another), or writing an `.rmeta` into a
249
226
/// directory being searched for `extern crate` (observing an incomplete file).
250
227
/// The returned path is the temporary file containing the complete metadata.
251
- fn emit_metadata < ' a > (
228
+ pub fn emit_metadata < ' a > (
252
229
sess : & ' a Session ,
253
- codegen_results : & CodegenResults ,
230
+ metadata : & EncodedMetadata ,
254
231
tmpdir : & TempDir
255
232
) -> PathBuf {
256
233
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 ) ;
258
235
259
236
if let Err ( e) = result {
260
237
sess. fatal ( & format ! ( "failed to write {}: {}" , out_filename. display( ) , e) ) ;
@@ -338,7 +315,7 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(sess: &'a Session,
338
315
RlibFlavor :: Normal => {
339
316
// Instead of putting the metadata in an object file section, rlibs
340
317
// 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) ) ;
342
319
343
320
// For LTO purposes, the bytecode of this library is also inserted
344
321
// into the archive.
0 commit comments