Skip to content

build: honor SOURCE_DATE_EPOCH for reproducible builds - #6

Merged
HalFrgrd merged 1 commit into
HalFrgrd:masterfrom
kcajf:reproducible-build
Jul 25, 2026
Merged

build: honor SOURCE_DATE_EPOCH for reproducible builds#6
HalFrgrd merged 1 commit into
HalFrgrd:masterfrom
kcajf:reproducible-build

Conversation

@kcajf

@kcajf kcajf commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

flycomp's build.rs bakes chrono::Utc::now() into the binary via BUILD_TIME, which makes any downstream build (e.g. flyline, and flycomp itself) non-reproducible — the embedded Generated by flycomp … built <timestamp> string differs on every build.

This honors SOURCE_DATE_EPOCH when set (falling back to the wall clock otherwise), which is the standard mechanism build tools and distros use to pin build timestamps. It's the same fix applied to flyline's own build.rs.

Verified downstream: with this change, nix build --rebuild of flyline is byte-identical on aarch64-darwin.

The build script baked chrono::Utc::now() into the binary (BUILD_TIME),
making downstream builds non-reproducible. Honor SOURCE_DATE_EPOCH when
set, falling back to the wall clock otherwise.
kcajf added a commit to kcajf/flyline that referenced this pull request Jul 12, 2026
Neutralize the build-directory and timestamp leaks that made the dylib
differ between builds:
  - --remap-path-prefix: strip the (randomised) build dir from rustc's
    embedded panic/debug source paths.
  - -install_name @rpath/libflyline.dylib: ld64 otherwise defaults a
    dylib's install name to its absolute build-dir output path.
  - -reproducible: let ld64 (956.6, shipped by nixpkgs) normalize the
    LC_UUID, which in turn makes the ad-hoc code signature deterministic.
  - flycomp bumped to a build that pins BUILD_TIME to SOURCE_DATE_EPOCH
    (the last remaining wall-clock leak).

`nix build --rebuild` is byte-identical on aarch64-darwin (exit 0).

NOTE: flycomp temporarily points at a personal fork pending the upstream
PR (HalFrgrd/flycomp#6); re-point to the merged rev once available.
@HalFrgrd
HalFrgrd merged commit 92a5809 into HalFrgrd:master Jul 25, 2026
1 check passed
kcajf added a commit to kcajf/flyline that referenced this pull request Jul 25, 2026
Neutralize the build-directory and timestamp leaks that made the dylib
differ between builds:
  - --remap-path-prefix: strip the (randomised) build dir from rustc's
    embedded panic/debug source paths.
  - -install_name @rpath/libflyline.dylib: ld64 otherwise defaults a
    dylib's install name to its absolute build-dir output path.
  - -reproducible: let ld64 (956.6, shipped by nixpkgs) normalize the
    LC_UUID, which in turn makes the ad-hoc code signature deterministic.
  - flycomp bumped to a build that pins BUILD_TIME to SOURCE_DATE_EPOCH
    (the last remaining wall-clock leak; HalFrgrd/flycomp#6).

`nix build --rebuild` is byte-identical on aarch64-darwin (exit 0).
HalFrgrd pushed a commit to HalFrgrd/flyline that referenced this pull request Jul 25, 2026
## What

`build.rs` currently stamps `BUILD_TIME` with `chrono::Utc::now()`, so
every
build embeds the wall-clock time. This makes the compiled artifact
differ on
each build — the last remaining source of non-determinism when packaging
flyline (e.g. for Nix, where builds are checked for bit-for-bit
reproducibility).

This change honors
[`SOURCE_DATE_EPOCH`](https://reproducible-builds.org/specs/source-date-epoch/):
when the env var is set, `BUILD_TIME` is derived from it; otherwise the
behavior is unchanged (falls back to the current wall-clock time). A
`rerun-if-env-changed=SOURCE_DATE_EPOCH` line ensures the build script
re-runs
when the value changes.

## Why

`SOURCE_DATE_EPOCH` is the cross-ecosystem standard for reproducible
builds and
is set automatically by Nix, most distro build systems, and `cargo`
tooling. No
behavior changes for normal `cargo build`/`cargo install` — the wall
clock is
still used when the var is absent.

## Testing

- `cargo build` with no env var: `BUILD_TIME` is the current time
(unchanged).
- `SOURCE_DATE_EPOCH=1700000000 cargo build`: `BUILD_TIME` is derived
from the
  epoch, and repeated builds produce byte-identical output.

This is the flyline-side counterpart to HalFrgrd/flycomp#6, which
applied the
same fix to flycomp's build script.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants