Skip to content

Commit 03b5102

Browse files
committed
auto merge of #11215 : alexcrichton/rust/metadata-filename, r=pcwalton
Right now if you have concurrent builds of two libraries in the same directory (such as rustc's bootstrapping process), it's possible that two libraries will stomp over each others' metadata, producing corrupt rlibs. By placing the metadata file in a tempdir we're guranteed to not conflict with ay other builds happening concurrently. Normally this isn't a problem because output filenames are scoped to the name of the crate, but metadata is special in that it has the same name across all crates.
2 parents e61937a + fe30087 commit 03b5102

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/librustc/back/link.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,8 +879,11 @@ fn link_rlib(sess: Session,
879879
match trans {
880880
Some(trans) => {
881881
// Instead of putting the metadata in an object file section, rlibs
882-
// contain the metadata in a separate file.
883-
let metadata = obj_filename.with_filename(METADATA_FILENAME);
882+
// contain the metadata in a separate file. We use a temp directory
883+
// here so concurrent builds in the same directory don't try to use
884+
// the same filename for metadata (stomping over one another)
885+
let tmpdir = TempDir::new("rustc").expect("needs a temp dir");
886+
let metadata = tmpdir.path().join(METADATA_FILENAME);
884887
fs::File::create(&metadata).write(trans.metadata);
885888
a.add_file(&metadata, false);
886889
fs::unlink(&metadata);

0 commit comments

Comments
 (0)