perf: remap build-machine paths out of release binaries#10177
Conversation
✅ Deploy Preview for rolldown-rs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
3e8182b to
bdd5a93
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3e8182b3c5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
c8d23bd to
7ca1dff
Compare
@rolldown/browser
@rolldown/debug
rolldown
@rolldown/binding-android-arm64
@rolldown/binding-darwin-arm64
@rolldown/binding-darwin-x64
@rolldown/binding-freebsd-x64
@rolldown/binding-linux-arm-gnueabihf
@rolldown/binding-linux-arm64-gnu
@rolldown/binding-linux-arm64-musl
@rolldown/binding-linux-ppc64-gnu
@rolldown/binding-linux-s390x-gnu
@rolldown/binding-linux-x64-gnu
@rolldown/binding-linux-x64-musl
@rolldown/binding-openharmony-arm64
@rolldown/binding-wasm32-wasi
@rolldown/binding-win32-arm64-msvc
@rolldown/binding-win32-x64-msvc
commit: |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
36a8585 to
6b21cdd
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Follow-up review on I found two remaining issues. 1. Fail the build when
|
…acktrace) (#1283) Shrink the shipped `.node` binaries, ported from rolldown/rolldown#10177. Measured on a matched pair of release runs ([baseline](https://github.com/oxc-project/oxc-resolver/actions/runs/28878899374) vs [this branch](https://github.com/oxc-project/oxc-resolver/actions/runs/28878896916)): **−8 to −12%** on build-std targets (darwin-arm64 1,738.8 → 1,543.7 KiB, linux-x64-gnu 2,303.2 → 2,104.7 KiB), −0.2 to −0.3% on the remap-only targets (windows, wasm, freebsd). `napi/build.mjs` wraps `napi build` (same clipanion arg parsing, `--` passthrough) and, **only on CI release builds with an explicit `--target`**, injects: 1. **Path remap** — `--remap-path-prefix` for cargo home → `/cargo`, rustup home → `/rustup`, workspace → `/oxc-resolver`, registry dirs → `/deps`, std sources → `/std`, injected as a cargo `--config` rustflags entry so the `.cargo/config.toml` target rustflags (gnu `nodelete`, wasi stack size) still apply. Panic locations read `/deps/sharded-slab-0.1.7/…` / `/std/alloc/…` instead of build-machine paths. Migrate to `-Ztrim-paths` once it stabilizes (rust-lang/cargo#12137). 2. **build-std without std's `backtrace` feature** — drops the ~200 KiB DWARF symbolizer (gimli/object/addr2line), dead weight under `panic = "abort"` + `strip = "symbols"`. `RUSTC_BOOTSTRAP=1` + `-Zbuild-std=std,panic_abort` CLI flags on the pinned stable toolchain (CLI flags hard-error if the unlock ever breaks; env config would be silently ignored). Excluded: wasm, windows-msvc, FreeBSD (`OXC_RESOLVER_BUILD_STD=0`). Local builds — debug or release — are untouched: real clickable paths, prebuilt std, no `cargo fetch`. `CI=1 pnpm build --target <t>` reproduces a shipped binary byte-for-byte. A CI release build missing `rust-src` fails the job instead of silently shipping the prebuilt std. Accepted behavior change: `RUST_BACKTRACE=1` on shipped binaries prints no stack frames — panic message + source location survive. Today's stripped binaries already can't symbolize (`=1` prints zero frames, `=full` mislabels every frame). Known gap: musl artifacts keep unremapped paths — napi-cli force-sets `RUSTFLAGS` for musl, which suppresses config-level rustflags; the fix belongs upstream. build-std still applies there. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
rustc embeds absolute cargo/rustup/workspace paths into panic locations and tracing callsite metadata. Release binding builds now pass --remap-path-prefix mappings (cargo home, rustup home, workspace root, and each registry src hash dir) so the build machine's filesystem layout stays out of shipped artifacts and the string tables shrink. The flags are injected via a cargo `--config target.'cfg(all())'.rustflags` entry rather than CARGO_BUILD_RUSTFLAGS: the napi CLI promotes the latter to RUSTFLAGS, which would suppress the target rustflags from .cargo/config.toml (windows crt-static / ucrt link-args). Registry dirs are enumerated after `cargo fetch --locked` and sorted so the flag set is deterministic on cold CI runners. Known gap: napi-cli always sets RUSTFLAGS for musl targets, which suppresses config-level rustflags, so musl artifacts keep unremapped paths.
ea99395 to
6ee291e
Compare
Remap the absolute build-machine paths that rustc embeds into shipped release binaries. Two benefits: the build machine's filesystem layout is kept out of published artifacts (12 of 14 targets), and every target's
.nodeshrinks (−52 to −165 KiB, mean −110 KiB).Size impact
Measured as a matched same-day pair: baseline branch
baseline-size-4b018b35pinned at this PR's exact parent4b018b35c, rebuilt today alongside the PR build by the same workflow. Drift is verified zero — the same-day baseline is byte-identical to the original 2026-07-07 baseline on all 14 targets, so every delta below is attributable to exactly this diff. Sizes are the stripped release.nodeper target.All 14 targets — 1,539 KiB saved total, 110 KiB/target mean
Only ~20–47% of each delta is the shorter path strings themselves (e.g. linux-x64-gnu: −69 KiB of strings within the −148 KiB total); the rest is the section-layout shift that adding
--remap-path-prefixinduces in rustc's symbol/metadata handling. That layout effect is also why the two musl targets still shrink even though their paths stay unremapped (see gaps).What changed
packages/rolldown/build-binding.ts— on release builds, builds the--remap-path-prefixset (cargo home →/cargo, rustup home →/rustup, workspace root →/rolldown, eachregistry/src/<hash>dir →/deps) and injects it via a cargo--config target.'cfg(all())'.rustflags=[…]option.rust-src, no-Z build-std, no env flags;.github/workflows/reusable-release-build.ymlis untouched.How it works
rustc embeds absolute paths (
/…/.cargo/registry/src/…, rustup toolchain sources, the workspace root) into panicLocations and tracing callsite metadata. Release builds remap them, so panic messages read/deps/oxc_transformer-0.139.0/src/…and the build machine's filesystem layout stays out of shipped artifacts. Release-only, so local dev backtraces keep clickable absolute paths.Deterministic: the per-registry
registry/src/<hash>dirs only exist after a fetch, so the script runscargo fetch --locked --targetfirst, then enumerates them sorted — the flag set is a function of the lockfile, not of ambient cargo-home state on the runner.Why
--configinstead ofRUSTFLAGS/CARGO_BUILD_RUSTFLAGS: the napi CLI promotesCARGO_BUILD_RUSTFLAGStoRUSTFLAGS, which suppresses all target-level rustflags from.cargo/config.toml— an earlier revision of this PR silently droppedcrt-staticfrom the windows binary that way (its.nodegainedVCRUNTIME140imports). Config-level target rustflags are joined with the config.toml entries instead, so windows keepscrt-staticand still gets remapped.Verification (from the PR artifacts)
/home/runner,/Users/runner,runneradmin, orD:\astrings (e.g. linux-x64-gnu 605 → 0, win32-x64-msvc 878 → 0).crt-staticintact — 0VCRUNTIME140imports; the.nodestays statically linked to the CRT.Known gaps / follow-ups
linux-x64-musl,linux-arm64-musl): napi-cli unconditionally setsRUSTFLAGSfor musl (-C target-feature=-crt-static), suppressing the config-level rustflags, so ~500/home/runner/.cargo/registry/…strings remain — no privacy benefit on musl (the size still drops via the layout effect). Root cause is the CLI'sCARGO_BUILD_RUSTFLAGS→RUSTFLAGSpromotion; the durable fix is upstream in napi-rs.-Ztrim-pathswhen it stabilizes (Tracking Issue for trim-paths RFC 3127 rust-lang/cargo#12137).🤖 Generated with Claude Code