Skip to content

Commit 863a69a

Browse files
committed
Auto merge of #127095 - Oneirical:testiary-education, r=<try>
Migrate `reproducible-build-2` and `stable-symbol-names` `run-make` tests to rmake Part of #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
2 parents c4c0897 + 1bbf359 commit 863a69a

File tree

6 files changed

+122
-70
lines changed

6 files changed

+122
-70
lines changed

src/tools/run-make-support/src/fs_wrapper.rs

+14
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) {
1818
));
1919
}
2020

21+
/// An extension of copy which can copy a directory recursively.
22+
pub fn copy_dir_all<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) {
23+
create_dir_all(&to);
24+
for entry in read_dir(from) {
25+
let entry = entry.unwrap();
26+
let ty = entry.file_type().unwrap();
27+
if ty.is_dir() {
28+
copy_dir_all(entry.path(), to.as_ref().join(entry.file_name()));
29+
} else {
30+
copy(entry.path(), to.as_ref().join(entry.file_name()));
31+
}
32+
}
33+
}
34+
2135
/// A wrapper around [`std::fs::File::create`] which includes the file path in the panic message..
2236
#[track_caller]
2337
pub fn create_file<P: AsRef<Path>>(path: P) {

src/tools/tidy/src/allowed_run_make_makefiles.txt

-2
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ run-make/raw-dylib-stdcall-ordinal/Makefile
146146
run-make/redundant-libs/Makefile
147147
run-make/remap-path-prefix-dwarf/Makefile
148148
run-make/remap-path-prefix/Makefile
149-
run-make/reproducible-build-2/Makefile
150149
run-make/reproducible-build/Makefile
151150
run-make/return-non-c-like-enum-from-c/Makefile
152151
run-make/return-non-c-like-enum/Makefile
@@ -166,7 +165,6 @@ run-make/share-generics-dylib/Makefile
166165
run-make/silly-file-names/Makefile
167166
run-make/simd-ffi/Makefile
168167
run-make/split-debuginfo/Makefile
169-
run-make/stable-symbol-names/Makefile
170168
run-make/static-dylib-by-default/Makefile
171169
run-make/static-extern-type/Makefile
172170
run-make/staticlib-blank-lib/Makefile

tests/run-make/reproducible-build-2/Makefile

-27
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Builds with fat link-time-optimizations and the --sysroot flag used to be
2+
// non-deterministic - that means, compiling twice with no changes would create
3+
// slightly different outputs. This has been fixed by #63352 and #63505.
4+
// Test 1: Compile with fat-lto twice, check that both compilation outputs are identical.
5+
// Test 2: Compile with sysroot, then change the sysroot path from absolute to relative.
6+
// Outputs should be identical.
7+
// See https://github.com/rust-lang/rust/issues/34902
8+
9+
//FIXME(Oneirical): excluded ignore-musl ignore-windows ignore-cross-compile
10+
11+
use run_make_support::{fs_wrapper, rust_lib_name, rustc};
12+
13+
fn main() {
14+
// test 1: fat lto
15+
rustc().input("reproducible-build-aux.rs").run();
16+
rustc().input("reproducible-build.rs").arg("-Clto=fat").run();
17+
fs_wrapper::rename("reproducible-build", "reproducible-build-a");
18+
rustc().input("reproducible-build.rs").arg("-Clto=fat").run();
19+
assert_eq!(fs_wrapper::read("reproducible-build"), fs_wrapper::read("reproducible-build-a"));
20+
21+
// test 2: sysroot
22+
let sysroot = rustc().print("sysroot").run().stdout_utf8();
23+
let sysroot = sysroot.trim();
24+
25+
rustc().input("reproducible-build-aux.rs").run();
26+
rustc()
27+
.input("reproducible-build.rs")
28+
.crate_type("rlib")
29+
.sysroot(&sysroot)
30+
.arg(format!("--remap-path-prefix={sysroot}=/sysroot"))
31+
.run();
32+
fs_wrapper::copy_dir_all(&sysroot, "sysroot");
33+
fs_wrapper::rename(rust_lib_name("reproducible_build"), rust_lib_name("foo"));
34+
rustc()
35+
.input("reproducible-build.rs")
36+
.crate_type("rlib")
37+
.sysroot("sysroot")
38+
.arg("--remap-path-prefix=/sysroot=/sysroot")
39+
.run();
40+
41+
assert_eq!(
42+
fs_wrapper::read(rust_lib_name("reproducible_build")),
43+
fs_wrapper::read(rust_lib_name("foo"))
44+
);
45+
}

tests/run-make/stable-symbol-names/Makefile

-41
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// A typo in rustc caused generic symbol names to be non-deterministic -
2+
// that is, it was possible to compile the same file twice with no changes
3+
// and get outputs with different symbol names.
4+
// This test compiles each of the two crates twice, and checks that each output
5+
// contains exactly the same symbol names.
6+
// Additionally, both crates should agree on the same symbol names for monomorphic
7+
// functions.
8+
// See https://github.com/rust-lang/rust/issues/32554
9+
10+
use run_make_support::{fs_wrapper, llvm_readobj, regex, rust_lib_name, rustc};
11+
use std::collections::HashSet;
12+
13+
fn main() {
14+
// test 1: first file
15+
rustc().input("stable-symbol-names1.rs").run();
16+
let sym1 = process_symbols("stable_symbol_names1", "generic_|mono_");
17+
fs_wrapper::remove_file(rust_lib_name("stable_symbol_names1"));
18+
rustc().input("stable-symbol-names1.rs").run();
19+
let sym2 = process_symbols("stable_symbol_names1", "generic_|mono_");
20+
assert_eq!(sym1, sym2);
21+
22+
// test 2: second file
23+
rustc().input("stable-symbol-names2.rs").run();
24+
let sym1 = process_symbols("stable_symbol_names2", "generic_|mono_");
25+
fs_wrapper::remove_file(rust_lib_name("stable_symbol_names2"));
26+
rustc().input("stable-symbol-names2.rs").run();
27+
let sym2 = process_symbols("stable_symbol_names2", "generic_|mono_");
28+
assert_eq!(sym1, sym2);
29+
30+
// test 3: crossed files
31+
let sym1 = process_symbols("stable_symbol_names1", "mono_");
32+
let sym2 = process_symbols("stable_symbol_names2", "mono_");
33+
assert_eq!(sym1, sym2);
34+
}
35+
36+
#[track_caller]
37+
fn process_symbols(path: &str, symbol: &str) -> Vec<String> {
38+
// Dump all symbols.
39+
let out = llvm_readobj().input(rust_lib_name(path)).arg("--symbols").run().stdout_utf8();
40+
// Extract only lines containing `symbol`.
41+
let out = out.lines().filter(|&x| x.contains(symbol));
42+
// From those lines, extract just the symbol name via `regex`, which:
43+
// * always starts with "_ZN" and ends with "E" (`legacy` mangling)
44+
// * always starts with "_R" (`v0` mangling)
45+
let legacy_pattern = regex::Regex::new(r"_ZN.*E").unwrap();
46+
let v0_pattern = regex::Regex::new(r"_R[a-zA-Z0-9_]*").unwrap();
47+
48+
// HashSet - duplicates should be excluded!
49+
let mut symbols: HashSet<String> = HashSet::new();
50+
for line in out {
51+
if let Some(mat) = legacy_pattern.find(line) {
52+
symbols.insert(mat.as_str().to_string());
53+
}
54+
if let Some(mat) = v0_pattern.find(line) {
55+
symbols.insert(mat.as_str().to_string());
56+
}
57+
}
58+
59+
let mut symbols: Vec<String> = symbols.into_iter().collect();
60+
// Sort those symbol names for deterministic comparison.
61+
symbols.sort();
62+
symbols
63+
}

0 commit comments

Comments
 (0)