Skip to content

Commit c20c552

Browse files
authored
Unrolled build for rust-lang#122723
Rollup merge of rust-lang#122723 - bjorn3:archive_writer_fixes, r=nnethercote Use same file permissions for ar_archive_writer as the LLVM archive writer This is required to switch to ar_archive_writer in the future without regressions. In addition to this PR support for reading thin archives needs to be added (rust-lang#107407) to fix all known regressions. Fixes rust-lang#107495
2 parents 00ed4ed + 297fceb commit c20c552

File tree

3 files changed

+51
-8
lines changed

3 files changed

+51
-8
lines changed

compiler/rustc_codegen_ssa/src/back/archive.rs

+19-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use object::read::macho::FatArch;
1313
use tempfile::Builder as TempFileBuilder;
1414

1515
use std::error::Error;
16-
use std::fs::File;
16+
use std::fs::{self, File};
1717
use std::io::{self, Write};
1818
use std::path::{Path, PathBuf};
1919

@@ -280,22 +280,33 @@ impl<'a> ArArchiveBuilder<'a> {
280280
// This prevents programs (including rustc) from attempting to read a partial archive.
281281
// It also enables writing an archive with the same filename as a dependency on Windows as
282282
// required by a test.
283-
let mut archive_tmpfile = TempFileBuilder::new()
283+
// The tempfile crate currently uses 0o600 as mode for the temporary files and directories
284+
// it creates. We need it to be the default mode for back compat reasons however. (See
285+
// #107495) To handle this we are telling tempfile to create a temporary directory instead
286+
// and then inside this directory create a file using File::create.
287+
let archive_tmpdir = TempFileBuilder::new()
284288
.suffix(".temp-archive")
285-
.tempfile_in(output.parent().unwrap_or_else(|| Path::new("")))
286-
.map_err(|err| io_error_context("couldn't create a temp file", err))?;
289+
.tempdir_in(output.parent().unwrap_or_else(|| Path::new("")))
290+
.map_err(|err| {
291+
io_error_context("couldn't create a directory for the temp file", err)
292+
})?;
293+
let archive_tmpfile_path = archive_tmpdir.path().join("tmp.a");
294+
let mut archive_tmpfile = File::create_new(&archive_tmpfile_path)
295+
.map_err(|err| io_error_context("couldn't create the temp file", err))?;
287296

288-
write_archive_to_stream(archive_tmpfile.as_file_mut(), &entries, archive_kind, false)?;
297+
write_archive_to_stream(&mut archive_tmpfile, &entries, archive_kind, false)?;
289298

290299
let any_entries = !entries.is_empty();
291300
drop(entries);
292301
// Drop src_archives to unmap all input archives, which is necessary if we want to write the
293302
// output archive to the same location as an input archive on Windows.
294303
drop(self.src_archives);
295304

296-
archive_tmpfile
297-
.persist(output)
298-
.map_err(|err| io_error_context("failed to rename archive file", err.error))?;
305+
fs::rename(archive_tmpfile_path, output)
306+
.map_err(|err| io_error_context("failed to rename archive file", err))?;
307+
archive_tmpdir
308+
.close()
309+
.map_err(|err| io_error_context("failed to remove temporary directory", err))?;
299310

300311
Ok(any_entries)
301312
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Empty
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#![feature(rustc_private)]
2+
3+
#[cfg(unix)]
4+
extern crate libc;
5+
extern crate run_make_support;
6+
7+
use run_make_support::{aux_build, tmp_dir};
8+
use std::fs;
9+
#[cfg(unix)]
10+
use std::os::unix::fs::PermissionsExt;
11+
use std::path::Path;
12+
13+
fn main() {
14+
#[cfg(unix)]
15+
unsafe {
16+
libc::umask(0o002);
17+
}
18+
19+
aux_build().arg("foo.rs").run();
20+
verify(&tmp_dir().join("libfoo.rlib"));
21+
}
22+
23+
fn verify(path: &Path) {
24+
let perm = fs::metadata(path).unwrap().permissions();
25+
26+
assert!(!perm.readonly());
27+
28+
// Check that the file is readable for everyone
29+
#[cfg(unix)]
30+
assert_eq!(perm.mode(), 0o100664);
31+
}

0 commit comments

Comments
 (0)