Skip to content

codex: drop codegen-units=1 (reproducible via the entropy shim), strip, link system sqlite/zstd/oniguruma/bzip2, skip the rusty_v8 fetch - #1713

Merged
bryan-minimal merged 3 commits into
mainfrom
codex-build-speed
Nov 26, 2026
Merged

bryan-minimal merged 3 commits into
mainfrom
codex-build-speed

Conversation

@bryan-minimal

@bryan-minimal bryan-minimal commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Makes packages/codex build faster and install smaller, keeps it reproducible, and links pkgs' C libraries instead of vendored copies.

Changes

  1. Drop -C codegen-units=1 from RUSTFLAGS and keep upstream's release profile (lto = "thin", codegen-units = 4). codex: -C codegen-units=1, v0 symbol mangling, path remap (parallel codegen made every build differ) #878 made the build reproducible with two fixes together: cgu=1 and the detbuild getrandom shim. Its lab double build still differed with cgu=1 alone. With the shim in place, cgu=1 is no longer needed: three local --rebuilds of upstream's profile, at 4, 4 and 6 cargo jobs, produced the same sha256. Set in RUSTFLAGS, cgu=1 applied to all ~1070 crates and made each crate's codegen serial. v0 mangling, path remapping and the shim stay.
  2. debug = 0, strip = "symbols". Upstream keeps line tables and symbols only so its own packaging can archive sidecar symbols before stripping.
  3. System C libraries. LIBSQLITE3_SYS_USE_PKG_CONFIG=1, ZSTD_SYS_USE_PKG_CONFIG=1, RUSTONIG_SYSTEM_LIBONIG=1, plus a generated bzip2.pc, because bzip2 1.0.8 ships none and bzip2-sys only probes pkg-config. Each crate silently falls back to its bundled copy when pkg-config fails, so build.sh now fails closed unless readelf -d lists all four libraries. aws-lc-sys, ring and tree-sitter have no system option and stay bundled.
    • Checked against the locked versions. libsqlite3-sys 0.39.1 has the bundled feature on, uses bundled bindings for 3.54.1 and requires at least 3.45.3; pkgs' sqlite is also 3.54.1. (Its CVE-2026-119586 patch touches only the CLI's shell.c, so the library is the same; the gain is one shared copy that pkgs updates.) The bundled build's only behavioral define that pkgs' sqlite doesn't set is SQLITE_DEFAULT_FOREIGN_KEYS=1, and sqlx turns foreign_keys on itself. unlock_notify is not enabled. zstd-sys 2.0.16+zstd.1.5.7 has legacy and zdict_builder on, and pkgs' zstd is 1.5.7. onig_sys 69.9.1 needs at least 6.9.3; pkgs has 6.9.10.
    • The libraries are added to build_deps (headers and .pc files) and as runtime_deps subsets (sqlite libs, zstd libzstd, oniguruma libs, bzip2 libs).
  4. No more rusty_v8 fetch. Cargo checks out every git dependency in the workspace, submodules included, even for -p codex-cli. v8 (rusty_v8 plus its Chromium submodules) is reached only by code-mode-host, code-mode-runtime and v8-poc. build.sh drops those three members and the v8 [patch] (and fails if those lines change shape), and cargo update --workspace prunes v8 and the 24 crates only it used. The pin check now refuses any registry or git pin that is added or moved; removals are allowed. It also fails if v8 is still in the lock. If codex-cli ever reaches v8, the fetch becomes a new registry pin and the build fails, which covers what the old RUSTY_V8_ARCHIVE=/nonexistent guard did.

Measurements

Local builds ran on an arm64 Mac in a min box with 6 CPUs and 26 GB, using min package build --rebuild. Build-bot numbers come from Cloud Logging (build feed claimed).

