Files
codex/codex-rs/bwrap/BUILD.bazel
T
Dmitriy Kovalenko 745d865521 Align Bazel release builds with Cargo and fix platform compatibility (#51848)
## Why

Bazel release builds need Cargo-compatible Rust and native build-script settings. Platform-specific issues also include Windows command-line limits, MSVC runtime conflicts with V8's allocator, and a missing V8 `__clear_cache` symbol on ARM64 musl.

## What changed

- Add `--config=release` settings for thin LTO, four target codegen units, and disabled debug assertions and overflow checks, with separate settings for build tools.
- Add opt-in Cargo release profile support for build-script optimization and debug information, preserving explicit C/C++ flags. Give optimized Bubblewrap builds `-O3`, debug symbols, and enabled native assertions.
- Statically link the MSVC CRT for Rust and C/C++ target and host dependencies, and disable SQLite intrinsics on x64 MSVC to avoid startup crashes on older CPUs.
- Let the Rust process wrapper read its arguments from a multiline parameter file to avoid Windows command-line limits.
- Select the ARM64 musl V8 archive containing compiler-rt builtins and raise the Rust recursion limit to `256` in the app-server client, exec, and TUI entry points for release compilation.

GitOrigin-RevId: 8f61e62b8735c36209ee92e04a0e0339a70badc5
2026-10-07 22:10:23 +00:00

68 lines
1.9 KiB
Python

load("@rules_cc//cc:defs.bzl", "cc_library")
load("//:defs.bzl", "codex_rust_crate")
codex_rust_crate(
name = "bwrap",
# Bazel wires vendored bubblewrap + libcap via :bwrap-ffi below and sets
# bwrap_available explicitly, so we skip Cargo's build.rs in Bazel builds.
build_script_enabled = False,
crate_name = "codex_bwrap",
deps_extra = select({
"@platforms//os:linux": [":bwrap-ffi"],
"//conditions:default": [],
}),
rustc_flags_extra = select({
"@platforms//os:linux": [
"--cfg=bwrap_available",
# TODO(anp) Extract bwrap symbols before stripping.
"-Cstrip=symbols",
],
"//conditions:default": [],
}),
)
genrule(
name = "bwrap-sha256-env",
srcs = [":bwrap"],
outs = ["bwrap.sha256.env"],
cmd = " && ".join([
'$(execpath @bazel_tools//tools/build_defs/hash:sha256) $(execpath :bwrap) "$@"',
'digest=$$(<"$@")',
'printf "CODEX_BWRAP_SHA256=%s\\n" "$$digest" > "$@"',
]),
target_compatible_with = ["@platforms//os:linux"],
tools = ["@bazel_tools//tools/build_defs/hash:sha256"],
visibility = ["//codex-rs/linux-sandbox:__pkg__"],
)
config_setting(
name = "optimized",
values = {"compilation_mode": "opt"},
)
cc_library(
name = "bwrap-ffi",
srcs = ["//codex-rs/vendor:bubblewrap_c_sources"],
hdrs = [
"config.h",
"//codex-rs/vendor:bubblewrap_headers",
],
copts = [
"-D_GNU_SOURCE",
"-Dmain=bwrap_main",
] + select({
# Cargo cc-rs uses release OPT_LEVEL=3 and DEBUG=true, without
# the C toolchain's default NDEBUG; retain native symbols for packaging.
":optimized": [
"-O3",
"-g",
"-UNDEBUG",
],
"//conditions:default": [],
}),
includes = ["."],
target_compatible_with = ["@platforms//os:linux"],
visibility = ["//visibility:private"],
deps = ["@libcap"],
)