Skip to content

Commit 3016d66

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: aarch64-gnu try-job: armhf-gnu try-job: test-various try-job: dist-various-1 try-job: x86_64-msvc try-job: x86_64-mingw try-job: i686-msvc try-job: i686-mingw
2 parents 0f442e2 + acce968 commit 3016d66

File tree

3 files changed

+241
-141
lines changed

3 files changed

+241
-141
lines changed

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ run-make/macos-deployment-target/Makefile
1616
run-make/min-global-align/Makefile
1717
run-make/native-link-modifier-bundle/Makefile
1818
run-make/no-alloc-shim/Makefile
19-
run-make/reproducible-build/Makefile
2019
run-make/rlib-format-packed-bundled-libs/Makefile
2120
run-make/split-debuginfo/Makefile
2221
run-make/symbol-mangling-hashed/Makefile

tests/run-make/reproducible-build/Makefile

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

0 commit comments

Comments
 (0)