Skip to content

Commit e752410

Browse files
committed
massive refactor of reproducible-build test
1 parent 3c68b11 commit e752410

File tree

1 file changed

+179
-161
lines changed
  • tests/run-make/reproducible-build

1 file changed

+179
-161
lines changed

tests/run-make/reproducible-build/rmake.rs

+179-161
Original file line numberDiff line numberDiff line change
@@ -18,205 +18,223 @@
1818
// - Trait object shims
1919
// - Fn Pointer shims
2020
// See https://github.com/rust-lang/rust/pull/32293
21+
// Tracking Issue: https://github.com/rust-lang/rust/issues/129080
2122

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};
23+
use run_make_support::{
24+
bin_name, cwd, diff, is_darwin, is_windows, rfs, run_in_tmpdir, rust_lib_name, rustc,
25+
};
3126

3227
fn main() {
33-
run_in_tmpdir(|| {
34-
rustc().input("linker.rs").opt().run();
35-
rustc().input("reproducible-build-aux.rs").run();
36-
rustc()
37-
.input("reproducible-build.rs")
38-
.linker(&cwd().join(bin_name("linker")).display().to_string())
39-
.run();
40-
rustc()
41-
.input("reproducible-build.rs")
42-
.linker(&cwd().join(bin_name("linker")).display().to_string())
43-
.run();
44-
diff().actual_file("linker-arguments1").expected_file("linker-arguments2").run();
45-
});
28+
// Smoke tests. Simple flags, build should be reproducible.
29+
eprintln!("smoke_test => None");
30+
smoke_test(None);
31+
eprintln!("smoke_test => SmokeFlag::Debug");
32+
smoke_test(Some(SmokeFlag::Debug));
33+
eprintln!("smoke_test => SmokeFlag::Opt");
34+
smoke_test(Some(SmokeFlag::Opt));
4635

47-
run_in_tmpdir(|| {
48-
rustc().input("linker.rs").opt().run();
49-
rustc().arg("-g").input("reproducible-build-aux.rs").run();
50-
rustc()
51-
.arg("-g")
52-
.input("reproducible-build.rs")
53-
.linker(&cwd().join(bin_name("linker")).display().to_string())
54-
.run();
55-
rustc()
56-
.arg("-g")
57-
.input("reproducible-build.rs")
58-
.linker(&cwd().join(bin_name("linker")).display().to_string())
59-
.run();
60-
diff().actual_file("linker-arguments1").expected_file("linker-arguments2").run();
61-
});
36+
// Builds should be reproducible even through custom library search paths
37+
// or remap path prefixes.
38+
eprintln!("paths_test => PathsFlag::Link");
39+
paths_test(PathsFlag::Link);
40+
eprintln!("paths_test => PathsFlag::Remap");
41+
paths_test(PathsFlag::Remap);
6242

63-
run_in_tmpdir(|| {
64-
rustc().input("linker.rs").opt().run();
65-
rustc().opt().input("reproducible-build-aux.rs").run();
66-
rustc()
67-
.opt()
68-
.input("reproducible-build.rs")
69-
.linker(&cwd().join(bin_name("linker")).display().to_string())
70-
.run();
71-
rustc()
72-
.opt()
73-
.input("reproducible-build.rs")
74-
.linker(&cwd().join(bin_name("linker")).display().to_string())
75-
.run();
76-
diff().actual_file("linker-arguments1").expected_file("linker-arguments2").run();
77-
});
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.
7845

79-
run_in_tmpdir(|| {
80-
rustc().input("reproducible-build-aux.rs").run();
81-
rustc().input("reproducible-build.rs").crate_type("rlib").library_search_path("b").run();
82-
rfs::copy(rust_lib_name("reproducible_build"), rust_lib_name("foo"));
83-
rustc().input("reproducible-build.rs").crate_type("rlib").library_search_path("a").run();
84-
assert_eq!(rfs::read(rust_lib_name("reproducible_build")), rfs::read(rust_lib_name("foo")));
85-
});
46+
// FIXME(Oneirical): Building with crate type set to `bin` AND having -Cdebuginfo=2
47+
// (or `-g`, the shorthand form) enabled will cause reproducibility failures.
48+
// See https://github.com/rust-lang/rust/issues/89911
49+
50+
if !is_darwin() && !is_windows() {
51+
// FIXME(Oneirical): Bin builds are not reproducible on non-Linux targets.
52+
eprintln!("diff_dir_test => Bin, Path");
53+
diff_dir_test(CrateType::Bin, RemapType::Path);
54+
}
55+
56+
eprintln!("diff_dir_test => Rlib, Path");
57+
diff_dir_test(CrateType::Rlib, RemapType::Path);
58+
59+
// FIXME(Oneirical): This specific case would fail on Linux, should -Cdebuginfo=2
60+
// be added.
61+
// FIXME(Oneirical): Bin builds are not reproducible on non-Linux targets.
62+
// See https://github.com/rust-lang/rust/issues/89911
63+
if !is_darwin() && !is_windows() {
64+
eprintln!("diff_dir_test => Bin, Cwd false");
65+
diff_dir_test(CrateType::Bin, RemapType::Cwd { is_empty: false });
66+
}
8667

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.
8775
run_in_tmpdir(|| {
8876
rustc().input("reproducible-build-aux.rs").run();
8977
rustc()
9078
.input("reproducible-build.rs")
9179
.crate_type("rlib")
92-
.arg("--remap-path-prefix=/a=/c")
80+
.extern_("reproducible_build_aux", rust_lib_name("reproducible_build_aux"))
9381
.run();
9482
rfs::copy(rust_lib_name("reproducible_build"), rust_lib_name("foo"));
83+
rfs::copy(rust_lib_name("reproducible_build_aux"), rust_lib_name("bar"));
9584
rustc()
9685
.input("reproducible-build.rs")
9786
.crate_type("rlib")
98-
.arg("--remap-path-prefix=/b=/c")
87+
.extern_("reproducible_build_aux", rust_lib_name("bar"))
9988
.run();
100-
assert_eq!(rfs::read(rust_lib_name("reproducible_build")), rfs::read(rust_lib_name("foo")));
89+
assert!(rfs::read(rust_lib_name("foo")) == rfs::read(rust_lib_name("reproducible_build")))
10190
});
91+
}
10292

