Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/codex/build.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ let version = "0.155.0" in
owner = "openai",
repo = "codex",
},
build_cost_multiple = 3,
# codegen-units=1 roughly doubled the build (~22 → ~46 min).
build_cost_multiple = 6,
env_dir_mappings = [{ read_only = false, path = "~/.codex", class = 'State }],
} | Attrs,

Expand Down
38 changes: 36 additions & 2 deletions packages/codex/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ cd codex-rs

export CC=gcc
export LD=gcc
export RUSTFLAGS="-C linker=gcc"
# codegen-units=1 and v0 mangling: with the default parallel codegen the binary came
# out different on every build (2026-10 prod-pair diff: 36 of 36 differing symbols were
# `.llvm.<hash>` codegen-unit locals, 49% of the 1.25 GB binary churned). The same two
# flags fixed nushell and difftastic (gominimal/inbox#253). The release profile keeps
# line tables and isn't stripped, so both the source and the cargo-home paths are
# remapped, as nushell and zola do.
export RUSTFLAGS="-C linker=gcc -C codegen-units=1 -C symbol-mangling-version=v0 --remap-path-prefix=$(pwd)=/builddir --remap-path-prefix=$HOME/.cargo=/cargo"

# Needed for crates that use bindgen / libclang
export LIBCLANG_PATH="$(dirname $(find /usr/lib -name 'libclang*.so' | head -1))"
Expand All @@ -26,7 +32,35 @@ if grep -A1 -E '^name = "(rustls-webpki|webpki-roots|webpki-root-certs)"$' Cargo
exit 1
fi

cargo build --locked --release -p codex-cli
# All network access happens here, with real entropy: crates and git deps are fetched
# (and checked against Cargo.lock) before the shim below is loaded, so no TLS session
# runs with the shim's fixed bytes.
cargo fetch --locked

# The workspace locks `v8` (rusty_v8), whose build script downloads a prebuilt
# librusty_v8.a with no checksum. codex-cli doesn't depend on it at this version
# (only codex-code-mode-runtime and codex-v8-poc do). If that changes, this
# nonexistent archive path makes v8's build script panic instead of downloading;
# the fix then is a pinned `Source` for the archive, passed via RUSTY_V8_ARCHIVE.
export RUSTY_V8_ARCHIVE=/nonexistent/librusty_v8-not-pinned.a

# Deterministic build-time entropy, the shim zola and nushell already use: interposes
# getrandom/getentropy so build.rs / proc-macro / rustc-internal HashMaps iterate in the
# same order every build. It wraps only the offline BUILD (`--frozen` refuses any
# network access); the produced binaries are unaffected.
shim_dir=$(mktemp -d)
cat > "$shim_dir/detrand.c" <<'SHIM'
#include <stddef.h>
#include <sys/types.h>
ssize_t getrandom(void *buf, size_t n, unsigned int flags) {
unsigned char *p = buf; size_t i;
for (i = 0; i < n; i++) p[i] = (unsigned char)(0xA5 ^ (i * 157));
return (ssize_t)n;
}
int getentropy(void *buf, size_t n) { getrandom(buf, n, 0); return 0; }
SHIM
gcc -shared -fPIC -O2 -o "$shim_dir/detrand.so" "$shim_dir/detrand.c"
LD_PRELOAD="$shim_dir/detrand.so" cargo build --frozen --release -p codex-cli

mkdir -p $OUTPUT_DIR/usr/bin
install -m 755 target/release/codex $OUTPUT_DIR/usr/bin/codex
Loading