Skip to content

Commit 6999739

Browse files
committed
Auto merge of rust-lang#128456 - Oneirical:clantestine-operations, r=<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: x86_64-msvc try-job: x86_64-mingw try-job: i686-msvc try-job: i686-mingw try-job: x86_64-gnu-llvm-17 try-job: dist-various-1
2 parents 0ddead3 + cf49241 commit 6999739

File tree

3 files changed

+210
-141
lines changed

3 files changed

+210
-141
lines changed

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ run-make/raw-dylib-alt-calling-convention/Makefile
2626
run-make/raw-dylib-c/Makefile
2727
run-make/redundant-libs/Makefile
2828
run-make/remap-path-prefix-dwarf/Makefile
29-
run-make/reproducible-build/Makefile
3029
run-make/rlib-format-packed-bundled-libs/Makefile
3130
run-make/simd-ffi/Makefile
3231
run-make/split-debuginfo/Makefile

tests/run-make/reproducible-build/Makefile

-140
This file was deleted.
+210
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
// This test case makes sure that two identical invocations of the compiler
2+
// (i.e. same code base, same compile-flags, same compiler-versions, etc.)
3+
// produce the same output. In the past, symbol names of monomorphized functions
4+
// were not deterministic (which we want to avoid).
5+
//
6+
// The test tries to exercise as many different paths into symbol name
7+
// generation as possible:
8+
//
9+
// - regular functions
10+
// - generic functions
11+
// - methods
12+
// - statics
13+
// - closures
14+
// - enum variant constructors
15+
// - tuple struct constructors
16+
// - drop glue
17+
// - FnOnce adapters
18+
// - Trait object shims
19+
// - Fn Pointer shims
20+
// See https://github.com/rust-lang/rust/pull/32293
21+
22+
// FIXME(Oneirical): ignore-musl
23+
// FIXME(Oneirical): two of these test blocks will apparently fail on windows
24+
// FIXME(Oneirical): try it on test-various
25+
// # FIXME: Builds of `bin` crate types are not deterministic with debuginfo=2 on
26+
// # Windows.
27+
// # See: https://github.com/rust-lang/rust/pull/87320#issuecomment-920105533
28+
// # Issue: https://github.com/rust-lang/rust/issues/88982
29+
30+
use run_make_support::{bin_name, cwd, diff, rfs, run_in_tmpdir, rust_lib_name, rustc};
31+
32+
fn main() {
33+
// Smoke tests. Simple flags, build should be reproducible.
34+
smoke_test(None);
35+
smoke_test(Some(SmokeFlag::Debug));
36+
smoke_test(Some(SmokeFlag::Opt));
37+
38+
// Builds should be reproducible even through custom library search paths
39+
// or remap path prefixes.
40+
paths_test(PathsFlag::Link);
41+
paths_test(PathsFlag::Remap);
42+
43+
// Builds should be reproducible even if each build is done in a different directory,
44+
// with both --remap-path-prefix and -Z remap-cwd-prefix.
45+
diff_dir_test(CrateType::Bin, RemapType::Path);
46+
diff_dir_test(CrateType::Rlib, RemapType::Path);
47+
// FIXME(Oneirical): this specific case fails the final assertion.
48+
// diff_dir_test(CrateType::Bin, RemapType::Cwd { is_empty: false });
49+
diff_dir_test(CrateType::Rlib, RemapType::Cwd { is_empty: false });
50+
diff_dir_test(CrateType::Rlib, RemapType::Cwd { is_empty: true });
51+
52+
// Builds should be reproducible when using the --extern flag.
53+
run_in_tmpdir(|| {
54+
rustc().input("reproducible-build-aux.rs").run();
55+
rustc()
56+
.input("reproducible-build.rs")
57+
.crate_type("rlib")
58+
.extern_("reproducible_build_aux", rust_lib_name("reproducible_build_aux"))
59+
.run();
60+
rfs::copy(rust_lib_name("reproducible_build"), rust_lib_name("foo"));
61+
rfs::copy(rust_lib_name("reproducible_build_aux"), rust_lib_name("bar"));
62+
rustc()
63+
.input("reproducible-build.rs")
64+
.crate_type("rlib")
65+
.extern_("reproducible_build_aux", rust_lib_name("bar"))
66+
.run();
67+
assert_eq!(rfs::read(rust_lib_name("foo")), rfs::read(rust_lib_name("reproducible_build")));
68+
});
69+
}
70+
71+
#[track_caller]
72+
fn smoke_test(flag: Option<SmokeFlag>) {
73+
run_in_tmpdir(|| {
74+
rustc().input("linker.rs").opt().run();
75+
rustc().input("reproducible-build-aux.rs").run();
76+
let mut compiler1 = rustc();
77+
let mut compiler2 = rustc();
78+
if let Some(flag) = flag {
79+
match flag {
80+
SmokeFlag::Debug => {
81+
compiler1.arg("-g");
82+
compiler2.arg("-g");
83+
}
84+
SmokeFlag::Opt => {
85+
compiler1.opt();
86+
compiler2.opt();
87+
}
88+
};
89+
};
90+
compiler1
91+
.input("reproducible-build.rs")
92+
.linker(&cwd().join(bin_name("linker")).display().to_string())
93+
.run();
94+
compiler2
95+
.input("reproducible-build.rs")
96+
.linker(&cwd().join(bin_name("linker")).display().to_string())
97+
.run();
98+
diff().actual_file("linker-arguments1").expected_file("linker-arguments2").run();
99+
});
100+
}
101+
102+
#[track_caller]
103+
fn paths_test(flag: PathsFlag) {
104+
run_in_tmpdir(|| {
105+
rustc().input("reproducible-build-aux.rs").run();
106+
let mut compiler1 = rustc();
107+
let mut compiler2 = rustc();
108+
match flag {
109+
PathsFlag::Link => {
110+
compiler1.library_search_path("a");
111+
compiler2.library_search_path("b");
112+
}
113+
PathsFlag::Remap => {
114+
compiler1.arg("--remap-path-prefix=/a=/c");
115+
compiler2.arg("--remap-path-prefix=/b=/c");
116+
}
117+
}
118+
compiler1.input("reproducible-build.rs").crate_type("rlib").run();
119+
rfs::rename(rust_lib_name("reproducible_build"), rust_lib_name("foo"));
120+
compiler2.input("reproducible-build.rs").crate_type("rlib").run();
121+
assert_eq!(rfs::read(rust_lib_name("reproducible_build")), rfs::read(rust_lib_name("foo")));
122+
});
123+
}
124+
125+
#[track_caller]
126+
fn diff_dir_test(crate_type: CrateType, remap_type: RemapType) {
127+
run_in_tmpdir(|| {
128+
let base_dir = cwd();
129+
rustc().input("reproducible-build-aux.rs").run();
130+
rfs::create_dir("test");
131+
rfs::copy("reproducible-build.rs", "test/reproducible-build.rs");
132+
let mut compiler1 = rustc();
133+
let mut compiler2 = rustc();
134+
match crate_type {
135+
CrateType::Bin => {
136+
compiler1.crate_type("bin");
137+
compiler2.crate_type("bin");
138+
}
139+
CrateType::Rlib => {
140+
compiler1.crate_type("rlib");
141+
compiler2.crate_type("rlib");
142+
}
143+
}
144+
match remap_type {
145+
RemapType::Path => {
146+
compiler1.arg(&format!("--remap-path-prefix={}=/b", cwd().display()));
147+
compiler2
148+
.arg(format!("--remap-path-prefix={}=/b", base_dir.join("test").display()));
149+
}
150+
RemapType::Cwd { is_empty } => {
151+
compiler1.arg("-g");
152+
compiler2.arg("-g");
153+
if is_empty {
154+
compiler1.arg("-Zremap-cwd-prefix=");
155+
compiler2.arg("-Zremap-cwd-prefix=");
156+
} else {
157+
compiler1.arg("-Zremap-cwd-prefix=.");
158+
compiler2.arg("-Zremap-cwd-prefix=.");
159+
}
160+
}
161+
}
162+
compiler1.input("reproducible-build.rs").run();
163+
match crate_type {
164+
CrateType::Bin => {
165+
rfs::rename(bin_name("reproducible-build"), bin_name("foo"));
166+
}
167+
CrateType::Rlib => {
168+
rfs::rename(rust_lib_name("reproducible_build"), rust_lib_name("foo"));
169+
}
170+
}
171+
std::env::set_current_dir("test").unwrap();
172+
compiler2
173+
.input("reproducible-build.rs")
174+
.library_search_path(&base_dir)
175+
.out_dir(&base_dir)
176+
.run();
177+
std::env::set_current_dir(&base_dir).unwrap();
178+
match crate_type {
179+
CrateType::Bin => {
180+
assert!(rfs::read(bin_name("reproducible-build")) == rfs::read(bin_name("foo")));
181+
}
182+
CrateType::Rlib => {
183+
assert_eq!(
184+
rfs::read(rust_lib_name("foo")),
185+
rfs::read(rust_lib_name("reproducible_build"))
186+
);
187+
}
188+
}
189+
});
190+
}
191+
192+
enum SmokeFlag {
193+
Debug,
194+
Opt,
195+
}
196+
197+
enum PathsFlag {
198+
Link,
199+
Remap,
200+
}
201+
202+
enum CrateType {
203+
Bin,
204+
Rlib,
205+
}
206+
207+
enum RemapType {
208+
Path,
209+
Cwd { is_empty: bool },
210+
}

0 commit comments

Comments
 (0)