93+
#[track_caller]
94+
fn smoke_test(flag: Option<SmokeFlag>) {
10395
run_in_tmpdir(|| {
96+
rustc().input("linker.rs").opt().run();
10497
rustc().input("reproducible-build-aux.rs").run();
105-
rfs::create_dir("test");
106-
rfs::copy("reproducible-build.rs", "test/reproducible-build.rs");
107-
rustc()
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
108113
.input("reproducible-build.rs")
109-
.crate_type("bin")
110-
.arg(&format!("--remap-path-prefix={}=/b", cwd().display()))
111-
.run();
112-
eprintln!("{:#?}", rfs::shallow_find_dir_entries(cwd()));
113-
rfs::copy(bin_name("reproducible_build"), bin_name("foo"));
114-
rustc()
115-
.input("test/reproducible-build.rs")
116-
.crate_type("bin")
117-
.arg("--remap-path-prefix=/test=/b")
114+
.linker(&cwd().join(bin_name("linker")).display().to_string())
118115
.run();
119-
assert_eq!(rfs::read(bin_name("reproducible_build")), rfs::read(bin_name("foo")));
120-
});
121-
122-
run_in_tmpdir(|| {
123-
rustc().input("reproducible-build-aux.rs").run();
124-
rfs::create_dir("test");
125-
rfs::copy("reproducible-build.rs", "test/reproducible-build.rs");
126-
rustc()
116+
compiler2
127117
.input("reproducible-build.rs")
128-
.crate_type("rlib")
129-
.arg(&format!("--remap-path-prefix={}=/b", cwd().display()))
130-
.run();
131-
rfs::copy(rust_lib_name("reproducible_build"), rust_lib_name("foo"));
132-
rustc()
133-
.input("test/reproducible-build.rs")
134-
.crate_type("rlib")
135-
.arg("--remap-path-prefix=/test=/b")
118+
.linker(&cwd().join(bin_name("linker")).display().to_string())
136119
.run();
137-
assert_eq!(rfs::read(rust_lib_name("reproducible_build")), rfs::read(rust_lib_name("foo")));
120+
diff().actual_file("linker-arguments1").expected_file("linker-arguments2").run();
138121
});
122+
}
139123

124+
#[track_caller]
125+
fn paths_test(flag: PathsFlag) {
140126
run_in_tmpdir(|| {
141127
rustc().input("reproducible-build-aux.rs").run();
142-
rfs::create_dir("test");
143-
rfs::copy("reproducible-build.rs", "test/reproducible-build.rs");
144-
rustc()
145-
.input("reproducible-build.rs")
146-
.crate_type("bin")
147-
.arg("-Zremap-path-prefix=.")
148-
.arg("-Cdebuginfo=2")
149-
.run();
150-
rfs::copy(bin_name("reproducible_build"), bin_name("first"));
151-
rustc()
152-
.input("test/reproducible-build.rs")
153-
.crate_type("bin")
154-
.arg("-Zremap-path-prefix=.")
155-
.arg("-Cdebuginfo=2")
156-
.run();
157-
assert_eq!(rfs::read(bin_name("first")), rfs::read(bin_name("reproducible_build")));
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!(rfs::read(rust_lib_name("foo")) == rfs::read(rust_lib_name("reproducible_build")))
158144
});
145+
}
159146

