Skip to content

Commit

Permalink
Auto merge of rust-lang#128456 - Oneirical:clantestine-operations, r=…
Browse files Browse the repository at this point in the history
…<try>

Migrate `reproducible-build` `run-make` test to rmake

Part of rust-lang#121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html).

This will likely fail. Locally, rustc errors with `linker 'linker' not found` on line 36 while the file exists according to the dir-debug statement before it.

If this gets fixed and the test passes, further developments may include:

- [x] There may be some leftovers from each test - `test_in_tmpdir` may therefore be required.
- [ ] Try jobs on all ignored architectures.
- [x] A potential refactor with a struct and a custom function like rust-lang#128410 so this isn't just a huge stream of `rfs` and `rustc`. This is a little bit harder to do in this test considering the variability present in each test case.

try-job: aarch64-apple
try-job: test-various
try-job: armhf-gnu
try-job: dist-various-1
  • Loading branch information
bors committed Aug 8, 2024
2 parents 86e7875 + 1da234c commit a64142b
Show file tree
Hide file tree
Showing 3 changed files with 226 additions and 141 deletions.
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 @@ -17,7 +17,6 @@ run-make/min-global-align/Makefile
run-make/native-link-modifier-bundle/Makefile
run-make/no-alloc-shim/Makefile
run-make/remap-path-prefix-dwarf/Makefile
run-make/reproducible-build/Makefile
run-make/rlib-format-packed-bundled-libs/Makefile
run-make/split-debuginfo/Makefile
run-make/symbol-mangling-hashed/Makefile
Expand Down
140 changes: 0 additions & 140 deletions tests/run-make/reproducible-build/Makefile

This file was deleted.

226 changes: 226 additions & 0 deletions tests/run-make/reproducible-build/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
// This test case makes sure that two identical invocations of the compiler
// (i.e. same code base, same compile-flags, same compiler-versions, etc.)
// produce the same output. In the past, symbol names of monomorphized functions
// were not deterministic (which we want to avoid).
//
// The test tries to exercise as many different paths into symbol name
// generation as possible:
//
// - regular functions
// - generic functions
// - methods
// - statics
// - closures
// - enum variant constructors
// - tuple struct constructors
// - drop glue
// - FnOnce adapters
// - Trait object shims
// - Fn Pointer shims
// See https://github.com/rust-lang/rust/pull/32293

// FIXME(Oneirical): ignore-musl
//@ ignore-windows
// FIXME(Oneirical): try it on test-various
// # FIXME: Builds of `bin` crate types are not deterministic with debuginfo=2 on
// # Windows.
// # See: https://github.com/rust-lang/rust/pull/87320#issuecomment-920105533
// # Issue: https://github.com/rust-lang/rust/issues/88982

use run_make_support::{bin_name, cwd, diff, rfs, run_in_tmpdir, rust_lib_name, rustc};

fn main() {
// Smoke tests. Simple flags, build should be reproducible.
smoke_test(None);
smoke_test(Some(SmokeFlag::Debug));
smoke_test(Some(SmokeFlag::Opt));

// Builds should be reproducible even through custom library search paths
// or remap path prefixes.
paths_test(PathsFlag::Link);
paths_test(PathsFlag::Remap);

// Builds should be reproducible even if each build is done in a different directory,
// with both --remap-path-prefix and -Z remap-cwd-prefix.

// FIXME(Oneirical): Building with crate type set to `bin` AND having -Cdebuginfo=2
// (or `-g`, the shorthand form) enabled will cause reproductibility failures.
// See https://github.com/rust-lang/rust/issues/89911

// This specific case would fail on OSX, should -Cdebuginfo=2 be added.
diff_dir_test(CrateType::Bin, RemapType::Path);

diff_dir_test(CrateType::Rlib, RemapType::Path);

//FIXME(Oneirical): This specific case would fail on both Linux and OSX, should -Cdebuginfo=2
// be added.
// See https://github.com/rust-lang/rust/issues/89911
diff_dir_test(CrateType::Bin, RemapType::Cwd { is_empty: false });

diff_dir_test(CrateType::Rlib, RemapType::Cwd { is_empty: false });
diff_dir_test(CrateType::Rlib, RemapType::Cwd { is_empty: true });

// Builds should be reproducible when using the --extern flag.
run_in_tmpdir(|| {
rustc().input("reproducible-build-aux.rs").run();
rustc()
.input("reproducible-build.rs")
.crate_type("rlib")
.extern_("reproducible_build_aux", rust_lib_name("reproducible_build_aux"))
.run();
rfs::copy(rust_lib_name("reproducible_build"), rust_lib_name("foo"));
rfs::copy(rust_lib_name("reproducible_build_aux"), rust_lib_name("bar"));
rustc()
.input("reproducible-build.rs")
.crate_type("rlib")
.extern_("reproducible_build_aux", rust_lib_name("bar"))
.run();
assert_eq!(rfs::read(rust_lib_name("foo")), rfs::read(rust_lib_name("reproducible_build")));
});
}

