Skip to content
Open
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
55 changes: 55 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,21 @@ dependencies = [
"wait-timeout",
]

[[package]]
name = "assert_fs"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a652f6cb1f516886fcfee5e7a5c078b9ade62cfcb889524efe5a64d682dd27a9"
dependencies = [
"anstyle",
"doc-comment",
"globwalk",
"predicates",
"predicates-core",
"predicates-tree",
"tempfile",
]

[[package]]
name = "autocfg"
version = "1.5.0"
Expand Down Expand Up @@ -544,8 +559,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2"
dependencies = [
"iana-time-zone",
"js-sys",
"num-traits",
"serde",
"wasm-bindgen",
"windows-link 0.2.1",
]

Expand Down Expand Up @@ -1265,6 +1282,12 @@ version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8975ffdaa0ef3661bfe02dbdcc06c9f829dfafe6a3c474de366a8d5e44276921"

[[package]]
name = "doc-comment"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "780955b8b195a21ab8e4ac6b60dd1dbdcec1dc6c51c0617964b08c81785e12c9"

[[package]]
name = "dyn-clone"
version = "1.0.20"
Expand Down Expand Up @@ -1637,6 +1660,17 @@ dependencies = [
"regex-syntax",
]

[[package]]
name = "globwalk"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bf760ebf69878d9fd8f110c89703d90ce35095324d1f1edcb595c63945ee757"
dependencies = [
"bitflags",
"ignore",
"walkdir",
]

[[package]]
name = "gsgdt"
version = "0.1.2"
Expand Down Expand Up @@ -3311,6 +3345,27 @@ dependencies = [
"walkdir",
]

[[package]]
name = "repro-check"
version = "0.1.0"
dependencies = [
"anyhow",
"assert_fs",
"chrono",
"clap",
"env_logger",
"hex",
"ignore",
"log",
"num_cpus",
"rayon",
"serde",
"sha2",
"tempfile",
"toml 0.8.23",
"walkdir",
]

