Lightweight coding agent that runs in your terminal
Rust
Add Bazel release staging archives (#51850)
Dmitriy Kovalenko02d78ab053d7
diff --git a/.bazelrc b/.bazelrcindex d0a1e2b89c..d30b1fa1ca 100644--- a/.bazelrc+++ b/.bazelrc@@ -231,22 +231,41 @@ common:v8-target-arm64 --@v8//bazel/config:v8_target_cpu=arm64# the matching runtime objects.common:rusty-v8-upstream-libcxx --@v8//:v8_use_rusty_v8_custom_libcxx=True+# Native Windows archive builds inherit the runner's MSVC SDK environment.+# Client environment capture and repository discovery happen before target+# transitions, so these runner settings cannot live in runtime_package.bzl.+# The archive target selects its own MSVC host platform and native toolchains.+build:ci-windows-msvc --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=0+build:ci-windows-msvc --action_env=PATH+build:ci-windows-msvc --host_action_env=PATH+build:ci-windows-msvc --action_env=INCLUDE+build:ci-windows-msvc --host_action_env=INCLUDE+build:ci-windows-msvc --action_env=LIB+build:ci-windows-msvc --host_action_env=LIB+build:ci-windows-msvc --action_env=LIBPATH+build:ci-windows-msvc --host_action_env=LIBPATH+build:ci-windows-msvc --action_env=SystemRoot+build:ci-windows-msvc --host_action_env=SystemRoot+build:ci-windows-msvc --action_env=PROCESSOR_ARCHITECTURE+build:ci-windows-msvc --host_action_env=PROCESSOR_ARCHITECTURE+build:ci-windows-msvc --action_env=WindowsSdkDir+build:ci-windows-msvc --host_action_env=WindowsSdkDir+build:ci-windows-msvc --action_env=VCINSTALLDIR+build:ci-windows-msvc --host_action_env=VCINSTALLDIR+# Release profile settings are also defined in codex-rs/Cargo.toml.+# runtime_package.bzl applies this profile to archive dependencies automatically.# Packaging extracts symbols before stripping; the Rust toolchains retain-# line tables and use split-debuginfo=off. opt mode selects Rust opt-level=3;-# Cargo release disables assertions/checks even if a smoke build overrides-# opt-level to 0, so these are explicit rather than inferred from optimization.+# line tables and use split-debuginfo=off. opt mode selects Rust opt-level=3,+# which disables debug assertions and overflow checks by default.build:release --compilation_mode=optbuild:release --@rules_rust//rust/settings:lto=thinbuild:release --@rules_rust//rust/settings:codegen_units=4-build:release --@rules_rust//rust/settings:extra_rustc_flag=-Cdebug-assertions=no-build:release --@rules_rust//rust/settings:extra_rustc_flag=-Coverflow-checks=no# Match observed Cargo 1.95 build-tool commands: opt-level=0, assertions off,# and rustc's non-incremental default of 16 codegen units (not target's 4).build:release --@rules_rust//rust/settings:extra_exec_rustc_flag=-Copt-level=0build:release --@rules_rust//rust/settings:extra_exec_rustc_flag=-Ccodegen-units=16build:release --@rules_rust//rust/settings:extra_exec_rustc_flag=-Cdebug-assertions=no-build:release --@rules_rust//rust/settings:extra_exec_rustc_flag=-Coverflow-checks=no# Compatibility: Cargo build scripts consume the Rust profile, including debug# info, and choose their native optimization. Preserve explicit user C/C++ flags.diff --git a/.github/actions/build-bazel-release/action.yml b/.github/actions/build-bazel-release/action.ymlnew file mode 100644index 0000000000..d305b6742d--- /dev/null+++ b/.github/actions/build-bazel-release/action.yml@@ -0,0 +1,50 @@+name: Build Bazel release staging archive+description: Build a binary/symbol archive and extract writable inputs for existing signing and packaging.+inputs:+ target:+ description: Rust release target triple.+ required: true+ bundle:+ description: Binary bundle (combined, primary, app-server, or helpers).+ default: combined+ release-dir:+ description: Directory where the archive is extracted for signing and packaging.+ required: true+ build-mode:+ description: Release optimizations, or debug for faster package smoke builds.+ default: release++runs:+ using: composite+ steps:+ - name: Refresh release workspace metadata+ shell: bash+ working-directory: ${{ github.workspace }}/codex-rs+ # Release tags change Cargo.toml; rules_rs needs matching workspace lock entries.+ run: cargo update --workspace++ - name: Build staging archive+ shell: bash+ working-directory: ${{ github.workspace }}+ env:+ TARGET: ${{ inputs.target }}+ BUNDLE: ${{ inputs.bundle }}+ BUILD_MODE: ${{ inputs.build-mode }}+ # Keep Git Bash from rewriting Bazel labels as Windows paths.+ MSYS2_ARG_CONV_EXCL: "*"+ run: |+ python3 .github/scripts/run_bazel_with_buildbuddy.py build \+ ${{ runner.os == 'Windows' && '--config=ci-windows-msvc' || '' }} \+ "--platforms=@rules_rs//rs/platforms:$TARGET" \+ "--//codex-rs:runtime_package_build_mode=$BUILD_MODE" \+ "//codex-rs:runtime_package_$BUNDLE"++ - name: Extract staging archive+ shell: bash+ working-directory: ${{ github.workspace }}+ env:+ BUNDLE: ${{ inputs.bundle }}+ RELEASE_DIR: ${{ inputs.release-dir }}+ run: |+ mkdir -p "$RELEASE_DIR"+ tar -xzf "bazel-bin/codex-rs/runtime_package_$BUNDLE.tar.gz" -C "$RELEASE_DIR"diff --git a/MODULE.bazel b/MODULE.bazelindex ed8303b1d9..40fcac55db 100644--- a/MODULE.bazel+++ b/MODULE.bazel@@ -160,6 +160,7 @@ single_version_override()bazel_dep(name = "rules_platform", version = "0.1.0")+bazel_dep(name = "rules_pkg", version = "1.0.1")bazel_dep(name = "aws-lc", version = "5.1.0.bcr.1")bazel_dep(name = "rules_rs", version = "0.0.96")bazel_dep(name = "rules_foreign_cc", version = "0.15.1")diff --git a/bazel/rules/BUILD.bazel b/bazel/rules/BUILD.bazelindex ab6d1f9763..3dca7318be 100644--- a/bazel/rules/BUILD.bazel+++ b/bazel/rules/BUILD.bazel@@ -2,5 +2,6 @@ package(default_visibility = ["//visibility:public"])exports_files(["e2e_benchmark.bzl",+ "runtime_package.bzl","schema_bundle.bzl",])diff --git a/bazel/rules/runtime_package.bzl b/bazel/rules/runtime_package.bzlnew file mode 100644index 0000000000..ba4cdad58f--- /dev/null+++ b/bazel/rules/runtime_package.bzl@@ -0,0 +1,178 @@+"""Archive unstripped release binaries and debug symbols for signing and packaging."""++load("@platforms//host:constraints.bzl", "HOST_CONSTRAINTS")+load("@rules_pkg//pkg:providers.bzl", "PackageFilegroupInfo", "PackageFilesInfo")+load("@rules_pkg//pkg:tar.bzl", "pkg_tar")++# Keep the profile in sync with --config=release in .bazelrc and Cargo.toml.+# Archive targets apply it themselves, including when built without CI flags.+_RUSTC_FLAGS = "@rules_rust//rust/settings:extra_rustc_flag"+_EXEC_RUSTC_FLAGS = "@rules_rust//rust/settings:extra_exec_rustc_flag"+_PROFILE_INPUTS = [+ "//command_line_option:features",+ "//command_line_option:host_features",+ "//command_line_option:copt",+ "//command_line_option:action_env",+ "//command_line_option:host_action_env",+ "//command_line_option:macos_minimum_os",+ "//command_line_option:host_platform",+ "//command_line_option:extra_toolchains",+ _RUSTC_FLAGS,+ _EXEC_RUSTC_FLAGS,+]+_PROFILE_OUTPUTS = _PROFILE_INPUTS + [+ "//command_line_option:compilation_mode",+ "@rules_rust//rust/settings:lto",+ "@rules_rust//rust/settings:codegen_units",+]++def _release_profile_impl(settings, attr):+ profile = {key: settings[key] for key in _PROFILE_INPUTS}+ smoke = settings["//codex-rs:runtime_package_build_mode"] == "debug"+ profile.update({+ "//command_line_option:compilation_mode": "opt",+ "@rules_rust//rust/settings:lto": "off" if smoke else "thin",+ "@rules_rust//rust/settings:codegen_units": 256 if smoke else 4,+ # opt mode selects opt-level=3, which disables assertions and overflow+ # checks by default. Unoptimized release smokes need the explicit opt-out.+ _RUSTC_FLAGS: settings[_RUSTC_FLAGS] + ([+ "-Copt-level=0",+ "-Cdebug-assertions=no",+ ] if smoke else []),+ # Cargo release build tools use opt-level=0, assertions/checks off,+ # and rustc's default 16 CGUs. Overflow checks follow debug assertions.+ _EXEC_RUSTC_FLAGS: settings[_EXEC_RUSTC_FLAGS] + [+ "-Copt-level=0",+ "-Ccodegen-units=16",+ "-Cdebug-assertions=no",+ ],+ })+ for key in ["//command_line_option:features", "//command_line_option:host_features"]:+ profile[key] = settings[key] + ["cargo-release-profile"]+ if attr.platform_os == "macos":+ profile[_RUSTC_FLAGS] += ["-Csplit-debuginfo=packed"]+ profile["//command_line_option:macos_minimum_os"] = attr.macos_minimum_os+ profile["//command_line_option:action_env"] += ["MACOSX_DEPLOYMENT_TARGET=" + attr.macos_minimum_os]++ # Host tools must run on the build host, including x86_64 cross builds.+ host_minimum_os = "11.0" if "@platforms//cpu:aarch64" in HOST_CONSTRAINTS else "10.12"+ profile["//command_line_option:host_action_env"] += ["MACOSX_DEPLOYMENT_TARGET=" + host_minimum_os]+ elif attr.platform_os == "linux":+ # Compatibility with the Cargo musl release: aws-lc jitter can hang.+ profile["//command_line_option:copt"] += ["-DDISABLE_CPU_JITTER_ENTROPY"]+ elif attr.platform_os == "windows" and "@platforms//os:windows" in HOST_CONSTRAINTS:+ # Native MSVC supplies the SDK and host tools for both architectures.+ profile["//command_line_option:host_platform"] = "//:local_windows_msvc"+ profile["//command_line_option:extra_toolchains"] += [+ "@local_config_cc//:cc-toolchain-x64_windows",+ "@local_config_cc//:cc-toolchain-arm64_windows",+ ]+ return profile++_release_profile = transition(+ implementation = _release_profile_impl,+ inputs = _PROFILE_INPUTS + ["//codex-rs:runtime_package_build_mode"],+ outputs = _PROFILE_OUTPUTS,+)++def _runtime_binary_files_impl(ctx):+ binary = ctx.attr.binary[0]+ executable = binary[DefaultInfo].files_to_run.executable+ outputs = [executable]+ validations = []+ files = [PackageFilesInfo(+ attributes = {"mode": "0755"},+ dest_src_map = {executable.basename: executable},+ )]++ # Use the binary's target configuration, including cross builds. Linux keeps+ # DWARF inside the executable until the existing packaging strip pass.+ for group, suffix in [("pdb_file", ".pdb"), ("dsym_folder", ".dSYM")]:+ symbols = getattr(binary[OutputGroupInfo], group, depset()).to_list()+ if not symbols and group == ctx.attr.symbol_group:+ fail("Missing %s for %s" % (group, binary.label))+ if not symbols:+ continue+ if len(symbols) != 1:+ fail("Expected one %s for %s, got %s" % (group, binary.label, symbols))+ if group == "dsym_folder":+ validation = ctx.actions.declare_file(ctx.label.name + ".dsym-checked")+ ctx.actions.run_shell(+ inputs = symbols,+ outputs = [validation],+ arguments = [symbols[0].path, executable.basename, validation.path],+ command = '''+ test -s "$1/Contents/Resources/DWARF/$2" || {+ echo "Missing or empty DWARF for $2 in $1" >&2+ exit 1+ }+ touch "$3"+ ''',+ mnemonic = "ValidateRuntimeSymbols",+ )+ validations.append(validation)+ outputs.extend(symbols)+ files.append(PackageFilesInfo(+ attributes = {"mode": "0644"},+ dest_src_map = {binary.label.name + suffix: symbols[0]},+ ))++ return [+ DefaultInfo(files = depset(outputs)),+ OutputGroupInfo(_validation = depset(validations)),+ PackageFilegroupInfo(+ pkg_files = [(info, ctx.label) for info in files],+ pkg_dirs = [],+ pkg_symlinks = [],+ ),+ ]++_runtime_binary_files = rule(+ implementation = _runtime_binary_files_impl,+ attrs = {+ "binary": attr.label(mandatory = True, executable = True, cfg = _release_profile),+ "platform_os": attr.string(),+ "macos_minimum_os": attr.string(),+ "_allowlist_function_transition": attr.label(+ default = "@bazel_tools//tools/allowlists/function_transition_allowlist",+ ),+ "symbol_group": attr.string(),+ },+)++def runtime_archive(name, srcs, **kwargs):+ """Produce a flat archive of writable files, without stripping or signing."""+ pkg_tar(+ name = name,+ srcs = srcs,+ extension = "tar.gz",+ mode = "0755",+ stamp = 0,+ allow_duplicates_with_different_content = False,+ **kwargs+ )++def release_binary(binary, name = "release", **kwargs):+ """Expose release_files and release.tar.gz; override name for sibling binaries."""+ kwargs.setdefault("tags", ["manual"])+ kwargs.setdefault("visibility", ["//visibility:public"])+ _runtime_binary_files(+ name = name + "_files",+ binary = binary,+ platform_os = select({+ "@platforms//os:macos": "macos",+ "@platforms//os:linux": "linux",+ "@platforms//os:windows": "windows",+ }),+ macos_minimum_os = select({+ "@platforms//cpu:aarch64": "11.0",+ "//conditions:default": "10.12",+ }),+ symbol_group = select({+ "@platforms//os:macos": "dsym_folder",+ "@platforms//os:windows": "pdb_file",+ "//conditions:default": "",+ }),+ **kwargs+ )+ runtime_archive(name = name, srcs = [":" + name + "_files"], **kwargs)diff --git a/codex-rs/BUILD.bazel b/codex-rs/BUILD.bazelindex 1e03df292e..e169894153 100644--- a/codex-rs/BUILD.bazel+++ b/codex-rs/BUILD.bazel@@ -1,3 +1,6 @@+load("@bazel_skylib//rules:common_settings.bzl", "string_flag")+load("//bazel/rules:runtime_package.bzl", "runtime_archive")+exports_files(["clippy.toml",])@@ -24,3 +27,79 @@ test_suite(],visibility = ["//visibility:public"],)++string_flag(+ name = "runtime_package_build_mode",+ build_setting_default = "release",+ values = [+ "release",+ "debug",+ ],+ visibility = ["//visibility:public"],+)++alias(+ name = "runtime_package",+ actual = ":runtime_package_combined",+ tags = ["manual"],+ visibility = ["//visibility:public"],+)++# These targets produce flat staging archives for the existing signing and+# packaging steps. Release builds retain their binaries and debug symbols.+runtime_archive(+ name = "runtime_package_combined",+ srcs = [+ "//codex-rs/app-server:release_files",+ "//codex-rs/cli:release_files",+ "//codex-rs/code-mode-host:release_files",+ ] + select({+ "@platforms//os:linux": ["//codex-rs/bwrap:release_files"],+ "@platforms//os:windows": [+ "//codex-rs/windows-sandbox-rs:command-runner-release_files",+ "//codex-rs/windows-sandbox-rs:sandbox-setup-release_files",+ ],+ "//conditions:default": [],+ }),+ tags = ["manual"],+ visibility = ["//visibility:public"],+)++runtime_archive(+ name = "runtime_package_primary",+ srcs = [+ "//codex-rs/cli:release_files",+ "//codex-rs/code-mode-host:release_files",+ "//codex-rs/responses-api-proxy:release_files",+ ] + select({+ "@platforms//os:linux": ["//codex-rs/bwrap:release_files"],+ "//conditions:default": [],+ }),+ tags = ["manual"],+ visibility = ["//visibility:public"],+)++runtime_archive(+ name = "runtime_package_app-server",+ srcs = [+ "//codex-rs/app-server:release_files",+ "//codex-rs/code-mode-host:release_files",+ ] + select({+ "@platforms//os:linux": ["//codex-rs/bwrap:release_files"],+ "//conditions:default": [],+ }),+ tags = ["manual"],+ visibility = ["//visibility:public"],+)++runtime_archive(+ name = "runtime_package_helpers",+ srcs = [+ "//codex-rs/windows-sandbox-rs:command-runner-release_files",+ "//codex-rs/windows-sandbox-rs:sandbox-setup-release_files",+ "//codex-rs/windows-sandbox-service:release_files",+ ],+ tags = ["manual"],+ target_compatible_with = ["@platforms//os:windows"],+ visibility = ["//visibility:public"],+)diff --git a/codex-rs/app-server/BUILD.bazel b/codex-rs/app-server/BUILD.bazelindex ae19f195c3..051a7dd8e4 100644--- a/codex-rs/app-server/BUILD.bazel+++ b/codex-rs/app-server/BUILD.bazel@@ -1,4 +1,5 @@load("//:defs.bzl", "codex_rust_crate")+load("//bazel/rules:runtime_package.bzl", "release_binary")codex_rust_crate(name = "app-server",@@ -29,3 +30,7 @@ codex_rust_crate("//conditions:default": 0,}),)++release_binary(+ binary = ":codex-app-server",+)diff --git a/codex-rs/bwrap/BUILD.bazel b/codex-rs/bwrap/BUILD.bazelindex b1b932ac48..cc27df89a1 100644--- a/codex-rs/bwrap/BUILD.bazel+++ b/codex-rs/bwrap/BUILD.bazel@@ -1,5 +1,6 @@load("@rules_cc//cc:defs.bzl", "cc_library")load("//:defs.bzl", "codex_rust_crate")+load("//bazel/rules:runtime_package.bzl", "release_binary")codex_rust_crate(name = "bwrap",@@ -21,6 +22,11 @@ codex_rust_crate(}),)+release_binary(+ binary = ":bwrap",+ target_compatible_with = ["@platforms//os:linux"],+)+genrule(name = "bwrap-sha256-env",srcs = [":bwrap"],diff --git a/codex-rs/cli/BUILD.bazel b/codex-rs/cli/BUILD.bazelindex 41fbbb78ba..d9673f989f 100644--- a/codex-rs/cli/BUILD.bazel+++ b/codex-rs/cli/BUILD.bazel@@ -1,6 +1,7 @@load("//:defs.bzl", "MACOS_WEBRTC_RUSTC_LINK_FLAGS", "codex_rust_crate")load("//bazel/platforms:release_binaries.bzl", "multiplatform_binaries")load("//bazel/rules:e2e_benchmark.bzl", "codex_e2e_benchmark")+load("//bazel/rules:runtime_package.bzl", "release_binary")codex_rust_crate(name = "cli",@@ -13,6 +14,10 @@ codex_rust_crate(test_data_extra = glob(["src/**/snapshots/**"]),)+release_binary(+ binary = ":codex",+)+multiplatform_binaries(name = "codex",)diff --git a/codex-rs/code-mode-host/BUILD.bazel b/codex-rs/code-mode-host/BUILD.bazelindex c1245e21a8..73cd63d40e 100644--- a/codex-rs/code-mode-host/BUILD.bazel+++ b/codex-rs/code-mode-host/BUILD.bazel@@ -1,6 +1,11 @@load("//:defs.bzl", "codex_rust_crate")+load("//bazel/rules:runtime_package.bzl", "release_binary")codex_rust_crate(name = "code-mode-host",crate_name = "codex_code_mode_host",)++release_binary(+ binary = ":codex-code-mode-host",+)diff --git a/codex-rs/responses-api-proxy/BUILD.bazel b/codex-rs/responses-api-proxy/BUILD.bazelindex b3fa2edc5d..b08e0e6452 100644--- a/codex-rs/responses-api-proxy/BUILD.bazel+++ b/codex-rs/responses-api-proxy/BUILD.bazel@@ -1,6 +1,11 @@load("//:defs.bzl", "codex_rust_crate")+load("//bazel/rules:runtime_package.bzl", "release_binary")codex_rust_crate(name = "responses-api-proxy",crate_name = "codex_responses_api_proxy",)++release_binary(+ binary = ":codex-responses-api-proxy",+)diff --git a/codex-rs/windows-sandbox-rs/BUILD.bazel b/codex-rs/windows-sandbox-rs/BUILD.bazelindex 8531cb4d66..9a3a03e203 100644--- a/codex-rs/windows-sandbox-rs/BUILD.bazel+++ b/codex-rs/windows-sandbox-rs/BUILD.bazel@@ -1,4 +1,5 @@load("//:defs.bzl", "codex_rust_crate")+load("//bazel/rules:runtime_package.bzl", "release_binary")# Cargo's build.rs emits rustc-link-arg-bin so only the setup helper gets the# asInvoker manifest. rules_rust warns on and drops that directive, so Bazel@@ -56,3 +57,15 @@ codex_rust_crate(":codex-windows-sandbox-setup",],)++release_binary(+ name = "command-runner-release",+ binary = ":codex-command-runner",+ target_compatible_with = ["@platforms//os:windows"],+)++release_binary(+ name = "sandbox-setup-release",+ binary = ":codex-windows-sandbox-setup",+ target_compatible_with = ["@platforms//os:windows"],+)diff --git a/codex-rs/windows-sandbox-service/BUILD.bazel b/codex-rs/windows-sandbox-service/BUILD.bazelindex 306c21fa06..63bcdf554b 100644--- a/codex-rs/windows-sandbox-service/BUILD.bazel+++ b/codex-rs/windows-sandbox-service/BUILD.bazel@@ -1,4 +1,5 @@load("//:defs.bzl", "codex_rust_crate")+load("//bazel/rules:runtime_package.bzl", "release_binary")codex_rust_crate(name = "windows-sandbox-service",@@ -6,3 +7,8 @@ codex_rust_crate(compile_data = ["src/registered_runtime/removal.ps1"],crate_name = "codex_windows_sandbox_service",)++release_binary(+ binary = ":codex-windows-sandbox-service",+ target_compatible_with = ["@platforms//os:windows"],+)