Skip to content

Commit

Permalink
rewrite reproducible-build-2 to rmake
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneirical committed Aug 1, 2024
1 parent c0e3298 commit b485dd1
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 28 deletions.
22 changes: 22 additions & 0 deletions src/tools/run-make-support/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,28 @@ pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) {
));
}

#[track_caller]
/// An extension of [`std::fs::copy`] which can copy a directory recursively.
pub fn copy_dir_all<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) {
create_dir_all(&to);
for entry in read_dir(from) {
let entry = entry.unwrap();
let ty = entry.file_type().unwrap();
if ty.is_dir() {
copy_dir_all(entry.path(), to.as_ref().join(entry.file_name()));
} else if ty.is_symlink() {
copy_symlink(entry.path(), to.as_ref().join(entry.file_name()));
} else {
copy(entry.path(), to.as_ref().join(entry.file_name()));
}
}
}

fn copy_symlink<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) {
let target_path = fs::read_link(from).unwrap();
std::os::unix::fs::symlink(target_path, to).unwrap();
}

/// A wrapper around [`std::fs::File::create`] which includes the file path in the panic message.
#[track_caller]
pub fn create_file<P: AsRef<Path>>(path: P) {
Expand Down
1 change: 0 additions & 1 deletion src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ run-make/raw-dylib-alt-calling-convention/Makefile
run-make/raw-dylib-c/Makefile
run-make/redundant-libs/Makefile
run-make/remap-path-prefix-dwarf/Makefile
run-make/reproducible-build-2/Makefile
run-make/reproducible-build/Makefile
run-make/rlib-format-packed-bundled-libs/Makefile
run-make/simd-ffi/Makefile
Expand Down
27 changes: 0 additions & 27 deletions tests/run-make/reproducible-build-2/Makefile

This file was deleted.

45 changes: 45 additions & 0 deletions tests/run-make/reproducible-build-2/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Builds with fat link-time-optimizations and the --sysroot flag used to be
// non-deterministic - that means, compiling twice with no changes would create
// slightly different outputs. This has been fixed by #63352 and #63505.
// Test 1: Compile with fat-lto twice, check that both compilation outputs are identical.
// Test 2: Compile with sysroot, then change the sysroot path from absolute to relative.
// Outputs should be identical.
// See https://github.com/rust-lang/rust/issues/34902

//FIXME(Oneirical): excluded ignore-musl ignore-windows ignore-cross-compile

use run_make_support::{fs_wrapper, rust_lib_name, rustc};

fn main() {
// test 1: fat lto
rustc().input("reproducible-build-aux.rs").run();
rustc().input("reproducible-build.rs").arg("-Clto=fat").run();
fs_wrapper::rename("reproducible-build", "reproducible-build-a");
rustc().input("reproducible-build.rs").arg("-Clto=fat").run();
assert_eq!(fs_wrapper::read("reproducible-build"), fs_wrapper::read("reproducible-build-a"));

// test 2: sysroot
let sysroot = rustc().print("sysroot").run().stdout_utf8();
let sysroot = sysroot.trim();

rustc().input("reproducible-build-aux.rs").run();
rustc()
.input("reproducible-build.rs")
.crate_type("rlib")
.sysroot(&sysroot)
.arg(format!("--remap-path-prefix={sysroot}=/sysroot"))
.run();
fs_wrapper::copy_dir_all(&sysroot, "sysroot");
fs_wrapper::rename(rust_lib_name("reproducible_build"), rust_lib_name("foo"));
rustc()
.input("reproducible-build.rs")
.crate_type("rlib")
.sysroot("sysroot")
.arg("--remap-path-prefix=/sysroot=/sysroot")
.run();

assert_eq!(
fs_wrapper::read(rust_lib_name("reproducible_build")),
fs_wrapper::read(rust_lib_name("foo"))
);
}

0 comments on commit b485dd1

Please sign in to comment.