Skip to content

Commit 4757271

Browse files
committed
docs: add fast rust build guidance
1 parent 53294c9 commit 4757271

3 files changed

Lines changed: 69 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,48 @@ In the codex-rs folder where the rust code lives:
4848
trivial; prefer new modules/files and keep `chatwidget.rs` focused on orchestration.
4949
- When running Rust commands (e.g. `just fix` or `cargo test`) be patient with the command and never try to kill them using the PID. Rust lock can make the execution slow, this is expected.
5050

51+
## Fast Rust Builds
52+
53+
The workspace is large (~90 crates). Use these defaults for fast dev builds:
54+
55+
### Prerequisites (one-time)
56+
```bash
57+
sudo apt install -y mold # fast linker
58+
cargo install sccache # compile cache
59+
```
60+
61+
### Global cargo config (`~/.cargo/config.toml`)
62+
```toml
63+
[build]
64+
jobs = 72 # match core count (nproc)
65+
rustc-wrapper = "sccache"
66+
rustflags = ["-C", "link-arg=-fuse-ld=mold"]
67+
target-dir = "/nvme0n1-disk/cargo-target" # fast disk; adjust per machine
68+
```
69+
70+
### Environment (`~/.bashrc` or `~/.zshrc`)
71+
```bash
72+
export SCCACHE_DIR=/nvme0n1-disk/sccache # keep cache on fast disk
73+
export SCCACHE_CACHE_SIZE=50G
74+
```
75+
76+
### Dev profile (already in `codex-rs/Cargo.toml`)
77+
```toml
78+
[profile.dev]
79+
codegen-units = 512 # trades binary size for parallel codegen speed
80+
```
81+
82+
### Verifying
83+
```bash
84+
cargo build --timings # produces HTML timing report in target/cargo-timings/
85+
sccache --show-stats # check cache hit rate
86+
```
87+
88+
### Portable setup
89+
`~/code/dotfiles/linux-setup.sh` auto-detects the fastest available disk (`/nvme0n1-disk``/scratch``$HOME`) and configures all of the above.
90+
91+
---
92+
5193
Run `just fmt` (in `codex-rs` directory) automatically after you have finished making Rust code changes; do not ask for approval to run it. Additionally, run the tests:
5294

5395
1. Run the test for the specific project that was changed. For example, if changes were made in `codex-rs/tui`, run `cargo test -p codex-tui`.

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,30 @@ cargo build --release -p codex-tui
106106
./target/release/codex "your prompt here"
107107
```
108108

109+
### Fast dev builds
110+
111+
The Rust workspace has ~90 crates. Speed up compilation with:
112+
113+
```bash
114+
# One-time setup
115+
sudo apt install -y mold # fast linker
116+
cargo install sccache # compile cache
117+
118+
# Add to ~/.cargo/config.toml
119+
cat > ~/.cargo/config.toml << 'EOF'
120+
[build]
121+
jobs = 72
122+
rustc-wrapper = "sccache"
123+
rustflags = ["-C", "link-arg=-fuse-ld=mold"]
124+
EOF
125+
126+
# Add to shell rc
127+
export SCCACHE_DIR=/path/to/fast/disk/sccache
128+
export SCCACHE_CACHE_SIZE=50G
129+
```
130+
131+
Profile bottlenecks with `cargo build --timings` and check cache hits with `sccache --show-stats`.
132+
109133
### Build npm package
110134

111135
```bash

codex-rs/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,9 @@ strip = "symbols"
446446
# See https://github.com/openai/codex/issues/1411 for details.
447447
codegen-units = 1
448448

449+
[profile.dev]
450+
codegen-units = 512
451+
449452
[profile.ci-test]
450453
debug = 1 # Reduce debug symbol size
451454
inherits = "test"

0 commit comments

Comments
 (0)