mirror of
https://github.com/openai/codex.git
synced 2026-11-10 21:00:47 +00:00
## Why Windows MSVC builds relied on installed C++ toolchains, and V8 snapshot generation required native Windows execution. Cross-compiling V8 also needs a Windows snapshot generator to preserve Windows unwind metadata. ## What changed - Use the registered hermetic LLVM toolchain and declared Microsoft SDK for Windows MSVC builds, with static CRT linkage and the toolchain's declared `lld-link` for Rust. - Run Windows V8 snapshot generators natively or through `rules_wine` on Linux, preserving target CPU, OS, and sandbox settings. Keep separate archive and binding pairs for the workspace's ISO stdio ABI and the distributed MSVC stdio ABI. - Update build dependencies and bindgen, scope V8's Chromium libc++ settings to its own targets, and adapt native voice dependencies for clang-cl and Windows ARM64. - Build SQLite directly with Bazel and give `openssl-sys` an explicit build using Bazel's OpenSSL. - Remove build-worker source-directory dependencies from Bazel resource lookup, schema output discovery, and snapshot paths; embed assets in debug builds as well. GitOrigin-RevId: fd224d9d28d73a67baf90f6d73c6079d60f20351
134 lines
5.9 KiB
Diff
134 lines
5.9 KiB
Diff
--- a/cargo/private/cargo_build_script.bzl
|
|
+++ b/cargo/private/cargo_build_script.bzl
|
|
@@ -3,6 +3,7 @@
|
|
load("@apple_support//lib:apple_support.bzl", "apple_support")
|
|
load("@bazel_skylib//lib:paths.bzl", "paths")
|
|
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
|
|
+load("@platforms//host:constraints.bzl", "HOST_CONSTRAINTS")
|
|
load("@rules_cc//cc:action_names.bzl", "ACTION_NAMES")
|
|
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
|
|
load("//cargo/private:cargo_toolchain.bzl", "cargo_version_mismatch", "find_cargo")
|
|
@@ -12,6 +13,7 @@
|
|
load(
|
|
"//rust/private:rustc.bzl",
|
|
"collect_cfg_query_rustc_flags",
|
|
+ "collect_extra_rustc_flags",
|
|
"get_compilation_mode_opts",
|
|
"get_linker_and_args",
|
|
)
|
|
@@ -23,6 +25,7 @@
|
|
"expand_dict_value_locations",
|
|
"find_cc_toolchain",
|
|
"find_toolchain",
|
|
+ "is_exec_configuration",
|
|
_name_to_crate_name = "name_to_crate_name",
|
|
)
|
|
|
|
@@ -66,6 +69,43 @@
|
|
},
|
|
executable = True,
|
|
)
|
|
+
|
|
+def _release_user_opts(ctx, flags):
|
|
+ # Bazel 9.2's default exec transition appends -g0 to host copts/cxxopts on
|
|
+ # non-Windows servers. Remove only that suffix; preserve explicit -g0.
|
|
+ # https://github.com/bazelbuild/bazel/blob/9.2.0/src/main/starlark/builtins_bzl/common/builtin_exec_platforms.bzl
|
|
+ if is_exec_configuration(ctx) and "@platforms//os:windows" not in HOST_CONSTRAINTS and flags and flags[-1] == "-g0":
|
|
+ return flags[:-1]
|
|
+ return flags
|
|
+
|
|
+def _cargo_profile_native_flags(flags):
|
|
+ # Let cc-rs/cmake derive optimization and debug info from Cargo's profile.
|
|
+ # Filter toolchain defaults only; explicit user flags are appended afterwards.
|
|
+ profile_defaults = [
|
|
+ "-O0",
|
|
+ "-O1",
|
|
+ "-O2",
|
|
+ "-O3",
|
|
+ "-Og",
|
|
+ "-Os",
|
|
+ "-Oz",
|
|
+ "-Ofast",
|
|
+ "-g0",
|
|
+ "-DNDEBUG",
|
|
+ "-DNDEBUG=1",
|
|
+ "/Od",
|
|
+ "/O1",
|
|
+ "/O2",
|
|
+ "/Ox",
|
|
+ "/Ob0",
|
|
+ "/Ob1",
|
|
+ "/Ob2",
|
|
+ "/Ob3",
|
|
+ "/Oi",
|
|
+ "/DNDEBUG",
|
|
+ "/DNDEBUG=1",
|
|
+ ]
|
|
+ return [flag for flag in flags if flag not in profile_defaults]
|
|
|
|
def get_cc_compile_args_and_env(ctx, cc_toolchain, feature_configuration):
|
|
"""Gather cc environment variables from the given `cc_toolchain`
|
|
@@ -94,12 +94,12 @@
|
|
c_compile_variables = cc_common.create_compile_variables(
|
|
feature_configuration = feature_configuration,
|
|
cc_toolchain = cc_toolchain,
|
|
- user_compile_flags = ctx.fragments.cpp.copts + ctx.fragments.cpp.conlyopts,
|
|
+ user_compile_flags = [] if _feature_enabled(ctx, "cargo-release-profile") else ctx.fragments.cpp.copts + ctx.fragments.cpp.conlyopts,
|
|
)
|
|
cxx_compile_variables = cc_common.create_compile_variables(
|
|
feature_configuration = feature_configuration,
|
|
cc_toolchain = cc_toolchain,
|
|
- user_compile_flags = ctx.fragments.cpp.copts + ctx.fragments.cpp.cxxopts,
|
|
+ user_compile_flags = [] if _feature_enabled(ctx, "cargo-release-profile") else ctx.fragments.cpp.copts + ctx.fragments.cpp.cxxopts,
|
|
)
|
|
cc_c_args = cc_common.get_memory_inefficient_command_line(
|
|
feature_configuration = feature_configuration,
|
|
@@ -469,6 +509,22 @@
|
|
env["CARGO_PKG_VERSION_PRE"] = patch[1] if len(patch) > 1 else ""
|
|
env["CARGO_PKG_VERSION"] = ctx.attr.version
|
|
|
|
+ cargo_release_profile = _feature_enabled(ctx, "cargo-release-profile")
|
|
+ if cargo_release_profile:
|
|
+ # Compatibility with Cargo release profiles that retain debug info:
|
|
+ # DEBUG describes symbol generation, not debug assertions. Read the
|
|
+ # consuming crate's configuration, not the build-script executable's.
|
|
+ debug_info = get_compilation_mode_opts(ctx, toolchain).debug_info
|
|
+ flags = collect_extra_rustc_flags(ctx, toolchain, None, "rlib")
|
|
+ for flag in flags:
|
|
+ # Accept both -Copt-level=N and the split -C opt-level=N spelling.
|
|
+ codegen = flag.removeprefix("-C").removeprefix("--codegen=")
|
|
+ if codegen.startswith("opt-level="):
|
|
+ env["OPT_LEVEL"] = codegen.removeprefix("opt-level=")
|
|
+ elif codegen.startswith("debuginfo="):
|
|
+ debug_info = codegen.removeprefix("debuginfo=")
|
|
+ env["DEBUG"] = "false" if debug_info in ["0", "none"] else "true"
|
|
+
|
|
use_cc_toolchain = _resolve_tristate(
|
|
ctx.attr.use_cc_toolchain,
|
|
ctx.attr._default_use_cc_toolchain,
|
|
@@ -484,6 +540,13 @@
|
|
if cc_toolchain:
|
|
# MSVC requires INCLUDE to be set
|
|
cc_c_args, cc_cxx_args, cc_env = get_cc_compile_args_and_env(ctx, cc_toolchain, feature_configuration)
|
|
+ if cargo_release_profile:
|
|
+ # Preserve SDK, ABI, CRT and security options. User copts and crate
|
|
+ # build_script_env overrides retain precedence over these defaults.
|
|
+ copts = _release_user_opts(ctx, ctx.fragments.cpp.copts)
|
|
+ cxxopts = _release_user_opts(ctx, ctx.fragments.cpp.cxxopts)
|
|
+ cc_c_args = _cargo_profile_native_flags(cc_c_args) + copts + ctx.fragments.cpp.conlyopts
|
|
+ cc_cxx_args = _cargo_profile_native_flags(cc_cxx_args) + copts + cxxopts
|
|
include = cc_env.get("INCLUDE")
|
|
if include:
|
|
if toolchain.exec_triple.str.find("windows") > 0:
|
|
@@ -837,6 +900,10 @@
|
|
"_cargo_manifest_dir_filename_suffixes_to_retain": attr.label(
|
|
default = Label("//cargo/settings:cargo_manifest_dir_filename_suffixes_to_retain"),
|
|
),
|
|
+ "_extra_exec_rustc_flag": attr.label(default = Label("//rust/settings:extra_exec_rustc_flag")),
|
|
+ "_extra_exec_rustc_flags": attr.label(default = Label("//rust/settings:extra_exec_rustc_flags")),
|
|
+ "_extra_rustc_flag": attr.label(default = Label("//rust/settings:extra_rustc_flag")),
|
|
+ "_extra_rustc_flags": attr.label(default = Label("//rust/settings:extra_rustc_flags")),
|
|
"_debug_std_streams_output_group": attr.label(
|
|
default = Label("//cargo/settings:debug_std_streams_output_group"),
|
|
),
|