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: https://github.com/openai/codex/pull/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.)
This commit is contained in:
@@ -16,14 +16,23 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { spawnSync } from "child_process";
|
import { spawnSync } from "child_process";
|
||||||
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { fileURLToPath, pathToFileURL } from "url";
|
import { fileURLToPath, pathToFileURL } from "url";
|
||||||
|
|
||||||
// Determine whether the user explicitly wants the Rust CLI.
|
// Determine whether the user explicitly wants the Rust CLI.
|
||||||
const wantsNative =
|
|
||||||
process.env.CODEX_RUST != null
|
// __dirname equivalent in ESM
|
||||||
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
|
// For the @native release of the Node module, the `use-native` file is added,
|
||||||
|
// indicating we should default to the native binary. For other releases,
|
||||||
|
// setting CODEX_RUST=1 will opt-in to the native binary, if included.
|
||||||
|
const wantsNative = fs.existsSync(path.join(__dirname, "use-native")) ||
|
||||||
|
(process.env.CODEX_RUST != null
|
||||||
? ["1", "true", "yes"].includes(process.env.CODEX_RUST.toLowerCase())
|
? ["1", "true", "yes"].includes(process.env.CODEX_RUST.toLowerCase())
|
||||||
: false;
|
: false);
|
||||||
|
|
||||||
// Try native binary if requested.
|
// Try native binary if requested.
|
||||||
if (wantsNative) {
|
if (wantsNative) {
|
||||||
@@ -63,10 +72,6 @@ if (wantsNative) {
|
|||||||
throw new Error(`Unsupported platform: ${platform} (${arch})`);
|
throw new Error(`Unsupported platform: ${platform} (${arch})`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// __dirname equivalent in ESM
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
|
||||||
const __dirname = path.dirname(__filename);
|
|
||||||
|
|
||||||
const binaryPath = path.join(__dirname, "..", "bin", `codex-${targetTriple}`);
|
const binaryPath = path.join(__dirname, "..", "bin", `codex-${targetTriple}`);
|
||||||
const result = spawnSync(binaryPath, process.argv.slice(2), {
|
const result = spawnSync(binaryPath, process.argv.slice(2), {
|
||||||
stdio: "inherit",
|
stdio: "inherit",
|
||||||
@@ -78,10 +83,6 @@ if (wantsNative) {
|
|||||||
|
|
||||||
// Fallback: execute the original JavaScript CLI.
|
// Fallback: execute the original JavaScript CLI.
|
||||||
|
|
||||||
// Determine this script's directory
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
|
||||||
const __dirname = path.dirname(__filename);
|
|
||||||
|
|
||||||
// Resolve the path to the compiled CLI bundle
|
// Resolve the path to the compiled CLI bundle
|
||||||
const cliPath = path.resolve(__dirname, "../dist/cli.js");
|
const cliPath = path.resolve(__dirname, "../dist/cli.js");
|
||||||
const cliUrl = pathToFileURL(cliPath).href;
|
const cliUrl = pathToFileURL(cliPath).href;
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ mkdir -p "$BIN_DIR"
|
|||||||
# Until we start publishing stable GitHub releases, we have to grab the binaries
|
# Until we start publishing stable GitHub releases, we have to grab the binaries
|
||||||
# from the GitHub Action that created them. Update the URL below to point to the
|
# from the GitHub Action that created them. Update the URL below to point to the
|
||||||
# appropriate workflow run:
|
# appropriate workflow run:
|
||||||
WORKFLOW_URL="https://github.com/openai/codex/actions/runs/15087655786"
|
WORKFLOW_URL="https://github.com/openai/codex/actions/runs/15192425904"
|
||||||
WORKFLOW_ID="${WORKFLOW_URL##*/}"
|
WORKFLOW_ID="${WORKFLOW_URL##*/}"
|
||||||
|
|
||||||
ARTIFACTS_DIR="$(mktemp -d)"
|
ARTIFACTS_DIR="$(mktemp -d)"
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ jq --arg version "$VERSION" \
|
|||||||
|
|
||||||
if [[ "$INCLUDE_NATIVE" -eq 1 ]]; then
|
if [[ "$INCLUDE_NATIVE" -eq 1 ]]; then
|
||||||
./scripts/install_native_deps.sh "$TMPDIR" --full-native
|
./scripts/install_native_deps.sh "$TMPDIR" --full-native
|
||||||
|
touch "${TMPDIR}/bin/use-native"
|
||||||
else
|
else
|
||||||
./scripts/install_native_deps.sh "$TMPDIR"
|
./scripts/install_native_deps.sh "$TMPDIR"
|
||||||
fi
|
fi
|
||||||
@@ -130,11 +131,12 @@ popd >/dev/null
|
|||||||
|
|
||||||
echo "Staged version $VERSION for release in $TMPDIR"
|
echo "Staged version $VERSION for release in $TMPDIR"
|
||||||
|
|
||||||
echo "Test Node:"
|
|
||||||
echo " node ${TMPDIR}/bin/codex.js --help"
|
|
||||||
if [[ "$INCLUDE_NATIVE" -eq 1 ]]; then
|
if [[ "$INCLUDE_NATIVE" -eq 1 ]]; then
|
||||||
echo "Test Rust:"
|
echo "Test Rust:"
|
||||||
echo " CODEX_RUST=1 node ${TMPDIR}/bin/codex.js --help"
|
echo " node ${TMPDIR}/bin/codex.js --help"
|
||||||
|
else
|
||||||
|
echo "Test Node:"
|
||||||
|
echo " node ${TMPDIR}/bin/codex.js --help"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Print final hint for convenience
|
# Print final hint for convenience
|
||||||
|
|||||||
Reference in New Issue
Block a user