baseline (main: cgu=1 on every crate + thin LTO) this PR (head)
build-bot arm64 wall / CPU 2260–2370 s / 7875–8016 s 902 s / 7701 s
build-bot amd64 wall / CPU 2958–3073 s / 9980–10597 s 799 s / 9173 s
build-bot artifact bytes arm64 178.0–181.2 MB, amd64 180.0–184.1 MB arm64 137.3 MB, amd64 136.4 MB
build_cost_multiple 6 8 (cores kept busy, CPU / wall: arm64 8.5, amd64 11.5)
usr/bin/codex (arm64) 1,208,721,376 B (prod artifact, unstripped with line tables; 220.5 MB after llvm-strip --strip-all) 282,277,080 B (stripped)
local wall, 6 jobs did not finish: codex-core's rustc was OOM-killed at 1311 s 1054 s (cargo 16m55s)
local time before the first Compiling 413 s 36 s
reproducible yes (#878) yes: 3 --rebuilds gave the same sha256 62fb906f…a65df0
NEEDED libssl, libcrypto, libgcc_s, libm, libc, ld-linux + libonig.so.5, libbz2.so.1.0, libsqlite3.so, libzstd.so.1

Candidates tried and rejected

  • lto = "off" with 16 codegen units (the first commit of this PR). It was reproducible over 2 rebuilds at 6 and 4 jobs, because with no ThinLTO there are no .llvm.<hash> names. But the stripped binary was 343,685,496 B, 22% bigger than upstream's profile, and it built no faster locally (cargo 18m36s at 6 jobs). Replaced by the second commit.
  • cgu=1 only on codex-cli through a profile package override, keeping thin LTO: not needed once the upstream profile proved reproducible. It also can't help on its own terms: package overrides can't set lto, and ThinLTO promotes locals across every dependency's modules, not only the final crate's.
  • strip = "symbols" alone to hide differing names: not relied on. The 2026-10 diff churned 49% of the binary, which is code layout and not only names. Stripping is in this PR only for size.

Caveat: the reproducibility evidence is three same-host local builds. The build-bot builds each arch once per push, so a prod-pair comparison only comes from a later rebuild.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Release builds now use system-provided SQLite, zstd, Oniguruma, and bzip2 libraries, which are also required at runtime.
    • Build checks verify the expected libraries are linked and that unwanted V8 lockfile entries are absent.
    • Release binaries are built without debug information and have symbols stripped.

…m sqlite/zstd/oniguruma/bzip2, skip the rusty_v8 fetch

- Reproducibility without serial codegen: CARGO_PROFILE_RELEASE_LTO=off + 16
  codegen units replaces `-C codegen-units=1` in RUSTFLAGS (which hit all ~1070
  crates). Without ThinLTO nothing gets a `.llvm.<hash>` name. Two local
  --rebuilds (6 and 4 cargo jobs) gave the same usr/bin/codex sha256.
- debug=0, strip=symbols: 1.21 GB binary -> 344 MB.
- Link pkgs' sqlite, zstd, oniguruma, bzip2 (pkg-config) instead of the -sys
  crates' vendored copies; fail closed on NEEDED if any fell back.
- Drop the three workspace members that alone reach rusty_v8, so cargo stops
  cloning it with its Chromium submodules (fetch phase 413 s -> 36 s locally);
  pin check now allows only removals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bryan-minimal
bryan-minimal requested a review from a team as a code owner November 25, 2026 06:14
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Codex package adds SQLite, zstd, Oniguruma, and bzip2 build and runtime dependencies. The build script updates release settings, adjusts V8 workspace and lockfile checks, and verifies the binary’s linked libraries.

Changes: Codex build

Layer / File(s) Summary
System library build configuration
packages/codex/build.ncl, packages/codex/build.sh
The package adds SQLite, zstd, Oniguruma, and bzip2 build and runtime dependencies. The script configures release settings and system library discovery. The build-cost multiple increases from 6 to 8.
V8 workspace and lockfile checks
packages/codex/build.sh
The script verifies and removes the expected V8-related workspace entries. The lockfile check rejects added registry pins and fails if V8 remains. The script no longer sets the RUSTY_V8_ARCHIVE override.
Binary linkage verification
packages/codex/build.sh
After the build, the script checks for the expected system libraries and prints the binary’s SHA-256, size, and dependency list.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: agent-137

Merge Risk: Minimal · up to b901c

The change links system libraries into the Codex build and verifies the result after the build. No concrete merge-blocking problem was found. Build-bot results are still pending and should be checked before merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names several changes that appear in the changeset: dropping codegen-units=1, stripping the binary, linking system sqlite/zstd/oniguruma/bzip2, and skipping the rusty_v8 fetch. The raw summa…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names several changes that appear in the changeset: dropping codegen-units=1, stripping the binary, linking system sqlite/zstd/oniguruma/bzip2, and skipping the rusty_v8 fetch. The raw summary covers the system library linking and the rusty_v8 removal, and the objectives add the strip and debug settings. The title is specific and accurate, though long at 136 characters and 16 words. The summary does not mention the codegen-units change explicitly, but the objectives confirm it. Overall, the title is fully related to the main change, so it passes.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 9f6219c and b901cc6.

Files selected for processing: 2

  • packages/codex/build.ncl
  • packages/codex/build.sh

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

…the entropy shim), not lto=off

