Skip to content

Commit 90ee682

Browse files
ericjutacodex
andcommitted
build(just): add perf-build-local recipe
Add a local PGO-oriented release build recipe for codex-cli with native CPU tuning and optional extra training commands. Co-authored-by: Codex <noreply@openai.com>
1 parent 9a6bcda commit 90ee682

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

justfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,44 @@ bazel-remote-test:
7575
build-for-release:
7676
bazel build //codex-rs/cli:release_binaries --config=remote
7777

78+
# Build a machine-local codex binary with native CPU tuning, panic=abort,
79+
# profile-guided optimization, and mimalloc on top of the existing release
80+
# profile's LTO and codegen-units settings.
81+
#
82+
# You can provide additional representative training commands via:
83+
# CODEX_PGO_TRAIN='
84+
# ./target/release/codex --version >/dev/null
85+
# ./target/release/codex exec --help >/dev/null
86+
# ' just perf-build-local
87+
perf-build-local:
88+
#!/usr/bin/env bash
89+
set -euo pipefail
90+
PGO_DIR="${TMPDIR:-/tmp}/codex-pgo"
91+
rm -rf "$PGO_DIR"
92+
mkdir -p "$PGO_DIR"
93+
LLVM_PROFDATA="$(command -v llvm-profdata || xcrun --find llvm-profdata)"
94+
COMMON_RUSTFLAGS="-C target-cpu=native"
95+
if command -v ld64.lld >/dev/null 2>&1 || command -v lld >/dev/null 2>&1; then
96+
COMMON_RUSTFLAGS="$COMMON_RUSTFLAGS -C link-arg=-fuse-ld=lld"
97+
fi
98+
CARGO_PROFILE_RELEASE_LTO=fat \
99+
CARGO_PROFILE_RELEASE_OPT_LEVEL=3 \
100+
CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1 \
101+
CARGO_PROFILE_RELEASE_PANIC=abort \
102+
RUSTFLAGS="$COMMON_RUSTFLAGS -C profile-generate=$PGO_DIR" \
103+
cargo build -p codex-cli --release --features mimalloc
104+
./target/release/codex --help >/dev/null
105+
./target/release/codex exec --help >/dev/null
106+
./target/release/codex mcp --help >/dev/null
107+
if [ -n "${CODEX_PGO_TRAIN:-}" ]; then sh -lc "$CODEX_PGO_TRAIN"; fi
108+
"$LLVM_PROFDATA" merge -output="$PGO_DIR/merged.profdata" "$PGO_DIR"
109+
CARGO_PROFILE_RELEASE_LTO=fat \
110+
CARGO_PROFILE_RELEASE_OPT_LEVEL=3 \
111+
CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1 \
112+
CARGO_PROFILE_RELEASE_PANIC=abort \
113+
RUSTFLAGS="$COMMON_RUSTFLAGS -C profile-use=$PGO_DIR/merged.profdata -C llvm-args=-pgo-warn-missing-function" \
114+
cargo build -p codex-cli --release --features mimalloc
115+
78116
# Run the MCP server
79117
mcp-server-run *args:
80118
cargo run -p codex-mcp-server -- "$@"

0 commit comments

Comments
 (0)