Skip to content

Enable reproducible-build-2 for Windows MSVC #142843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub use run::{cmd, run, run_fail, run_with_args};

/// Helpers for checking target information.
pub use targets::{
apple_os, is_aix, is_darwin, is_msvc, is_windows, is_windows_gnu, is_win7, llvm_components_contain,
apple_os, is_aix, is_darwin, is_msvc, is_windows, is_windows_gnu, is_windows_msvc, is_win7, llvm_components_contain,
target, uname,
};

Expand Down
6 changes: 6 additions & 0 deletions src/tools/run-make-support/src/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ pub fn is_windows_gnu() -> bool {
target().ends_with("windows-gnu")
}

/// Check if target is windows-msvc.
#[must_use]
pub fn is_windows_msvc() -> bool {
target().ends_with("windows-msvc")
}

/// Check if target is win7.
#[must_use]
pub fn is_win7() -> bool {
Expand Down
36 changes: 25 additions & 11 deletions tests/run-make/reproducible-build-2/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,36 @@
// See https://github.com/rust-lang/rust/issues/34902

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

use run_make_support::{rfs, rust_lib_name, rustc};
//@ ignore-windows-gnu
// GNU Linker for Windows is non-deterministic.

use run_make_support::{bin_name, is_windows_msvc, rfs, rust_lib_name, rustc};

fn main() {
// test 1: fat lto
rustc().input("reproducible-build-aux.rs").run();
rustc().input("reproducible-build.rs").arg("-Clto=fat").output("reproducible-build").run();
rfs::rename("reproducible-build", "reproducible-build-a");
rustc().input("reproducible-build.rs").arg("-Clto=fat").output("reproducible-build").run();
assert_eq!(rfs::read("reproducible-build"), rfs::read("reproducible-build-a"));
let make_reproducible_build = || {
let mut reproducible_build = rustc();
reproducible_build
.input("reproducible-build.rs")
.arg("-Clto=fat")
.output(bin_name("reproducible-build"));
if is_windows_msvc() {
// Avoids timestamps, etc. when linking.
reproducible_build.arg("-Clink-arg=/Brepro");
}
reproducible_build.run();
};
make_reproducible_build();
rfs::rename(bin_name("reproducible-build"), "reproducible-build-a");
if is_windows_msvc() {
// Linker acts differently if there is already a PDB file with the same
// name.
rfs::remove_file("reproducible-build.pdb");
}
make_reproducible_build();
assert_eq!(rfs::read(bin_name("reproducible-build")), rfs::read("reproducible-build-a"));

// test 2: sysroot
let sysroot = rustc().print("sysroot").run().stdout_utf8();
Expand Down
Loading