Skip to content

Commit a64142b

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: dist-various-1
2 parents 86e7875 + 1da234c commit a64142b

File tree

3 files changed

+226
-141
lines changed

3 files changed

+226
-141
lines changed

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ run-make/min-global-align/Makefile
1717
run-make/native-link-modifier-bundle/Makefile
1818
run-make/no-alloc-shim/Makefile
1919
run-make/remap-path-prefix-dwarf/Makefile
20-
run-make/reproducible-build/Makefile
2120
run-make/rlib-format-packed-bundled-libs/Makefile
2221
run-make/split-debuginfo/Makefile
2322
run-make/symbol-mangling-hashed/Makefile

tests/run-make/reproducible-build/Makefile

-140
This file was deleted.
+226
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
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+
//@ ignore-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+
46+
// FIXME(Oneirical): Building with crate type set to `bin` AND having -Cdebuginfo=2
47+
// (or `-g`, the shorthand form) enabled will cause reproductibility failures.
48+
// See https://github.com/rust-lang/rust/issues/89911
49+
50+
// This specific case would fail on OSX, should -Cdebuginfo=2 be added.
51+
diff_dir_test(CrateType::Bin, RemapType::Path);
52+
53+
diff_dir_test(CrateType::Rlib, RemapType::Path);
54+
55+
//FIXME(Oneirical): This specific case would fail on both Linux and OSX, should -Cdebuginfo=2
56+
// be added.
57+
// See https://github.com/rust-lang/rust/issues/89911
58+
diff_dir_test(CrateType::Bin, RemapType::Cwd { is_empty: false });
59+
60+
diff_dir_test(CrateType::Rlib, RemapType::Cwd { is_empty: false });
61+
diff_dir_test(CrateType::Rlib, RemapType::Cwd { is_empty: true });
62+
63+
// Builds should be reproducible when using the --extern flag.
64+
run_in_tmpdir(|| {
65+
rustc().input("reproducible-build-aux.rs").run();
66+
rustc()
67+
.input("reproducible-build.rs")
68+
.crate_type("rlib")
69+
.extern_("reproducible_build_aux", rust_lib_name("reproducible_build_aux"))
70+
.run();
71+
rfs::copy(rust_lib_name("reproducible_build"), rust_lib_name("foo"));
72+
rfs::copy(rust_lib_name("reproducible_build_aux"), rust_lib_name("bar"));
73+
rustc()
74+
.input("reproducible-build.rs")
75+
.crate_type("rlib")
76+
.extern_("reproducible_build_aux", rust_lib_name("bar"))
77+
.run();
78+
assert_eq!(rfs::read(rust_lib_name("foo")), rfs::read(rust_lib_name("reproducible_build")));
79+
});
80+
}
81+
82+
#[track_caller]
83+
fn smoke_test(flag: Option<SmokeFlag>) {
84+
run_in_tmpdir(|| {
85+
rustc().input("linker.rs").opt().run();
86+
rustc().input("reproducible-build-aux.rs").run();
87+
let mut compiler1 = rustc();
88+
let mut compiler2 = rustc();
89+
if let Some(flag) = flag {
90+
match flag {
91+
SmokeFlag::Debug => {
92+
compiler1.arg("-g");
93+
compiler2.arg("-g");
94+
}
95+
SmokeFlag::Opt => {
96+
compiler1.opt();
97+
compiler2.opt();
98+
}
99+
};
100+
};
101+
compiler1
102+
.input("reproducible-build.rs")
103+
.linker(&cwd().join(bin_name("linker")).display().to_string())
104+
.run();
105+
compiler2
106+
.input("reproducible-build.rs")
107+
.linker(&cwd().join(bin_name("linker")).display().to_string())
108+
.run();
109+
diff().actual_file("linker-arguments1").expected_file("linker-arguments2").run();
110+
});
111+
}
112+
113+
#[track_caller]
114+
fn paths_test(flag: PathsFlag) {
115+
run_in_tmpdir(|| {
116+
rustc().input("reproducible-build-aux.rs").run();
117+
let mut compiler1 = rustc();
118+
let mut compiler2 = rustc();
119+
match flag {
120+
PathsFlag::Link => {
121+
compiler1.library_search_path("a");
122+
compiler2.library_search_path("b");
123+
}
124+
PathsFlag::Remap => {
125+
compiler1.arg("--remap-path-prefix=/a=/c");
126+
compiler2.arg("--remap-path-prefix=/b=/c");
127+
}
128+
}
129+
compiler1.input("reproducible-build.rs").crate_type("rlib").run();
130+
rfs::rename(rust_lib_name("reproducible_build"), rust_lib_name("foo"));
131+
compiler2.input("reproducible-build.rs").crate_type("rlib").run();
132+
assert_eq!(rfs::read(rust_lib_name("reproducible_build")), rfs::read(rust_lib_name("foo")));
133+
});
134+
}
135+
136+
#[track_caller]
137+
fn diff_dir_test(crate_type: CrateType, remap_type: RemapType) {
138+
run_in_tmpdir(|| {
139+
let base_dir = cwd();
140+
rustc().input("reproducible-build-aux.rs").run();
141+
rfs::create_dir("test");
142+
rfs::copy("reproducible-build.rs", "test/reproducible-build.rs");
143+
let mut compiler1 = rustc();
144+
let mut compiler2 = rustc();
145+
match crate_type {
146+
CrateType::Bin => {
147+
compiler1.crate_type("bin");
148+
compiler2.crate_type("bin");
149+
}
150+
CrateType::Rlib => {
151+
compiler1.crate_type("rlib");
152+
compiler2.crate_type("rlib");
153+
}
154+
}
155+
match remap_type {
156+
RemapType::Path => {
157+
compiler1.arg(&format!("--remap-path-prefix={}=/b", cwd().display()));
158+
compiler2
159+
.arg(format!("--remap-path-prefix={}=/b", base_dir.join("test").display()));
160+
}
161+
RemapType::Cwd { is_empty } => {
162+
// FIXME(Oneirical): Building with crate type set to `bin` AND having -Cdebuginfo=2
163+
// (or `-g`, the shorthand form) enabled will cause reproductibility failures.
164+
// See https://github.com/rust-lang/rust/issues/89911
165+
if !matches!(crate_type, CrateType::Bin) {
166+
compiler1.arg("-Cdebuginfo=2");
167+
compiler2.arg("-Cdebuginfo=2");
168+
}
169+
if is_empty {
170+
compiler1.arg("-Zremap-cwd-prefix=");
171+
compiler2.arg("-Zremap-cwd-prefix=");
172+
} else {
173+
compiler1.arg("-Zremap-cwd-prefix=.");
174+
compiler2.arg("-Zremap-cwd-prefix=.");
175+
}
176+
}
177+
}
178+
compiler1.input("reproducible-build.rs").run();
179+
match crate_type {
180+
CrateType::Bin => {
181+
rfs::rename(bin_name("reproducible-build"), bin_name("foo"));
182+
}
183+
CrateType::Rlib => {
184+
rfs::rename(rust_lib_name("reproducible_build"), rust_lib_name("foo"));
185+
}
186+
}
187+
std::env::set_current_dir("test").unwrap();
188+
compiler2
189+
.input("reproducible-build.rs")
190+
.library_search_path(&base_dir)
191+
.out_dir(&base_dir)
192+
.run();
193+
std::env::set_current_dir(&base_dir).unwrap();
194+
match crate_type {
195+
CrateType::Bin => {
196+
assert!(rfs::read(bin_name("reproducible-build")) == rfs::read(bin_name("foo")));
197+
}
198+
CrateType::Rlib => {
199+
assert_eq!(
200+
rfs::read(rust_lib_name("foo")),
201+
rfs::read(rust_lib_name("reproducible_build"))
202+
);
203+
}
204+
}
205+
});
206+
}
207+
208+
enum SmokeFlag {
209+
Debug,
210+
Opt,
211+
}
212+
213+
enum PathsFlag {
214+
Link,
215+
Remap,
216+
}
217+
218+
enum CrateType {
219+
Bin,
220+
Rlib,
221+
}
222+
223+
enum RemapType {
224+
Path,
225+
Cwd { is_empty: bool },
226+
}

0 commit comments

Comments
 (0)