Skip to content

Commit c6ea3a5

Browse files
Auto merge of #142843 - dpaoliello:reproducible-build-2, r=<try>
Enable reproducible-build-2 for Windows Works with MSVC if instructing the linker to avoid timestamps and deleting the PDB between compilations. Addresses item in #128602 --- try-job: x86_64-mingw-* try-job: x86_64-msvc-* try-job: i686-msvc-*
2 parents d4e1159 + e3bd3be commit c6ea3a5

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

src/tools/run-make-support/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub use run::{cmd, run, run_fail, run_with_args};
8383

8484
/// Helpers for checking target information.
8585
pub use targets::{
86-
apple_os, is_aix, is_darwin, is_msvc, is_windows, is_windows_gnu, is_win7, llvm_components_contain,
86+
apple_os, is_aix, is_darwin, is_msvc, is_windows, is_windows_gnu, is_windows_msvc, is_win7, llvm_components_contain,
8787
target, uname,
8888
};
8989

src/tools/run-make-support/src/targets.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ pub fn is_windows_gnu() -> bool {
2828
target().ends_with("windows-gnu")
2929
}
3030

31+
/// Check if target is windows-gnu.
32+
#[must_use]
33+
pub fn is_windows_msvc() -> bool {
34+
target().ends_with("windows-msvc")
35+
}
36+
3137
/// Check if target is win7.
3238
#[must_use]
3339
pub fn is_win7() -> bool {

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,32 @@
77
// See https://github.com/rust-lang/rust/issues/34902
88

99
//@ ignore-cross-compile
10-
//@ ignore-windows
11-
// Reasons:
12-
// 1. The object files are reproducible, but their paths are not, which causes
13-
// the first assertion in the test to fail.
14-
// 2. When the sysroot gets copied, some symlinks must be re-created,
15-
// which is a privileged action on Windows.
1610

17-
use run_make_support::{rfs, rust_lib_name, rustc};
11+
use run_make_support::{is_windows_msvc, rfs, rust_lib_name, rustc};
1812

1913
fn main() {
2014
// test 1: fat lto
2115
rustc().input("reproducible-build-aux.rs").run();
22-
rustc().input("reproducible-build.rs").arg("-Clto=fat").output("reproducible-build").run();
16+
let make_reproducible_build = || {
17+
let mut reproducible_build = rustc();
18+
reproducible_build
19+
.input("reproducible-build.rs")
20+
.arg("-Clto=fat")
21+
.output("reproducible-build");
22+
if is_windows_msvc() {
23+
// Avoids timestamps, etc. when linking.
24+
reproducible_build.arg("-Clink-arg=/Brepro");
25+
}
26+
reproducible_build.run();
27+
};
28+
make_reproducible_build();
2329
rfs::rename("reproducible-build", "reproducible-build-a");
24-
rustc().input("reproducible-build.rs").arg("-Clto=fat").output("reproducible-build").run();
30+
if is_windows_msvc() {
31+
// Linker acts differently if there is already a PDB file with the same
32+
// name.
33+
rfs::remove_file("reproducible-build.pdb");
34+
}
35+
make_reproducible_build();
2536
assert_eq!(rfs::read("reproducible-build"), rfs::read("reproducible-build-a"));
2637

2738
// test 2: sysroot

0 commit comments

Comments
 (0)