Skip to content

Commit 63deb7c

Browse files
authored
fix: for the @Native release of the Node module, use the Rust version by default (#1084)
Added logic so that when we run `./scripts/stage_release.sh --native` (for the `@native` version of the Node module), we drop a `use-native` file next to `codex.js`. If present, `codex.js` will now run the Rust CLI. Ran `./scripts/stage_release.sh --native` and verified that when the running `codex.js` in the staged folder: ``` $ /var/folders/wm/f209bc1n2bd_r0jncn9s6j_00000gp/T/tmp.efvEvBlSN6/bin/codex.js --version codex-cli 0.0.2505220956 ``` it ran the expected Rust version of the CLI, as desired. While here, I also updated the Rust version to one that I cut today, which includes the new shell environment policy config option: #1061. Note this may "break" some users if the processes spawned by Codex need extra environment variables. (We are still working to determine what the right defaults should be for this option.)
1 parent cb379d7 commit 63deb7c

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

codex-cli/bin/codex.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,23 @@
1616
*/
1717

1818
import { spawnSync } from "child_process";
19+
import fs from "fs";
1920
import path from "path";
2021
import { fileURLToPath, pathToFileURL } from "url";
2122

2223
// Determine whether the user explicitly wants the Rust CLI.
23-
const wantsNative =
24-
process.env.CODEX_RUST != null
24+
25+
// __dirname equivalent in ESM
26+
const __filename = fileURLToPath(import.meta.url);
27+
const __dirname = path.dirname(__filename);
28+
29+
// For the @native release of the Node module, the `use-native` file is added,
30+
// indicating we should default to the native binary. For other releases,
31+
// setting CODEX_RUST=1 will opt-in to the native binary, if included.
32+
const wantsNative = fs.existsSync(path.join(__dirname, "use-native")) ||
33+
(process.env.CODEX_RUST != null
2534
? ["1", "true", "yes"].includes(process.env.CODEX_RUST.toLowerCase())
26-
: false;
35+
: false);
2736

2837
// Try native binary if requested.
2938
if (wantsNative) {
@@ -63,10 +72,6 @@ if (wantsNative) {
6372
throw new Error(`Unsupported platform: ${platform} (${arch})`);
6473
}
6574

66-
// __dirname equivalent in ESM
67-
const __filename = fileURLToPath(import.meta.url);
68-
const __dirname = path.dirname(__filename);
69-
7075
const binaryPath = path.join(__dirname, "..", "bin", `codex-${targetTriple}`);
7176
const result = spawnSync(binaryPath, process.argv.slice(2), {
7277
stdio: "inherit",
@@ -78,10 +83,6 @@ if (wantsNative) {
7883

7984
// Fallback: execute the original JavaScript CLI.
8085

81-
// Determine this script's directory
82-
const __filename = fileURLToPath(import.meta.url);
83-
const __dirname = path.dirname(__filename);
84-
8586
// Resolve the path to the compiled CLI bundle
8687
const cliPath = path.resolve(__dirname, "../dist/cli.js");
8788
const cliUrl = pathToFileURL(cliPath).href;

codex-cli/scripts/install_native_deps.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ mkdir -p "$BIN_DIR"
6565
# Until we start publishing stable GitHub releases, we have to grab the binaries
6666
# from the GitHub Action that created them. Update the URL below to point to the
6767
# appropriate workflow run:
68-
WORKFLOW_URL="https://github.com/openai/codex/actions/runs/15087655786"
68+
WORKFLOW_URL="https://github.com/openai/codex/actions/runs/15192425904"
6969
WORKFLOW_ID="${WORKFLOW_URL##*/}"
7070

7171
ARTIFACTS_DIR="$(mktemp -d)"

codex-cli/scripts/stage_release.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ jq --arg version "$VERSION" \
122122

123123
if [[ "$INCLUDE_NATIVE" -eq 1 ]]; then
124124
./scripts/install_native_deps.sh "$TMPDIR" --full-native
125+
touch "${TMPDIR}/bin/use-native"
125126
else
126127
./scripts/install_native_deps.sh "$TMPDIR"
127128
fi
@@ -130,11 +131,12 @@ popd >/dev/null
130131

131132
echo "Staged version $VERSION for release in $TMPDIR"
132133

133-
echo "Test Node:"
134-
echo " node ${TMPDIR}/bin/codex.js --help"
135134
if [[ "$INCLUDE_NATIVE" -eq 1 ]]; then
136135
echo "Test Rust:"
137-
echo " CODEX_RUST=1 node ${TMPDIR}/bin/codex.js --help"
136+
echo " node ${TMPDIR}/bin/codex.js --help"
137+
else
138+
echo "Test Node:"
139+
echo " node ${TMPDIR}/bin/codex.js --help"
138140
fi
139141

140142
# Print final hint for convenience

0 commit comments

Comments
 (0)