Skip to content

Commit 31d0d7a

Browse files
authored
feat: initial import of Rust implementation of Codex CLI in codex-rs/ (openai#629)
As stated in `codex-rs/README.md`: Today, Codex CLI is written in TypeScript and requires Node.js 22+ to run it. For a number of users, this runtime requirement inhibits adoption: they would be better served by a standalone executable. As maintainers, we want Codex to run efficiently in a wide range of environments with minimal overhead. We also want to take advantage of operating system-specific APIs to provide better sandboxing, where possible. To that end, we are moving forward with a Rust implementation of Codex CLI contained in this folder, which has the following benefits: - The CLI compiles to small, standalone, platform-specific binaries. - Can make direct, native calls to [seccomp](https://man7.org/linux/man-pages/man2/seccomp.2.html) and [landlock](https://man7.org/linux/man-pages/man7/landlock.7.html) in order to support sandboxing on Linux. - No runtime garbage collection, resulting in lower memory consumption and better, more predictable performance. Currently, the Rust implementation is materially behind the TypeScript implementation in functionality, so continue to use the TypeScript implmentation for the time being. We will publish native executables via GitHub Releases as soon as we feel the Rust version is usable.
1 parent acc4acc commit 31d0d7a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+14099
-0
lines changed

.github/workflows/rust-ci.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: rust-ci
2+
on:
3+
pull_request: { branches: [main] }
4+
push: { branches: [main] }
5+
6+
# For CI, we build in debug (`--profile dev`) rather than release mode so we
7+
# get signal faster.
8+
9+
jobs:
10+
macos:
11+
runs-on: macos-14
12+
timeout-minutes: 30
13+
defaults:
14+
run:
15+
working-directory: codex-rs
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: dtolnay/rust-toolchain@stable
19+
with:
20+
targets: aarch64-apple-darwin,x86_64-apple-darwin
21+
22+
- name: Initialize failure flag
23+
run: echo "FAILED=" >> $GITHUB_ENV
24+
25+
- name: cargo fmt
26+
run: cargo fmt -- --config imports_granularity=Item --check || echo "FAILED=${FAILED:+$FAILED, }cargo fmt" >> $GITHUB_ENV
27+
28+
- name: cargo test
29+
run: cargo test || echo "FAILED=${FAILED:+$FAILED, }cargo test" >> $GITHUB_ENV
30+
31+
- name: cargo clippy
32+
run: cargo clippy --all-features -- -D warnings || echo "FAILED=${FAILED:+$FAILED, }cargo clippy" >> $GITHUB_ENV
33+
34+
- name: arm64 build
35+
run: cargo build --target aarch64-apple-darwin || echo "FAILED=${FAILED:+$FAILED, }arm64 build" >> $GITHUB_ENV
36+
37+
- name: x86_64 build
38+
run: cargo build --target x86_64-apple-darwin || echo "FAILED=${FAILED:+$FAILED, }x86_64 build" >> $GITHUB_ENV
39+
40+
- name: Fail if any step failed
41+
run: |
42+
if [ -n "$FAILED" ]; then
43+
echo -e "See logs above, as the following steps failed:\n$FAILED"
44+
exit 1
45+
fi
46+
env:
47+
FAILED: ${{ env.FAILED }}
48+
49+
linux-musl-x86_64:
50+
runs-on: ubuntu-24.04
51+
timeout-minutes: 30
52+
defaults:
53+
run:
54+
working-directory: codex-rs
55+
steps:
56+
- uses: actions/checkout@v4
57+
- uses: dtolnay/rust-toolchain@stable
58+
with:
59+
targets: x86_64-unknown-linux-musl
60+
- name: Install musl build tools
61+
run: |
62+
sudo apt update
63+
sudo apt install -y musl-tools pkg-config
64+
65+
- name: Initialize failure flag
66+
run: echo "FAILED=" >> $GITHUB_ENV
67+
68+
- name: cargo fmt
69+
run: cargo fmt -- --config imports_granularity=Item --check || echo "FAILED=${FAILED:+$FAILED, }cargo fmt" >> $GITHUB_ENV
70+
71+
- name: cargo test
72+
run: cargo test || echo "FAILED=${FAILED:+$FAILED, }cargo test" >> $GITHUB_ENV
73+
74+
- name: cargo clippy
75+
run: cargo clippy --all-features -- -D warnings || echo "FAILED=${FAILED:+$FAILED, }cargo clippy" >> $GITHUB_ENV
76+
77+
- name: x86_64 musl build
78+
run: cargo build --target x86_64-unknown-linux-musl || echo "FAILED=${FAILED:+$FAILED, }x86_64 musl build" >> $GITHUB_ENV
79+
80+
- name: Fail if any step failed
81+
run: |
82+
if [ -n "$FAILED" ]; then
83+
echo -e "See logs above, as the following steps failed:\n$FAILED"
84+
exit 1
85+
fi
86+
env:
87+
FAILED: ${{ env.FAILED }}

codex-rs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target/

0 commit comments

Comments
 (0)