|
20 | 20 | // See https://github.com/rust-lang/rust/pull/32293
|
21 | 21 |
|
22 | 22 | // FIXME(Oneirical): ignore-musl
|
23 |
| -// FIXME(Oneirical): two of these test blocks will apparently fail on windows |
| 23 | +//@ ignore-windows |
24 | 24 | // FIXME(Oneirical): try it on test-various
|
25 | 25 | // # FIXME: Builds of `bin` crate types are not deterministic with debuginfo=2 on
|
26 | 26 | // # Windows.
|
|
30 | 30 | use run_make_support::{bin_name, cwd, diff, rfs, run_in_tmpdir, rust_lib_name, rustc};
|
31 | 31 |
|
32 | 32 | 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 |
| - }); |
| 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)); |
46 | 37 |
|
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 |
| - }); |
| 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); |
62 | 42 |
|
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. |
78 | 45 |
|
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 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 }); |
86 | 62 |
|
| 63 | + // Builds should be reproducible when using the --extern flag. |
87 | 64 | run_in_tmpdir(|| {
|
88 | 65 | rustc().input("reproducible-build-aux.rs").run();
|
89 | 66 | rustc()
|
90 | 67 | .input("reproducible-build.rs")
|
91 | 68 | .crate_type("rlib")
|
92 |
| - .arg("--remap-path-prefix=/a=/c") |
| 69 | + .extern_("reproducible_build_aux", rust_lib_name("reproducible_build_aux")) |
93 | 70 | .run();
|
94 | 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")); |
95 | 73 | rustc()
|
96 | 74 | .input("reproducible-build.rs")
|
97 | 75 | .crate_type("rlib")
|
98 |
| - .arg("--remap-path-prefix=/b=/c") |
| 76 | + .extern_("reproducible_build_aux", rust_lib_name("bar")) |
99 | 77 | .run();
|
100 |
| - assert_eq!(rfs::read(rust_lib_name("reproducible_build")), rfs::read(rust_lib_name("foo"))); |
| 78 | + assert_eq!(rfs::read(rust_lib_name("foo")), rfs::read(rust_lib_name("reproducible_build"))); |
101 | 79 | });
|
| 80 | +} |
102 | 81 |
|
| 82 | +#[track_caller] |
| 83 | +fn smoke_test(flag: Option<SmokeFlag>) { |
103 | 84 | run_in_tmpdir(|| {
|
| 85 | + rustc().input("linker.rs").opt().run(); |
104 | 86 | rustc().input("reproducible-build-aux.rs").run();
|
105 |
| - rfs::create_dir("test"); |
106 |
| - rfs::copy("reproducible-build.rs", "test/reproducible-build.rs"); |
107 |
| - rustc() |
| 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 |
108 | 102 | .input("reproducible-build.rs")
|
109 |
| - .crate_type("bin") |
110 |
| - .arg(&format!("--remap-path-prefix={}=/b", cwd().display())) |
| 103 | + .linker(&cwd().join(bin_name("linker")).display().to_string()) |
111 | 104 | .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") |
| 105 | + compiler2 |
| 106 | + .input("reproducible-build.rs") |
| 107 | + .linker(&cwd().join(bin_name("linker")).display().to_string()) |
118 | 108 | .run();
|
119 |
| - assert_eq!(rfs::read(bin_name("reproducible_build")), rfs::read(bin_name("foo"))); |
| 109 | + diff().actual_file("linker-arguments1").expected_file("linker-arguments2").run(); |
120 | 110 | });
|
| 111 | +} |
121 | 112 |
|
| 113 | +#[track_caller] |
| 114 | +fn paths_test(flag: PathsFlag) { |
122 | 115 | run_in_tmpdir(|| {
|
123 | 116 | rustc().input("reproducible-build-aux.rs").run();
|
124 |
| - rfs::create_dir("test"); |
125 |
| - rfs::copy("reproducible-build.rs", "test/reproducible-build.rs"); |
126 |
| - rustc() |
127 |
| - .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") |
136 |
| - .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(); |
137 | 132 | assert_eq!(rfs::read(rust_lib_name("reproducible_build")), rfs::read(rust_lib_name("foo")));
|
138 | 133 | });
|
| 134 | +} |
139 | 135 |
|
| 136 | +#[track_caller] |
| 137 | +fn diff_dir_test(crate_type: CrateType, remap_type: RemapType) { |
140 | 138 | run_in_tmpdir(|| {
|
| 139 | + let base_dir = cwd(); |
141 | 140 | rustc().input("reproducible-build-aux.rs").run();
|
142 | 141 | rfs::create_dir("test");
|
143 | 142 | rfs::copy("reproducible-build.rs", "test/reproducible-build.rs");
|
144 |
| - rustc() |
| 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 |
145 | 189 | .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"))); |
| 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 | + } |
158 | 205 | });
|
| 206 | +} |
159 | 207 |
|
160 |
| - run_in_tmpdir(|| { |
161 |
| - rustc().input("reproducible-build-aux.rs").run(); |
162 |
| - rfs::create_dir("test"); |
163 |
| - rfs::copy("reproducible-build.rs", "test/reproducible-build.rs"); |
164 |
| - rustc() |
165 |
| - .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 |
| - ); |
181 |
| - }); |
| 208 | +enum SmokeFlag { |
| 209 | + Debug, |
| 210 | + Opt, |
| 211 | +} |
182 | 212 |
|
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 |
| - }); |
| 213 | +enum PathsFlag { |
| 214 | + Link, |
| 215 | + Remap, |
| 216 | +} |
205 | 217 |
|
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 |
| - }); |
| 218 | +enum CrateType { |
| 219 | + Bin, |
| 220 | + Rlib, |
| 221 | +} |
| 222 | + |
| 223 | +enum RemapType { |
| 224 | + Path, |
| 225 | + Cwd { is_empty: bool }, |
222 | 226 | }
|
0 commit comments