mirror of
https://github.com/openai/codex.git
synced 2026-09-15 12:08:01 +00:00
feat: support local development using Buck2
This commit is contained in:
91
scripts/buck2
Executable file
91
scripts/buck2
Executable file
@@ -0,0 +1,91 @@
|
||||
#!/usr/bin/env dotslash
|
||||
|
||||
{
|
||||
"name": "buck2",
|
||||
"platforms": {
|
||||
"macos-aarch64": {
|
||||
"size": 33146442,
|
||||
"hash": "blake3",
|
||||
"digest": "2940f7436659784c8e6e628ebdbe01c02b565901e37c0ccc22d910a549c8f56a",
|
||||
"format": "zst",
|
||||
"path": "buck2-aarch64-apple-darwin",
|
||||
"providers": [
|
||||
{
|
||||
"url": "https://github.com/facebook/buck2/releases/download/2025-12-15/buck2-aarch64-apple-darwin.zst"
|
||||
}
|
||||
]
|
||||
},
|
||||
"windows-aarch64": {
|
||||
"size": 28937384,
|
||||
"hash": "blake3",
|
||||
"digest": "1f91d6fd0db612b6ce62b18d9267dec87ea076d83f6bd316d29a3264f9dad4f7",
|
||||
"format": "zst",
|
||||
"path": "buck2-aarch64-pc-windows-msvc.exe",
|
||||
"providers": [
|
||||
{
|
||||
"url": "https://github.com/facebook/buck2/releases/download/2025-12-15/buck2-aarch64-pc-windows-msvc.exe.zst"
|
||||
}
|
||||
]
|
||||
},
|
||||
"linux-aarch64": {
|
||||
"size": 34435966,
|
||||
"hash": "blake3",
|
||||
"digest": "0e0a599cf3d9da6d81fe8b615fefa0d57d0b4c3117cbc9984a74d45aaf061cad",
|
||||
"format": "zst",
|
||||
"path": "buck2-aarch64-unknown-linux-musl",
|
||||
"providers": [
|
||||
{
|
||||
"url": "https://github.com/facebook/buck2/releases/download/2025-12-15/buck2-aarch64-unknown-linux-musl.zst"
|
||||
}
|
||||
]
|
||||
},
|
||||
"linux-riscv64": {
|
||||
"size": 36811888,
|
||||
"hash": "blake3",
|
||||
"digest": "52dcb7df8353283d95858cc03eb4acb4014d4ae06c3ad244f2c32c9ff5e4343c",
|
||||
"format": "zst",
|
||||
"path": "buck2-riscv64gc-unknown-linux-gnu",
|
||||
"providers": [
|
||||
{
|
||||
"url": "https://github.com/facebook/buck2/releases/download/2025-12-15/buck2-riscv64gc-unknown-linux-gnu.zst"
|
||||
}
|
||||
]
|
||||
},
|
||||
"macos-x86_64": {
|
||||
"size": 35331653,
|
||||
"hash": "blake3",
|
||||
"digest": "3834c662779ac9c3de22a8b0e6b85aacc2df21a716fa5a9316374e676ab69e64",
|
||||
"format": "zst",
|
||||
"path": "buck2-x86_64-apple-darwin",
|
||||
"providers": [
|
||||
{
|
||||
"url": "https://github.com/facebook/buck2/releases/download/2025-12-15/buck2-x86_64-apple-darwin.zst"
|
||||
}
|
||||
]
|
||||
},
|
||||
"windows-x86_64": {
|
||||
"size": 30576683,
|
||||
"hash": "blake3",
|
||||
"digest": "9df9a89e9ffba06eef0f3808dd802280380922cf26eba87aebb6313847c4754e",
|
||||
"format": "zst",
|
||||
"path": "buck2-x86_64-pc-windows-msvc.exe",
|
||||
"providers": [
|
||||
{
|
||||
"url": "https://github.com/facebook/buck2/releases/download/2025-12-15/buck2-x86_64-pc-windows-msvc.exe.zst"
|
||||
}
|
||||
]
|
||||
},
|
||||
"linux-x86_64": {
|
||||
"size": 35814139,
|
||||
"hash": "blake3",
|
||||
"digest": "3c78e830016fd68156913a830a5376b278ae366ffc976f155ba3d4b455a2f6e9",
|
||||
"format": "zst",
|
||||
"path": "buck2-x86_64-unknown-linux-musl",
|
||||
"providers": [
|
||||
{
|
||||
"url": "https://github.com/facebook/buck2/releases/download/2025-12-15/buck2-x86_64-unknown-linux-musl.zst"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
80
scripts/buildifier
Executable file
80
scripts/buildifier
Executable file
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env dotslash
|
||||
|
||||
// Buildifier is published as raw binaries (not archived), so this manifest omits
|
||||
// the optional `format` field.
|
||||
//
|
||||
// TODO: Add `windows-aarch64` once the buildtools releases include a Windows
|
||||
// arm64 artifact. Support was added in https://github.com/bazelbuild/buildtools/issues/874,
|
||||
// but as of v8.2.1, only windows-amd64 is available.
|
||||
{
|
||||
"name": "buildifier",
|
||||
"platforms": {
|
||||
"macos-aarch64": {
|
||||
"size": 7717890,
|
||||
"hash": "blake3",
|
||||
"digest": "1f01da46c314bd22890d92731b44bcfc555331c87bc113c72c9be13eaa27cb59",
|
||||
"path": "buildifier",
|
||||
"providers": [
|
||||
{
|
||||
"url": "https://github.com/bazelbuild/buildtools/releases/download/v8.2.1/buildifier-darwin-arm64"
|
||||
}
|
||||
]
|
||||
},
|
||||
"linux-aarch64": {
|
||||
"size": 7755744,
|
||||
"hash": "blake3",
|
||||
"digest": "9a35407ecf3d4aa0daf493a364c1a68a2a469f0f96c295f85ab29deb46265f16",
|
||||
"path": "buildifier",
|
||||
"providers": [
|
||||
{
|
||||
"url": "https://github.com/bazelbuild/buildtools/releases/download/v8.2.1/buildifier-linux-arm64"
|
||||
}
|
||||
]
|
||||
},
|
||||
"linux-riscv64": {
|
||||
"size": 7895176,
|
||||
"hash": "blake3",
|
||||
"digest": "90abd14b0eac635de23273588d2224624541cf6a45f548334252182a45a2f9a6",
|
||||
"path": "buildifier",
|
||||
"providers": [
|
||||
{
|
||||
"url": "https://github.com/bazelbuild/buildtools/releases/download/v8.2.1/buildifier-linux-riscv64"
|
||||
}
|
||||
]
|
||||
},
|
||||
"macos-x86_64": {
|
||||
"size": 7776816,
|
||||
"hash": "blake3",
|
||||
"digest": "f367d5e52779571e4da8363b5db2cb60b64c1c97d83ab53de3eaa60d598e8bf1",
|
||||
"path": "buildifier",
|
||||
"providers": [
|
||||
{
|
||||
"url": "https://github.com/bazelbuild/buildtools/releases/download/v8.2.1/buildifier-darwin-amd64"
|
||||
}
|
||||
]
|
||||
},
|
||||
"windows-x86_64": {
|
||||
"size": 8020480,
|
||||
"hash": "blake3",
|
||||
"digest": "1aa436cdcbda55ab32ac18bf76940c8bc83d548c424e9e7db660ee38fb9a91fc",
|
||||
"path": "buildifier.exe",
|
||||
"providers": [
|
||||
{
|
||||
"url": "https://github.com/bazelbuild/buildtools/releases/download/v8.2.1/buildifier-windows-amd64.exe"
|
||||
}
|
||||
]
|
||||
},
|
||||
"linux-x86_64": {
|
||||
"size": 7882884,
|
||||
"hash": "blake3",
|
||||
"digest": "0405f14324a9dae109a9fffb556b49adff9d6fd710f2648d2a6787e000f6b8f9",
|
||||
"path": "buildifier",
|
||||
"providers": [
|
||||
{
|
||||
"url": "https://github.com/bazelbuild/buildtools/releases/download/v8.2.1/buildifier-linux-amd64"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
67
scripts/reindeer
Executable file
67
scripts/reindeer
Executable file
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env dotslash
|
||||
|
||||
{
|
||||
"name": "reindeer",
|
||||
"platforms": {
|
||||
"macos-aarch64": {
|
||||
"size": 10333626,
|
||||
"hash": "blake3",
|
||||
"digest": "087035eba5af3addbbd79354b48ba8c3b5696d1d301ee68023b386e113a68b13",
|
||||
"format": "zst",
|
||||
"path": "reindeer-aarch64-apple-darwin",
|
||||
"providers": [
|
||||
{
|
||||
"url": "https://github.com/facebookincubator/reindeer/releases/download/v2025.11.24.00/reindeer-aarch64-apple-darwin.zst"
|
||||
}
|
||||
]
|
||||
},
|
||||
"linux-aarch64": {
|
||||
"size": 12023922,
|
||||
"hash": "blake3",
|
||||
"digest": "1c41919ddadbdd2390b43a6d4a97267e079038fcb3c42db14868627b0b6eaa6d",
|
||||
"format": "zst",
|
||||
"path": "reindeer-aarch64-unknown-linux-musl",
|
||||
"providers": [
|
||||
{
|
||||
"url": "https://github.com/facebookincubator/reindeer/releases/download/v2025.11.24.00/reindeer-aarch64-unknown-linux-musl.zst"
|
||||
}
|
||||
]
|
||||
},
|
||||
"macos-x86_64": {
|
||||
"size": 10444977,
|
||||
"hash": "blake3",
|
||||
"digest": "8242100bf3b07bd5665c07f42e082a2546b39a2d096c556c19db62d879604c3c",
|
||||
"format": "zst",
|
||||
"path": "reindeer-x86_64-apple-darwin",
|
||||
"providers": [
|
||||
{
|
||||
"url": "https://github.com/facebookincubator/reindeer/releases/download/v2025.11.24.00/reindeer-x86_64-apple-darwin.zst"
|
||||
}
|
||||
]
|
||||
},
|
||||
"windows-x86_64": {
|
||||
"size": 9285431,
|
||||
"hash": "blake3",
|
||||
"digest": "c90e79a55f15b20021eb5ee6ddd4149cb1f6c013cfca4d7ab3902e94b1de0dd3",
|
||||
"format": "zst",
|
||||
"path": "reindeer-x86_64-pc-windows-msvc.exe",
|
||||
"providers": [
|
||||
{
|
||||
"url": "https://github.com/facebookincubator/reindeer/releases/download/v2025.11.24.00/reindeer-x86_64-pc-windows-msvc.exe.zst"
|
||||
}
|
||||
]
|
||||
},
|
||||
"linux-x86_64": {
|
||||
"size": 12135295,
|
||||
"hash": "blake3",
|
||||
"digest": "ad5cdd028d244d47f6ba2368f9c8a9ab1c19451a046b917ce84b07acc7fee319",
|
||||
"format": "zst",
|
||||
"path": "reindeer-x86_64-unknown-linux-musl",
|
||||
"providers": [
|
||||
{
|
||||
"url": "https://github.com/facebookincubator/reindeer/releases/download/v2025.11.24.00/reindeer-x86_64-unknown-linux-musl.zst"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
218
scripts/setup_buck2_local.sh
Executable file
218
scripts/setup_buck2_local.sh
Executable file
@@ -0,0 +1,218 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
|
||||
usage() {
|
||||
cat <<'EOF'
|
||||
Usage: scripts/setup_buck2_local.sh [--build]
|
||||
|
||||
Sets up local-only Buck2 + Reindeer artifacts for codex-rs:
|
||||
- vendors crates into codex-rs/third-party/vendor/
|
||||
- generates codex-rs/third-party/BUCK via reindeer buckify
|
||||
- generates codex-rs/**/BUCK for workspace crates
|
||||
- generates a toolchain definition under codex-rs/toolchains/BUCK
|
||||
|
||||
All generated Buck artifacts are expected to be gitignored (BUCK files,
|
||||
codex-rs/third-party, buck-out).
|
||||
|
||||
Environment:
|
||||
REINDEER_BIN Optional path to reindeer binary (default: scripts/reindeer)
|
||||
BUCK2_BIN Optional path to buck2 binary (default: scripts/buck2)
|
||||
|
||||
If invoked from within Codex CLI, you may want:
|
||||
env -u BASH_EXEC_WRAPPER -u CODEX_ESCALATE_SOCKET buck2 build //codex-rs/cli:codex
|
||||
EOF
|
||||
}
|
||||
|
||||
DO_BUILD=0
|
||||
if [[ "${1:-}" == "--help" || "${1:-}" == "-h" ]]; then
|
||||
usage
|
||||
exit 0
|
||||
elif [[ "${1:-}" == "--build" ]]; then
|
||||
DO_BUILD=1
|
||||
elif [[ -n "${1:-}" ]]; then
|
||||
echo "Unknown argument: $1" >&2
|
||||
usage >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
REINDEER_BIN="${REINDEER_BIN:-}"
|
||||
if [[ -z "${REINDEER_BIN}" ]]; then
|
||||
if [[ -x "${REPO_ROOT}/scripts/reindeer" ]]; then
|
||||
REINDEER_BIN="${REPO_ROOT}/scripts/reindeer"
|
||||
elif command -v reindeer >/dev/null 2>&1; then
|
||||
REINDEER_BIN="$(command -v reindeer)"
|
||||
else
|
||||
echo "Could not find reindeer. Set REINDEER_BIN or use scripts/reindeer." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
BUCK2_BIN="${BUCK2_BIN:-}"
|
||||
if [[ -z "${BUCK2_BIN}" ]]; then
|
||||
if [[ -x "${REPO_ROOT}/scripts/buck2" ]]; then
|
||||
BUCK2_BIN="${REPO_ROOT}/scripts/buck2"
|
||||
elif command -v buck2 >/dev/null 2>&1; then
|
||||
BUCK2_BIN="$(command -v buck2)"
|
||||
else
|
||||
echo "Could not find buck2. Set BUCK2_BIN or use scripts/buck2." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
BUILDIFIER_BIN="${BUILDIFIER_BIN:-}"
|
||||
if [[ -z "${BUILDIFIER_BIN}" ]]; then
|
||||
if [[ -e "${REPO_ROOT}/scripts/buildifier" ]]; then
|
||||
BUILDIFIER_BIN="${REPO_ROOT}/scripts/buildifier"
|
||||
elif command -v buildifier >/dev/null 2>&1; then
|
||||
BUILDIFIER_BIN="$(command -v buildifier)"
|
||||
else
|
||||
BUILDIFIER_BIN=""
|
||||
fi
|
||||
fi
|
||||
|
||||
cd "${REPO_ROOT}"
|
||||
|
||||
# Resolve the Rust toolchain used by codex-rs so Buck uses the same compiler
|
||||
# regardless of the working directory Buck actions run in.
|
||||
RUST_TOOLCHAIN="$(
|
||||
python3 - <<'PY'
|
||||
import pathlib, re
|
||||
text = pathlib.Path("codex-rs/rust-toolchain.toml").read_text(encoding="utf-8")
|
||||
m = re.search(r'(?m)^channel\s*=\s*"([^"]+)"\s*$', text)
|
||||
if not m:
|
||||
raise SystemExit("Could not find toolchain channel in codex-rs/rust-toolchain.toml")
|
||||
print(m.group(1))
|
||||
PY
|
||||
)"
|
||||
|
||||
if command -v rustup >/dev/null 2>&1; then
|
||||
RUSTC_PATH="$(rustup which rustc --toolchain "${RUST_TOOLCHAIN}")"
|
||||
RUSTDOC_PATH="$(rustup which rustdoc --toolchain "${RUST_TOOLCHAIN}")"
|
||||
if rustup which clippy-driver --toolchain "${RUST_TOOLCHAIN}" >/dev/null 2>&1; then
|
||||
CLIPPY_DRIVER_PATH="$(rustup which clippy-driver --toolchain "${RUST_TOOLCHAIN}")"
|
||||
else
|
||||
CLIPPY_DRIVER_PATH="clippy-driver"
|
||||
fi
|
||||
else
|
||||
echo "rustup not found; falling back to rustc/rustdoc from PATH (may not match codex-rs toolchain)." >&2
|
||||
RUSTC_PATH="rustc"
|
||||
RUSTDOC_PATH="rustdoc"
|
||||
CLIPPY_DRIVER_PATH="clippy-driver"
|
||||
fi
|
||||
|
||||
# Reindeer canonicalizes third_party_dir up-front, so it must exist.
|
||||
mkdir -p codex-rs/third-party
|
||||
|
||||
# Ensure we have an ignored Cargo.lock next to the manifest Reindeer uses.
|
||||
if [[ ! -e "codex-rs/cli/Cargo.lock" ]]; then
|
||||
(
|
||||
cd codex-rs/cli
|
||||
# Prefer a symlink (fast), but fall back to copying if symlinks are unsupported.
|
||||
if ln -s ../Cargo.lock Cargo.lock 2>/dev/null; then
|
||||
true
|
||||
else
|
||||
cp ../Cargo.lock Cargo.lock
|
||||
fi
|
||||
)
|
||||
fi
|
||||
|
||||
# Ensure Buck can load bzl files from codex-rs/buck2 by creating an (ignored)
|
||||
# BUCK file to define the package.
|
||||
mkdir -p codex-rs/buck2
|
||||
if [[ ! -e "codex-rs/buck2/BUCK" ]]; then
|
||||
: > codex-rs/buck2/BUCK
|
||||
fi
|
||||
|
||||
# Generate a minimal toolchain package under the toolchains cell.
|
||||
mkdir -p codex-rs/toolchains
|
||||
# This BUCK file is local-only (gitignored), so we bake in absolute tool paths.
|
||||
cat > codex-rs/toolchains/BUCK <<EOF
|
||||
load("@prelude//tests:test_toolchain.bzl", "noop_test_toolchain")
|
||||
load("@prelude//toolchains:cxx.bzl", "system_cxx_toolchain")
|
||||
load("@prelude//toolchains:genrule.bzl", "system_genrule_toolchain")
|
||||
load(
|
||||
"@prelude//toolchains:python.bzl",
|
||||
"system_python_bootstrap_toolchain",
|
||||
"system_python_toolchain",
|
||||
)
|
||||
load("@prelude//toolchains:remote_test_execution.bzl", "remote_test_execution_toolchain")
|
||||
load("@root//codex-rs/buck2:codex_rust_toolchain.bzl", "codex_rust_toolchain")
|
||||
|
||||
system_cxx_toolchain(
|
||||
name = "cxx",
|
||||
visibility = ["PUBLIC"],
|
||||
)
|
||||
|
||||
system_genrule_toolchain(
|
||||
name = "genrule",
|
||||
visibility = ["PUBLIC"],
|
||||
)
|
||||
|
||||
system_python_toolchain(
|
||||
name = "python",
|
||||
visibility = ["PUBLIC"],
|
||||
)
|
||||
|
||||
system_python_bootstrap_toolchain(
|
||||
name = "python_bootstrap",
|
||||
visibility = ["PUBLIC"],
|
||||
)
|
||||
|
||||
codex_rust_toolchain(
|
||||
name = "rust",
|
||||
default_edition = "2024",
|
||||
rustc = "${RUSTC_PATH}",
|
||||
rustdoc = "${RUSTDOC_PATH}",
|
||||
clippy_driver = "${CLIPPY_DRIVER_PATH}",
|
||||
visibility = ["PUBLIC"],
|
||||
)
|
||||
|
||||
remote_test_execution_toolchain(
|
||||
name = "remote_test_execution",
|
||||
visibility = ["PUBLIC"],
|
||||
)
|
||||
|
||||
noop_test_toolchain(
|
||||
name = "test",
|
||||
visibility = ["PUBLIC"],
|
||||
)
|
||||
EOF
|
||||
|
||||
if [[ -n "${BUILDIFIER_BIN}" ]]; then
|
||||
# Keep local-only BUCK files readable for debugging.
|
||||
"${BUILDIFIER_BIN}" -lint=off -mode=fix codex-rs/toolchains/BUCK codex-rs/buck2/BUCK || true
|
||||
fi
|
||||
|
||||
echo "Using:"
|
||||
echo " reindeer: ${REINDEER_BIN}"
|
||||
echo " buck2: ${BUCK2_BIN}"
|
||||
echo " rustc: ${RUSTC_PATH} (toolchain: ${RUST_TOOLCHAIN})"
|
||||
|
||||
(
|
||||
cd codex-rs
|
||||
"${REINDEER_BIN}" vendor
|
||||
python3 scripts/gen_reindeer_fixups.py
|
||||
"${REINDEER_BIN}" buckify
|
||||
python3 scripts/patch_third_party_buck_for_tests.py
|
||||
python3 scripts/gen_buck_first_party.py
|
||||
)
|
||||
|
||||
echo ""
|
||||
echo "Third-party size:"
|
||||
if command -v du >/dev/null 2>&1; then
|
||||
du -sh codex-rs/third-party 2>/dev/null || true
|
||||
du -sh codex-rs/third-party/vendor 2>/dev/null || true
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Next:"
|
||||
echo " ${BUCK2_BIN} build //codex-rs/cli:codex"
|
||||
|
||||
if [[ "${DO_BUILD}" -eq 1 ]]; then
|
||||
echo ""
|
||||
echo "Building //codex-rs/cli:codex ..."
|
||||
# When running inside Codex CLI, these wrapper env vars can interfere with buck2.
|
||||
env -u BASH_EXEC_WRAPPER -u CODEX_ESCALATE_SOCKET "${BUCK2_BIN}" build //codex-rs/cli:codex
|
||||
fi
|
||||
Reference in New Issue
Block a user