Skip to content

build(bin): embed sourcemaps in the compiled binary - #1213

Open
TheGreatAxios wants to merge 2 commits into
mainfrom
cl-9018-bytecode
Open

TheGreatAxios wants to merge 2 commits into
mainfrom
cl-9018-bytecode

Conversation

@TheGreatAxios

@TheGreatAxios TheGreatAxios commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

What

Adds --sourcemap to the build:bin Bun compile flags (--compile --minify --sourcemap), so crash stacks from the standalone binary resolve to src/*.ts file-and-line instead of minified frames.

Measurements (darwin arm64, same worktree install, 1168 modules both sides)

before (HEAD) after (--sourcemap)
dist/corbits size 74,507,200 B (71.0 MiB) 79,382,752 B (75.7 MiB, +6.5%)
./dist/corbits --help median (5x, /usr/bin/time -p real) 0.75s (0.72/0.73/0.75/0.92/1.54) 0.87s then 0.74s on re-run (0.79/0.82/0.87/1.19/1.99; 0.53/0.57/0.72/0.74/0.80/0.99/1.03)

Startup holds within run-to-run noise (machine variance dominates, ranges overlap); size growth is modest. No rollback trigger met.

Rollback decision (per brief protocol)

--bytecode was tried first (--compile --minify --sourcemap --bytecode) and rolled back: bun build exits 1 with error: "await" can only be used inside an "async" function at src/index.ts:151:18 — Bun bytecode compilation does not accept the entry point's top-level await, and refactoring the entry is out of scope for this change. Kept --sourcemap, dropped --bytecode, re-measured above. No >2x bloat, no codesign breakage (codesign -v passes), no platform build failure with the shipped flags.

Sourcemap packaging

  • The map is embedded in the binary: forced-error stacks (e.g. unrecognized flag) resolve to src/config/index.ts:965, src/index.ts:39/117/151 even with no sidecar present.
  • Bun additionally emits a stray 13.3 MB dist/corbits.map sidecar next to the binary; it is not needed at runtime (binary runs clean and maps stacks without it).
  • Release does not need it: scripts/release.sh compile_bin copies only the binary file into each tarball, never dist/*.map.
  • Follow-up landed (720f4a0): scripts/release.sh compile_bin now carries --sourcemap too (--compile --target=… --minify --sourcemap, no --bytecode), so release binaries carry the embedded map. bash -n syntax check passes.

Verification

  • bun run check green in the worktree (lint, typecheck, dead-exports, build, projects-dir-guard; 8595 pass, 0 fail).
  • Smoke: TUI-less --help launch clean; forced error exits with mapped src/*.ts stack.

Fixes CL-9018

Crash stacks from the standalone binary pointed at minified frames with no source mapping, leaving production failures unactionable. An embedded sourcemap restores file-and-line stacks at a small size cost.
@linear-code

linear-code Bot commented Sep 28, 2026

Copy link
Copy Markdown

CL-9018

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.

1 participant