Skip to content

Commit

Permalink
Auto merge of rust-lang#127095 - Oneirical:testiary-education, r=<try>
Browse files Browse the repository at this point in the history
Migrate `reproducible-build-2` and `stable-symbol-names` `run-make` tests 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).

Needs try-jobs.

try-job: dist-x86_64-musl
try-job: x86_64-mingw
  • Loading branch information
bors committed Jun 28, 2024
2 parents c4c0897 + 1bbf359 commit 863a69a
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 70 deletions.
14 changes: 14 additions & 0 deletions src/tools/run-make-support/src/fs_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) {
));
}

/// An extension of 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 {
copy(entry.path(), to.as_ref().join(entry.file_name()));
}
}
}

/// 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
2 changes: 0 additions & 2 deletions src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ run-make/raw-dylib-stdcall-ordinal/Makefile
run-make/redundant-libs/Makefile
run-make/remap-path-prefix-dwarf/Makefile
run-make/remap-path-prefix/Makefile
run-make/reproducible-build-2/Makefile
run-make/reproducible-build/Makefile
run-make/return-non-c-like-enum-from-c/Makefile
run-make/return-non-c-like-enum/Makefile
Expand All @@ -166,7 +165,6 @@ run-make/share-generics-dylib/Makefile
run-make/silly-file-names/Makefile
run-make/simd-ffi/Makefile
run-make/split-debuginfo/Makefile
run-make/stable-symbol-names/Makefile
run-make/static-dylib-by-default/Makefile
run-make/static-extern-type/Makefile
run-make/staticlib-blank-lib/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"))
);
}
41 changes: 0 additions & 41 deletions tests/run-make/stable-symbol-names/Makefile

This file was deleted.

63 changes: 63 additions & 0 deletions tests/run-make/stable-symbol-names/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// A typo in rustc caused generic symbol names to be non-deterministic -
// that is, it was possible to compile the same file twice with no changes
// and get outputs with different symbol names.
// This test compiles each of the two crates twice, and checks that each output
// contains exactly the same symbol names.
// Additionally, both crates should agree on the same symbol names for monomorphic
// functions.
// See https://github.com/rust-lang/rust/issues/32554

use run_make_support::{fs_wrapper, llvm_readobj, regex, rust_lib_name, rustc};
use std::collections::HashSet;

fn main() {
// test 1: first file
rustc().input("stable-symbol-names1.rs").run();
let sym1 = process_symbols("stable_symbol_names1", "generic_|mono_");
fs_wrapper::remove_file(rust_lib_name("stable_symbol_names1"));
rustc().input("stable-symbol-names1.rs").run();
let sym2 = process_symbols("stable_symbol_names1", "generic_|mono_");
assert_eq!(sym1, sym2);

// test 2: second file
rustc().input("stable-symbol-names2.rs").run();
let sym1 = process_symbols("stable_symbol_names2", "generic_|mono_");
fs_wrapper::remove_file(rust_lib_name("stable_symbol_names2"));
rustc().input("stable-symbol-names2.rs").run();
let sym2 = process_symbols("stable_symbol_names2", "generic_|mono_");
assert_eq!(sym1, sym2);

// test 3: crossed files
let sym1 = process_symbols("stable_symbol_names1", "mono_");
let sym2 = process_symbols("stable_symbol_names2", "mono_");
assert_eq!(sym1, sym2);
}

#[track_caller]
fn process_symbols(path: &str, symbol: &str) -> Vec<String> {
// Dump all symbols.
let out = llvm_readobj().input(rust_lib_name(path)).arg("--symbols").run().stdout_utf8();
// Extract only lines containing `symbol`.
let out = out.lines().filter(|&x| x.contains(symbol));
// From those lines, extract just the symbol name via `regex`, which:
// * always starts with "_ZN" and ends with "E" (`legacy` mangling)
// * always starts with "_R" (`v0` mangling)
let legacy_pattern = regex::Regex::new(r"_ZN.*E").unwrap();
let v0_pattern = regex::Regex::new(r"_R[a-zA-Z0-9_]*").unwrap();

// HashSet - duplicates should be excluded!
let mut symbols: HashSet<String> = HashSet::new();
for line in out {
if let Some(mat) = legacy_pattern.find(line) {
symbols.insert(mat.as_str().to_string());
}
if let Some(mat) = v0_pattern.find(line) {
symbols.insert(mat.as_str().to_string());
}
}

let mut symbols: Vec<String> = symbols.into_iter().collect();
// Sort those symbol names for deterministic comparison.
symbols.sort();
symbols
}

0 comments on commit 863a69a

Please sign in to comment.