about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src
diff options
context:
space:
mode:
authorYoshiki Matsuda <myskjp@gmail.com>2022-04-24 19:34:35 +0900
committerYoshiki Matsuda <myskjp@gmail.com>2022-07-02 22:48:16 +0900
commit709a78226b12025385976bdafa6d7793ec8a4a5b (patch)
treebc5a056c5d07b1b105b3b417aa290cb92cde292f /compiler/rustc_codegen_ssa/src
parentaedf78e56b2279cc869962feac5153b6ba7001ed (diff)
downloadrust-709a78226b12025385976bdafa6d7793ec8a4a5b.tar.gz
rust-709a78226b12025385976bdafa6d7793ec8a4a5b.zip
move emit_metadata to rustc_metadata::fs
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
-rw-r--r--compiler/rustc_codegen_ssa/src/back/link.rs29
-rw-r--r--compiler/rustc_codegen_ssa/src/back/metadata.rs3
-rw-r--r--compiler/rustc_codegen_ssa/src/lib.rs3
3 files changed, 6 insertions, 29 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs
index 72aa790c363..ab794fd4d27 100644
--- a/compiler/rustc_codegen_ssa/src/back/link.rs
+++ b/compiler/rustc_codegen_ssa/src/back/link.rs
@@ -28,10 +28,7 @@ use super::command::Command;
 use super::linker::{self, Linker};
 use super::metadata::{create_rmeta_file, MetadataPosition};
 use super::rpath::{self, RPathConfig};
-use crate::{
-    looks_like_rust_object_file, CodegenResults, CompiledModule, CrateInfo, NativeLib,
-    METADATA_FILENAME,
-};
+use crate::{looks_like_rust_object_file, CodegenResults, CompiledModule, CrateInfo, NativeLib};
 
 use cc::windows_registry;
 use regex::Regex;
@@ -237,23 +234,7 @@ pub fn each_linked_rlib(
     Ok(())
 }
 
-/// We use a temp directory here to avoid races between concurrent rustc processes,
-/// such as builds in the same directory using the same filename for metadata while
-/// building an `.rlib` (stomping over one another), or writing an `.rmeta` into a
-/// directory being searched for `extern crate` (observing an incomplete file).
-/// The returned path is the temporary file containing the complete metadata.
-pub fn emit_metadata(sess: &Session, metadata: &[u8], tmpdir: &MaybeTempDir) -> PathBuf {
-    let out_filename = tmpdir.as_ref().join(METADATA_FILENAME);
-    let result = fs::write(&out_filename, metadata);
-
-    if let Err(e) = result {
-        sess.fatal(&format!("failed to write {}: {}", out_filename.display(), e));
-    }
-
-    out_filename
-}
-
-/// Create an 'rlib'.
+/// Create an 'arlib'.
 ///
 /// An rlib in its current incarnation is essentially a renamed .a file. The rlib primarily contains
 /// the object file of the crate, but it also contains all of the object files from native
@@ -276,7 +257,7 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(
         RlibFlavor::Normal => {
             let (metadata, metadata_position) =
                 create_rmeta_file(sess, codegen_results.metadata.raw_data());
-            let metadata = emit_metadata(sess, &metadata, tmpdir);
+            let metadata = rustc_metadata::fs::emit_metadata(sess, &metadata, tmpdir);
             match metadata_position {
                 MetadataPosition::First => {
                     // Most of the time metadata in rlib files is wrapped in a "dummy" object
@@ -502,7 +483,7 @@ fn link_staticlib<'a, B: ArchiveBuilder<'a>>(
 
         ab.add_archive(path, move |fname: &str| {
             // Ignore metadata files, no matter the name.
-            if fname == METADATA_FILENAME {
+            if fname == rustc_metadata::fs::METADATA_FILENAME {
                 return true;
             }
 
@@ -2474,7 +2455,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
 
             let mut archive = <B as ArchiveBuilder>::new(sess, &dst);
             if let Err(e) = archive.add_archive(cratepath, move |f| {
-                if f == METADATA_FILENAME {
+                if f == rustc_metadata::fs::METADATA_FILENAME {
                     return true;
                 }
 
diff --git a/compiler/rustc_codegen_ssa/src/back/metadata.rs b/compiler/rustc_codegen_ssa/src/back/metadata.rs
index 3dd607adee5..0302c28815a 100644
--- a/compiler/rustc_codegen_ssa/src/back/metadata.rs
+++ b/compiler/rustc_codegen_ssa/src/back/metadata.rs
@@ -16,14 +16,13 @@ use rustc_data_structures::memmap::Mmap;
 use rustc_data_structures::owning_ref::OwningRef;
 use rustc_data_structures::rustc_erase_owner;
 use rustc_data_structures::sync::MetadataRef;
+use rustc_metadata::fs::METADATA_FILENAME;
 use rustc_metadata::EncodedMetadata;
 use rustc_session::cstore::MetadataLoader;
 use rustc_session::Session;
 use rustc_target::abi::Endian;
 use rustc_target::spec::{RelocModel, Target};
 
-use crate::METADATA_FILENAME;
-
 /// The default metadata loader. This is used by cg_llvm and cg_clif.
 ///
 /// # Metadata location
diff --git a/compiler/rustc_codegen_ssa/src/lib.rs b/compiler/rustc_codegen_ssa/src/lib.rs
index 4be3ae11e4e..1802eedf193 100644
--- a/compiler/rustc_codegen_ssa/src/lib.rs
+++ b/compiler/rustc_codegen_ssa/src/lib.rs
@@ -64,9 +64,6 @@ pub struct ModuleCodegen<M> {
     pub kind: ModuleKind,
 }
 
-// FIXME(eddyb) maybe include the crate name in this?
-pub const METADATA_FILENAME: &str = "lib.rmeta";
-
 impl<M> ModuleCodegen<M> {
     pub fn into_compiled_module(
         self,