Skip to content

Add reproducible build verification to bootstrap #144669

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
10 changes: 10 additions & 0 deletions bootstrap.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,16 @@
# This is only useful for verifying that rustc generates reproducible builds.
#build.full-bootstrap = false

# Set to `true` to verify build reproducibility by compiling the compiler twice
# in separate directories and comparing outputs. This only takes effect when
# running `x.py build` (not other commands) and requires significant time/disk space.
# Can also be enabled via `--reproducible` CLI flag.
#
# Optionally, you can generate a detailed HTML report using the CLI:
# ./x.py build --reproducible --html report.html
# The report is saved to the specified path, and a copy is placed in the Rust source directory.
#build.reproducible = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe call this test-reproducible instead? This option doesn't change anything that causes the build to be reproducible when it otherwise would not be.


# Set the bootstrap/download cache path. It is useful when building rust
# repeatedly in a CI environment.
#build.bootstrap-cache-path = /path/to/shared/cache
Expand Down
34 changes: 33 additions & 1 deletion src/bootstrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ compiler. What actually happens when you invoke bootstrap is:
and the compiler, and then these binaries are then copied to the `stage1`
directory. That compiler is then used to generate the stage1 artifacts which
are then copied to the stage2 directory, and then finally, the stage2
artifacts are generated using that compiler.
artifacts are generated using that compiler. A full stage 2 build (producing
a complete, self-contained compiler) can be executed with:

```bash
./x.py build --stage 2 compiler/rustc
```
This builds the compiler through all bootstrap stages.

The goal of each stage is to (a) leverage Cargo as much as possible and failing
that (b) leverage Rust as much as possible!
Expand Down Expand Up @@ -154,6 +160,32 @@ build/
stage2/
stage3/
```
## Verifying Build Reproducibility

To ensure the compiler produces identical output across builds (important for
security and deterministic builds), you can verify build reproducibility:

```bash
./x.py build --reproducible
```
Or set in `bootstrap.toml`:
```toml
[build]
build.reproducible = true
```

This will:
1. Build the compiler in two separate directories
2. Compare critical artifacts (binaries, libraries)
3. Report any differences
Note: Requires significant time and disk space as it performs two complete builds.
Verification compares:
- Rustc binaries (`bin/`)
- Standard library (`lib/*.so`)
- Compiler RLIBs (`lib/rustlib/`)

For a detailed HTML report, use the --html flag:
./x.py build --reproducible --html report.html

## Extending bootstrap

Expand Down
Loading
Loading