Repository navigation
ci(deploy): reproducible build #453
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
KSXGitHub
wants to merge
10
commits into
master
Choose a base branch
from
claude/rust-reproducible-builds-54t6la
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
324d929
ci: make release binaries reproducible across hosts
claude 3a18a1f
docs(contributing): document reproducible builds
claude 6e76ac5
ci(deploy): drop unnecessary codegen-units pin
claude 0bb8240
docs(contributing): trim redundant reproducible-builds prose
claude d94b149
ci(deploy): add script to reproduce and check a release binary
claude e2bb008
ci(deploy): remap the toolchain sysroot for reproducibility
claude 49d6d3c
ci(deploy): build linux binaries in a pinned container
claude a3f9d9f
docs(contributing): note the containerized reproducible build
claude 1feaec8
ci(deploy): extract the in-container build into a script
claude bf01fe5
docs: trim the reproducible-build comments
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #! /bin/bash | ||
| set -o errexit -o pipefail -o nounset | ||
|
|
||
| # This script runs inside the container started by reproducible-build.sh, where | ||
| # the workspace is mounted at /build. It is not meant to be run on the host. | ||
| target="$1" | ||
| cd /build | ||
|
|
||
| # The chosen target is not always the image's host target. | ||
| rustup target add "$target" >/dev/null | ||
|
|
||
| # Keep the paths that the compiler embeds canonical, matching the remapping that | ||
| # a build outside the container performs. | ||
| commit_hash="$(rustc --version --verbose | awk '/^commit-hash:/ { print $2 }')" | ||
| rust_src="$(rustc --print sysroot)/lib/rustlib/src/rust" | ||
| export CARGO_INCREMENTAL=0 | ||
| export RUSTFLAGS="--remap-path-prefix=${CARGO_HOME:-/usr/local/cargo}=/cargo --remap-path-prefix=$rust_src=/rustc/$commit_hash" | ||
|
|
||
| cargo build --release --all-features --target "$target" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #! /bin/bash | ||
| set -o errexit -o pipefail -o nounset | ||
|
|
||
| # Emit the environment variables that make the release binary reproducible into | ||
| # "$GITHUB_ENV", so that every later step in the job inherits them. | ||
|
|
||
| cargo_home="${CARGO_HOME:-$HOME/.cargo}" | ||
| workspace="${GITHUB_WORKSPACE:-$PWD}" | ||
|
|
||
| # Replace the machine-specific absolute prefixes that the compiler would | ||
| # otherwise embed into the binary. This is the stable equivalent of the | ||
| # still-unstable "-Z trim-paths" option. | ||
| remap="--remap-path-prefix=$cargo_home=/cargo" | ||
| remap="$remap --remap-path-prefix=$workspace=/build" | ||
|
|
||
| # When the "rust-src" component is installed, the compiler rewrites the standard | ||
| # library's "/rustc/<commit-hash>/..." paths to the local toolchain directory. | ||
| # Remap them back, so the result does not depend on whether it is installed. | ||
| commit_hash="$(rustc --version --verbose | awk '/^commit-hash:/ { print $2 }')" | ||
| rust_src="$(rustc --print sysroot)/lib/rustlib/src/rust" | ||
| if [[ -n "$commit_hash" ]]; then | ||
| remap="$remap --remap-path-prefix=$rust_src=/rustc/$commit_hash" | ||
| fi | ||
|
|
||
| if [[ -n "${RUSTFLAGS:-}" ]]; then | ||
| remap="$RUSTFLAGS $remap" | ||
| fi | ||
|
|
||
| { | ||
| echo "RUSTFLAGS=$remap" | ||
| echo "CARGO_INCREMENTAL=0" | ||
| # A fixed timestamp for any build script that would otherwise read the clock. | ||
| echo "SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)" | ||
| } >>"$GITHUB_ENV" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #! /bin/bash | ||
| set -o errexit -o pipefail -o nounset | ||
|
|
||
| cd "$(dirname "$0")" | ||
|
|
||
| # Build a release binary inside a pinned container image. The GNU target takes | ||
| # its C runtime from the build environment rather than from the Rust toolchain, | ||
| # so pinning the image is what makes the output identical on every host. | ||
| # | ||
| # The image ships rustc 1.97.1 on Debian bullseye, whose glibc 2.31 keeps the | ||
| # required glibc version low for broad compatibility. | ||
| target="${1:-x86_64-unknown-linux-gnu}" | ||
| image="rust:1.97.1-slim-bullseye@sha256:dd159e8e44aaa84dffbb7f24a742a96b8d0a26920bd3b46ec2b1778be0da1cdf" | ||
|
|
||
| # Detect a container runtime. PDU_CONTAINER_RUNTIME overrides the choice. | ||
| runtime="${PDU_CONTAINER_RUNTIME:-}" | ||
| if [[ -z "$runtime" ]]; then | ||
| for candidate in docker podman; do | ||
| if command -v "$candidate" >/dev/null; then | ||
| runtime="$candidate" | ||
| break | ||
| fi | ||
| done | ||
| fi | ||
| if [[ -z "$runtime" ]]; then | ||
| echo "error: no container runtime found; install docker or podman, or set PDU_CONTAINER_RUNTIME" >&2 | ||
| exit 1 | ||
| fi | ||
| echo "reproducible-build: using $runtime with $image" >&2 | ||
|
|
||
| mkdir -p target | ||
|
|
||
| # The workspace is mounted read-only, so only the target directory is writable. | ||
| # PDU_CONTAINER_RUN_ARGS passes extra runtime flags for unusual environments, | ||
| # such as a custom CA certificate mount. | ||
| # shellcheck disable=SC2086 | ||
| "$runtime" run --rm --interactive \ | ||
| --env HTTPS_PROXY --env HTTP_PROXY --env NO_PROXY \ | ||
| --env https_proxy --env http_proxy --env no_proxy \ | ||
| --volume "$PWD":/build:ro \ | ||
| --volume "$PWD/target":/build/target \ | ||
| ${PDU_CONTAINER_RUN_ARGS:-} \ | ||
| "$image" \ | ||
| bash /build/ci/build-in-container.sh "$target" | ||
|
|
||
| echo "reproducible-build: built target/$target/release/pdu" >&2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #! /bin/bash | ||
| set -o errexit -o pipefail -o nounset | ||
|
|
||
| cd "$(dirname "$0")" | ||
|
|
||
| # Rebuild a release binary and print its checksum for comparison against a | ||
| # published release. | ||
| target="${1:-x86_64-unknown-linux-gnu}" | ||
|
|
||
| ./reproducible-build.sh "$target" | ||
| sha256sum "target/$target/release/pdu" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.