[[package]]
name = "run_make_support"
version = "0.0.0"
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ members = [
"src/tools/remote-test-client",
"src/tools/remote-test-server",
"src/tools/replace-version-placeholder",
"src/tools/repro-check",
"src/tools/run-make-support",
"src/tools/rust-installer",
"src/tools/rustdoc",
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ bootstrap_tool!(
UnicodeTableGenerator, "src/tools/unicode-table-generator", "unicode-table-generator";
FeaturesStatusDump, "src/tools/features-status-dump", "features-status-dump";
OptimizedDist, "src/tools/opt-dist", "opt-dist", submodules = &["src/tools/rustc-perf"];
ReproCheck, "src/tools/repro-check", "repro-check";
RunMakeSupport, "src/tools/run-make-support", "run_make_support", artifact_kind = ToolArtifactKind::Library;
);

Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/src/core/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,7 @@ impl<'a> Builder<'a> {
llvm::CrtBeginEnd,
tool::RustdocGUITest,
tool::OptimizedDist,
tool::ReproCheck,
tool::CoverageDump,
tool::LlvmBitcodeLinker,
tool::RustcPerf,
Expand Down
23 changes: 23 additions & 0 deletions src/tools/repro-check/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "repro-check"
version = "0.1.0"
edition = "2024"

[dependencies]
anyhow = "1.0"
clap = { version = "4.5", features = ["derive", "env"] }
chrono = { version = "0.4", features = ["clock"] }
env_logger = "0.11"
hex = "0.4"
ignore = "0.4"
log = "0.4"
num_cpus = "1.16"
rayon = "1.10"
serde = { version = "1.0", features = ["derive"] }
sha2 = "0.10"
toml = "0.8"
walkdir = "2.5"

[dev-dependencies]
assert_fs = "1.1"
tempfile = "3.12"
47 changes: 47 additions & 0 deletions src/tools/repro-check/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# repro-check

repro-check is a lightweight tool designed to verify the reproducibility of Rust compiler builds.

It works by creating two separate copies of the Rust source tree, building stage-2 (or a full distribution)
in each copy, and then comparing the resulting sysroots using SHA-256 checksums.
If any discrepancies are detected, repro-check generates a detailed HTML report highlighting the differences
and exits with a non-zero status.

This tool is ideal for developers and CI systems aiming to ensure deterministic, reproducible builds of Rust.

## How to build and run:

```bash
./x.py build src/tools/repro-check
./build/<your-host-triple>/stage1-tools-bin/repro-check --help

# simplest run (host target, stage 2 only)
./build/x86_64-unknown-linux-gnu/stage1-tools-bin/repro-check

# Recommended usage
./build/x86_64-unknown-linux-gnu/stage1-tools-bin/repro-check \
--jobs 16 \
--exclude-pattern .so \
--path-delta 10 \
--html-output my-report.html

# full distribution (takes a long time)
./build/x86_64-unknown-linux-gnu/stage1-tools-bin/repro-check --full-dist

# start from scratch
./build/x86_64-unknown-linux-gnu/stage1-tools-bin/repro-check --clean

All flags:

--src-root <dir> path to the rust checkout (default: current dir)
--target <triple> build for this target (default: host)
--jobs <n> parallel jobs (default: number of CPUs)
--html-output <file> report file (default: repro_report.html)
--exclude-pattern <pat> ignore files ending with <pat> (can be repeated)
--path-delta <n> make the second build’s path longer by n segments (default 10)
--full-dist build a complete distribution instead of stage 2
--clean delete the workspace first
--skip-copy reuse an existing workspace (don’t copy source)
--verbose print more details

- Tests: Run `cargo test` in src/tools/repro-check.
82 changes: 82 additions & 0 deletions src/tools/repro-check/src/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
use std::env;
use std::path::Path;
use std::process::{Command, Stdio};

use anyhow::{Context, Result};
use log::{info, warn};

// Runs x.py in the given environment root. Handles the build or dist command,
// stage limiting, and job config.
pub fn run_xpy(env_root: &Path, jobs: u32, target: Option<&str>, full_dist: bool) -> Result<()> {
let x_py = env_root.join("x.py");

let python = env::var("BOOTSTRAP_PYTHON").unwrap_or_else(|_| {
if cfg!(windows) { "python".to_string() } else { "python3".to_string() }
});

let mut cmd = Command::new(&python);
cmd.arg(&x_py);

let build_cmd = if full_dist { "dist" } else { "build" };
cmd.arg(build_cmd);

if !full_dist {
cmd.arg("--stage").arg("2");
cmd.arg("compiler");
}

if let Some(t) = target {
cmd.arg("--target").arg(t);
}

cmd.arg("-j").arg(jobs.to_string());
cmd.arg("--config").arg("bootstrap.toml");
cmd.current_dir(env_root);
cmd.stdout(Stdio::inherit());
cmd.stderr(Stdio::inherit());

info!("Kicking off: {} {}", python, x_py.display());

let status = cmd.status().with_context(|| format!("Couldn't run x.py in {:?}", env_root))?;
if !status.success() {
return Err(anyhow::anyhow!("Build bombed in {:?}", env_root));
}

Ok(())
}

// Figures out the host triple by asking rustc, or guessing if that fails.
pub fn detect_host(src_root: &Path) -> Result<String> {
let output = Command::new("rustc")
.arg("-vV")
.output()
.context("Couldn't query rustc for version info")?;

if !output.status.success() {
warn!("rustc -vV didn't work; falling back to a guess.");
}

let out_str = String::from_utf8_lossy(&output.stdout);
for line in out_str.lines() {
if line.starts_with("host: ") {
return Ok(line.trim_start_matches("host: ").trim().to_string());
}
}

let arch = if cfg!(target_arch = "x86_64") {
"x86_64"
} else if cfg!(target_arch = "aarch64") {
"aarch64"
} else {
"unknown"
};
let os = if cfg!(target_os = "windows") {
"windows"
} else if cfg!(target_os = "macos") {
"apple-darwin"
} else {
"linux-gnu"
};
info!("Detected host from src root {:?}: {arch}-unknown-{os}", src_root);
Ok(format!("{arch}-unknown-{os}"))
}
Loading
Loading