Measured locally (arm64, 6-CPU min box), stripped usr/bin/codex:
- lto=off, cgu=16: 343,685,496 B, same sha256 over 2 rebuilds, cargo 18m36s
- upstream thin/cgu=4: 282,277,080 B, same sha256 over 3 rebuilds (4/4/6 jobs), cargo 16m55s

cgu=1 was needed only alongside the getrandom shim (#878); with the shim the
upstream profile is reproducible on its own, faster and 18% smaller.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bryan-minimal bryan-minimal changed the title codex: lto=off instead of codegen-units=1 everywhere, stripped, system sqlite/zstd/oniguruma/bzip2, skip the rusty_v8 fetch codex: drop codegen-units=1 (reproducible via the entropy shim), strip, link system sqlite/zstd/oniguruma/bzip2, skip the rusty_v8 fetch Nov 25, 2026

@norrietaylor norrietaylor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scope matches the title. Both files are in packages/codex, and every hunk traces to one of the four stated changes.

Clobber none. git log -- packages/codex shows no recent fix reverted. The removed RUSTY_V8_ARCHIVE=/nonexistent guard has a replacement: the added-pin check and the name = "v8" lock check fail before cargo fetch.

Correctness The guards read correctly. The v8_lines count check runs before the sed. comm -13 reports added or moved pins and permits removals. The NEEDED loop fails closed for all four libraries. The four subsetOf output names exist in sqlite, zstd, oniguruma and bzip2. readelf comes from toolchain through binutils. The detbuild preload stays on the one --frozen command. The findings are about comments only. One comment gives a security reason that the code does not support.

Not checked (needs a build or the crate sources): the reproducibility of thin LTO with 4 codegen units on the build-bot. The PR states that the evidence is three same-host builds. I did not check the claim that SQLITE_DEFAULT_FOREIGN_KEYS=1 is the only behavioral define that pkgs' sqlite lacks. packages/sqlite/build.sh sets only SQLITE_ENABLE_COLUMN_METADATA plus fts4, fts5, rtree and session. The upstream Cargo.toml shape that v8_lines matches was not checked. One small note: bzip2's libs glob is usr/lib/*, so the runtime subset can also carry libbz2.a. That is a bzip2 packaging matter, not a defect in this PR.

Comment thread packages/codex/build.sh Resolved
Comment thread packages/codex/build.ncl Resolved
Comment thread packages/codex/build.sh Resolved
…im, build_cost_multiple from build-bot CPU/wall

- sqlite: the pkgs CVE patch only touches shell.c (the CLI), so it is no
  reason to link libsqlite3; the reason is one shared, pkgs-updated copy.
- build_cost_multiple 6 -> 8: build-bot at 6b61b25 kept 8.5 (arm64,
  7701 s CPU / 902 s wall) and 11.5 (amd64, 9173 s / 799 s) cores busy.
- build.sh keeps only why cgu=1 must not come back; measurements and the
  rejected lto=off candidate live in the PR body.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bryan-minimal
bryan-minimal added this pull request to the merge queue Nov 25, 2026
@bryan-minimal
bryan-minimal removed this pull request from the merge queue due to a manual request Nov 25, 2026
@bryan-minimal
bryan-minimal added this pull request to the merge queue Nov 26, 2026
Merged via the queue into main with commit c4a589b Nov 26, 2026
16 checks passed
@bryan-minimal
bryan-minimal deleted the codex-build-speed branch November 26, 2026 07:14
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