Skip to content

Commit a9a9a77

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 e9c965d + 9c6b413 commit a9a9a77

File tree

3 files changed

+235
-141
lines changed

3 files changed

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

0 commit comments

Comments
 (0)