147+
#[track_caller]
148+
fn diff_dir_test(crate_type: CrateType, remap_type: RemapType) {
160149
run_in_tmpdir(|| {
150+
let base_dir = cwd();
161151
rustc().input("reproducible-build-aux.rs").run();
162152
rfs::create_dir("test");
163153
rfs::copy("reproducible-build.rs", "test/reproducible-build.rs");
164-
rustc()
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 reproducibility failures
175+
// for multiple platforms.
176+
// See https://github.com/rust-lang/rust/issues/89911
177+
// FIXME(#129117): Windows rlib + `-Cdebuginfo=2` + `-Z remap-cwd-prefix=.` seems
178+
// to be unreproducible.
179+
if !matches!(crate_type, CrateType::Bin) && !is_windows() {
180+
compiler1.arg("-Cdebuginfo=2");
181+
compiler2.arg("-Cdebuginfo=2");
182+
}
183+
if is_empty {
184+
compiler1.arg("-Zremap-cwd-prefix=");
185+
compiler2.arg("-Zremap-cwd-prefix=");
186+
} else {
187+
compiler1.arg("-Zremap-cwd-prefix=.");
188+
compiler2.arg("-Zremap-cwd-prefix=.");
189+
}
190+
}
191+
}
192+
compiler1.input("reproducible-build.rs").run();
193+
match crate_type {
194+
CrateType::Bin => {
195+
rfs::rename(bin_name("reproducible-build"), bin_name("foo"));
196+
}
197+
CrateType::Rlib => {
198+
rfs::rename(rust_lib_name("reproducible_build"), rust_lib_name("foo"));
199+
}
200+
}
201+
std::env::set_current_dir("test").unwrap();
202+
compiler2
165203
.input("reproducible-build.rs")
166-
.crate_type("rlib")
167-
.arg("-Zremap-path-prefix=.")
168-
.arg("-Cdebuginfo=2")
169-
.run();
170-
rfs::copy("reproducible_build", "first");
171-
rustc()
172-
.input("test/reproducible-build.rs")
173-
.crate_type("rlib")
174-
.arg("-Zremap-path-prefix=.")
175-
.arg("-Cdebuginfo=2")
176-
.run();
177-
assert_eq!(
178-
rfs::read(rust_lib_name("first")),
179-
rfs::read(rust_lib_name("reproducible_build"))
180-
);
204+
.library_search_path(&base_dir)
205+
.out_dir(&base_dir)
206+
.run();
207+
std::env::set_current_dir(&base_dir).unwrap();
208+
match crate_type {
209+
CrateType::Bin => {
210+
assert!(rfs::read(bin_name("reproducible-build")) == rfs::read(bin_name("foo")));
211+
}
212+
CrateType::Rlib => {
213+
assert!(
214+
rfs::read(rust_lib_name("foo"))
215+
== rfs::read(rust_lib_name("reproducible_build"))
216+
);
217+
}
218+
}
181219
});
220+
}
182221

183-
run_in_tmpdir(|| {
184-
rustc().input("reproducible-build-aux.rs").run();
185-
rfs::create_dir("test");
186-
rfs::copy("reproducible-build.rs", "test/reproducible-build.rs");
187-
rustc()
188-
.input("reproducible-build.rs")
189-
.crate_type("rlib")
190-
.arg("-Zremap-path-prefix=")
191-
.arg("-Cdebuginfo=2")
192-
.run();
193-
rfs::copy(rust_lib_name("reproducible_build"), rust_lib_name("first"));
194-
rustc()
195-
.input("test/reproducible-build.rs")
196-
.crate_type("rlib")
197-
.arg("-Zremap-path-prefix=")
198-
.arg("-Cdebuginfo=2")
199-
.run();
200-
assert_eq!(
201-
rfs::read(rust_lib_name("first")),
202-
rfs::read(rust_lib_name("reproducible_build"))
203-
);
204-
});
222+
enum SmokeFlag {
223+
Debug,
224+
Opt,
225+
}
205226

206-
run_in_tmpdir(|| {
207-
rustc().input("reproducible-build-aux.rs").run();
208-
rustc()
209-
.input("reproducible-build.rs")
210-
.crate_type("rlib")
211-
.extern_("reproducible_build_aux", rust_lib_name("reproducible_build_aux"))
212-
.run();
213-
rfs::copy(rust_lib_name("reproducible_build"), rust_lib_name("foo"));
214-
rfs::copy(rust_lib_name("reproducible_build_aux"), rust_lib_name("bar"));
215-
rustc()
216-
.input("reproducible-build.rs")
217-
.crate_type("rlib")
218-
.extern_("reproducible_build_aux", rust_lib_name("bar"))
219-
.run();
220-
assert_eq!(rfs::read(rust_lib_name("foo")), rfs::read(rust_lib_name("reproducible_build")));
221-
});
227+
enum PathsFlag {
228+
Link,
229+
Remap,
230+
}
231+
232+
enum CrateType {
233+
Bin,
234+
Rlib,
235+
}
236+
237+
enum RemapType {
238+
Path,
239+
Cwd { is_empty: bool },
222240
}

0 commit comments

Comments
 (0)