fix(perf): refuse compiler overrides in build-at-ref (#10965)

Merged
LO
10d ago
+295-6

Closes #10965

build-at-ref.sh now exits 1 when the binary would come from a compiler other than the ref's toolchain. That also makes --rustc-out (#10751) record the compiler that actually built it.

  • Env: RUSTC, RUSTC_WRAPPER, RUSTC_WORKSPACE_WRAPPER, RUSTUP_TOOLCHAIN, RUSTC_BOOTSTRAP and the CARGO_BUILD_* forms are refused before any worktree is created. An empty wrapper, RUSTUP_TOOLCHAIN or RUSTC_BOOTSTRAP means no override, and an empty RUSTC_*WRAPPER cancels its CARGO_BUILD_* counterpart, as in cargo.
  • Config: after checkout, --inject and --patch, the script asks cargo for its resolved config (cargo -Z unstable-options config get, with RUSTC_BOOTSTRAP=1 for that query only) and refuses build.rustc, build.rustc-wrapper or build.rustc-workspace-wrapper. The message names the file. If the query fails, the build is refused. On a non-nightly cargo the query drops CARGO_UNSTABLE_* and an [unstable] table is refused, because the stable build ignores them while the bootstrapped query would apply them (reproduced on cargo 1.90).

Rebased onto main after #10751. The only conflict was the --help line range.

Testing: node --test scripts/perf/build-at-ref.test.mjs passes 30/30, including with CI=1 and RUSTC_WRAPPER=sccache exported. The tests cover every env name and each empty-wrapper pairing, each config key in all TOML string forms, CARGO_HOME, ancestor and injected config, the fail-closed path, and the empty-wrapper pass path. Mutation runs confirmed each branch is covered. ShellCheck is clean at warning level. #10751's cache-stream-report.test.mjs still passes. I checked cargo's empty-wrapper precedence by hand with real builds.

Out of scope:

  • ab.sh and dm-e2e-ab build the branch side before calling this script.
  • RUSTFLAGS and CARGO_PROFILE_* still pass through.
  • A cargo earlier on PATH than rustup is not detected.
  • A relative --worktree-root breaks the run, but no caller passes one.

All four were true before this change.

This PR is not critical, so it got an independent reviewer instead of paid CodeRabbit.

šŸ¤– Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Performance builds now stop when compiler overrides are configured through environment variables or Cargo settings, helping prevent builds from using an unexpected compiler.
    • Failures to determine or record the compiler version now return an error.
  • Documentation
    • Help text now explains compiler override checks and compiler-version recording.