#[track_caller]
fn smoke_test(flag: Option<SmokeFlag>) {
run_in_tmpdir(|| {
rustc().input("linker.rs").opt().run();
rustc().input("reproducible-build-aux.rs").run();
let mut compiler1 = rustc();
let mut compiler2 = rustc();
if let Some(flag) = flag {
match flag {
SmokeFlag::Debug => {
compiler1.arg("-g");
compiler2.arg("-g");
}
SmokeFlag::Opt => {
compiler1.opt();
compiler2.opt();
}
};
};
compiler1
.input("reproducible-build.rs")
.linker(&cwd().join(bin_name("linker")).display().to_string())
.run();
compiler2
.input("reproducible-build.rs")
.linker(&cwd().join(bin_name("linker")).display().to_string())
.run();
diff().actual_file("linker-arguments1").expected_file("linker-arguments2").run();
});
}

#[track_caller]
fn paths_test(flag: PathsFlag) {
run_in_tmpdir(|| {
rustc().input("reproducible-build-aux.rs").run();
let mut compiler1 = rustc();
let mut compiler2 = rustc();
match flag {
PathsFlag::Link => {
compiler1.library_search_path("a");
compiler2.library_search_path("b");
}
PathsFlag::Remap => {
compiler1.arg("--remap-path-prefix=/a=/c");
compiler2.arg("--remap-path-prefix=/b=/c");
}
}
compiler1.input("reproducible-build.rs").crate_type("rlib").run();
rfs::rename(rust_lib_name("reproducible_build"), rust_lib_name("foo"));
compiler2.input("reproducible-build.rs").crate_type("rlib").run();
assert_eq!(rfs::read(rust_lib_name("reproducible_build")), rfs::read(rust_lib_name("foo")));
});
}

#[track_caller]
fn diff_dir_test(crate_type: CrateType, remap_type: RemapType) {
run_in_tmpdir(|| {
let base_dir = cwd();
rustc().input("reproducible-build-aux.rs").run();
rfs::create_dir("test");
rfs::copy("reproducible-build.rs", "test/reproducible-build.rs");
let mut compiler1 = rustc();
let mut compiler2 = rustc();
match crate_type {
CrateType::Bin => {
compiler1.crate_type("bin");
compiler2.crate_type("bin");
}
CrateType::Rlib => {
compiler1.crate_type("rlib");
compiler2.crate_type("rlib");
}
}
match remap_type {
RemapType::Path => {
compiler1.arg(&format!("--remap-path-prefix={}=/b", cwd().display()));
compiler2
.arg(format!("--remap-path-prefix={}=/b", base_dir.join("test").display()));
}
RemapType::Cwd { is_empty } => {
// FIXME(Oneirical): Building with crate type set to `bin` AND having -Cdebuginfo=2
// (or `-g`, the shorthand form) enabled will cause reproductibility failures.
// See https://github.com/rust-lang/rust/issues/89911
if !matches!(crate_type, CrateType::Bin) {
compiler1.arg("-Cdebuginfo=2");
compiler2.arg("-Cdebuginfo=2");
}
if is_empty {
compiler1.arg("-Zremap-cwd-prefix=");
compiler2.arg("-Zremap-cwd-prefix=");
} else {
compiler1.arg("-Zremap-cwd-prefix=.");
compiler2.arg("-Zremap-cwd-prefix=.");
}
}
}
compiler1.input("reproducible-build.rs").run();
match crate_type {
CrateType::Bin => {
rfs::rename(bin_name("reproducible-build"), bin_name("foo"));
}
CrateType::Rlib => {
rfs::rename(rust_lib_name("reproducible_build"), rust_lib_name("foo"));
}
}
std::env::set_current_dir("test").unwrap();
compiler2
.input("reproducible-build.rs")
.library_search_path(&base_dir)
.out_dir(&base_dir)
.run();
std::env::set_current_dir(&base_dir).unwrap();
match crate_type {
CrateType::Bin => {
assert!(rfs::read(bin_name("reproducible-build")) == rfs::read(bin_name("foo")));
}
CrateType::Rlib => {
assert_eq!(
rfs::read(rust_lib_name("foo")),
rfs::read(rust_lib_name("reproducible_build"))
);
}
}
});
}

enum SmokeFlag {
Debug,
Opt,
}

enum PathsFlag {
Link,
Remap,
}

enum CrateType {
Bin,
Rlib,
}

enum RemapType {
Path,
Cwd { is_empty: bool },
}

0 comments on commit a64142b

Please sign in to comment.