Skip to content

Commit a537c52

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 try-job: x86_64-msvc try-job: x86_64-mingw try-job: i686-msvc try-job: i686-mingw
2 parents d3a3939 + e753581 commit a537c52

File tree

3 files changed

+237
-141
lines changed

3 files changed

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

0 commit comments

Comments
 (0)