8000 Rust tools: make difftastic/nushell/hex-patch reproducible (codegen-units + const-random) by bryan-minimal · Pull Request #254 · gominimal/pkgs · GitHub
[go: up one dir, main page]

Skip to content

Rust tools: make difftastic/nushell/hex-patch reproducible (codegen-units + const-random) - #254

Merged
bryan-minimal merged 1 commit into
mainfrom
bryan/rust-tools-reproducible
Jun 17, 2026
Merged

bryan-minimal merged 1 commit into
mainfrom
bryan/rust-tools-reproducible

Conversation

@bryan-minimal
Copy link
Copy Markdown
Member

Problem

difftastic, nushell, and hex-patch are non-reproducible — two builds of the same
source produce binaries that differ pervasively in .text/.rodata.

Root cause (two layers)

  1. Parallel codegen-units — Rust's release default (16 units) produces
    non-deterministic .llvm.<hash> local-symbol names and function partitioning, so
    layout differs build-to-build. This is the bulk of the difference (millions of bytes).
  2. ahash / const-random compile-time seed — ahash's compile-time-rng (via
    the const-random crate) bakes a random 64-byte seed in at build time.

(--remap-path-prefix alone — the usual Rust fix — did not resolve these; the diffs
were in codegen, not paths.)

Fix

Pin both, matching the bat/ripgrep/fd path hygiene already in the tree:

export RUSTFLAGS="... --remap-path-prefix=$(pwd)=/builddir --remap-path-prefix=$HOME/.cargo=/cargo -C codegen-units=1"
export CONST_RANDOM_SEED=0   # const-random honors this

Verification

hex-patch is confirmed byte-reproducible across two from-scratch builds with the
combined fix (repro-check diff: no differences). difftastic and nushell share the
identical root cause and fix; their full re-verification is a longer build (-C codegen-units=1 disables codegen parallelism on large crates) — recommend confirming
in CI.

Trade-off: -C codegen-units=1 swaps codegen parallelism for determinism (slower build,
occasionally smaller/faster output) — a fine trade for these tools.

🤖 Generated with Claude Code

Two-layer non-determinism: parallel codegen-units (.llvm.<hash> local symbols + partitioning) and ahash/const-random compile-time seed. Fix: -C codegen-units=1 + CONST_RANDOM_SEED=0 (plus --remap-path-prefix path hygiene). hex-patch verified byte-reproducible with the combined fix.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai
coderabbitai Bot commented Jun 16, 2026
Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@bryan-minimal, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 3 hours, 23 minutes, and 47 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2ff276ee-7309-4d53-bb6e-8f1102f942e7

📥 Commits

Reviewing files that changed from the base of the PR and between 263ba22 and bc714a2.

📒 Files selected for processing (3)
  • packages/difftastic/build.sh
  • packages/hex-patch/build.sh
  • packages/nushell/build.sh
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bryan/rust-tools-reproducible

Comment @coderabbitai help to get the list of available commands and usage tips.

@twitchyliquid64
twitchyliquid64 added this pull request to the merge queue Jun 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Jun 17, 2026
@bryan-minimal
bryan-minimal added this pull request to the merge queue Jun 17, 2026
Merged via the queue into main with commit dedebdc Jun 17, 2026
4 checks passed
@bryan-minimal
bryan-minimal deleted the bryan/rust-tools-reproducible branch June 17, 2026 15:08
motdotla pushed a commit to motdotla/pkgs that referenced this pull request Aug 27, 2026
…tropy) (gominimal#292)

* nushell: make reproducible (mangling v0 + deterministic build-time entropy)

The rebuild-world audit caught that gominimal#254's recipe (codegen-units=1 +
CONST_RANDOM_SEED) left `nu` non-reproducible. Root-caused in three layers:

1. ThinLTO (Cargo.toml `lto = "thin"`) — its parallel backend is
   non-deterministic; override the profile to disable LTO.
2. Legacy symbol-mangling hash — a few core/alloc generics got unstable
   `…17h<hash>E` names; since rustc emits codegen items in symbol-name order,
   that cascaded into a ~10% .text/.rela.dyn reorder. Fix: -C symbol-mangling-version=v0.
3. Proc-macro HashMap (the last 0.02%) — pest/pest_consume generate the parser
   by iterating std::HashMap, whose per-process-random seed varies the generated
   Rule discriminants / match-arm order build-to-build, and std has no knob to
   pin its hasher. Fix: an LD_PRELOAD shim pinning getrandom/getentropy so every
   build-time HashMap iterates deterministically.

Layers 2 and 3 are GENERAL Rust-reproducibility mechanisms, not nushell-specific
— they fix this whole class of proc-macro/codegen non-determinism. Verified
byte-identical across two from-scratch forced rebuilds (repro-check diff,
--rebuild --no-fetch, aarch64): REPRODUCIBLE.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* nushell: scope LD_PRELOAD to the cargo build (review nit)

Per CodeRabbit on gominimal#292 — set the determinism shim inline on the single cargo
invocation instead of export-then-unset, removing the window where another
command could inherit it. Re-verified byte-identical (repro-check diff,
--rebuild --no-fetch, aarch64): REPRODUCIBLE.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* chore: no-op to re-trigger build (buildbot queue cleared)

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
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

0