mirror of
https://github.com/openai/codex.git
synced 2026-09-05 15:18:41 +00:00
build: use gnullvm for Windows Rust exec tools
This commit is contained in:
committed by
Adam Perry @ OpenAI
parent
5c0fbf3492
commit
b9a3496581
@@ -3,36 +3,6 @@
|
||||
set -euo pipefail
|
||||
|
||||
bazel_lint_args=("$@")
|
||||
if [[ "${RUNNER_OS:-}" == "Windows" ]]; then
|
||||
has_host_platform_override=0
|
||||
for arg in "${bazel_lint_args[@]}"; do
|
||||
if [[ "$arg" == --host_platform=* ]]; then
|
||||
has_host_platform_override=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ $has_host_platform_override -eq 0 ]]; then
|
||||
# The nightly Windows lint toolchain is registered with an MSVC exec
|
||||
# platform even though the lint target platform stays on `windows-gnullvm`.
|
||||
# Override the host platform here so the exec-side helper binaries actually
|
||||
# match the registered toolchain set.
|
||||
bazel_lint_args+=("--host_platform=//:local_windows_msvc")
|
||||
fi
|
||||
|
||||
# Native Windows lint runs need exec-side Rust helper binaries and proc-macros
|
||||
# to use rust-lld instead of the C++ linker path. The default `none`
|
||||
# preference resolves to `cc` when a cc_toolchain is present, which currently
|
||||
# routes these exec actions through clang++ with an argument shape it cannot
|
||||
# consume.
|
||||
bazel_lint_args+=("--@rules_rust//rust/settings:toolchain_linker_preference=rust")
|
||||
|
||||
# Some Rust top-level targets are still intentionally incompatible with the
|
||||
# local Windows MSVC exec platform. Skip those explicit targets so the native
|
||||
# lint aspect can run across the compatible crate graph instead of failing the
|
||||
# whole build after analysis.
|
||||
bazel_lint_args+=("--skip_incompatible_explicit_targets")
|
||||
fi
|
||||
|
||||
read_query_labels() {
|
||||
local query="$1"
|
||||
|
||||
22
MODULE.bazel
22
MODULE.bazel
@@ -136,34 +136,26 @@ nightly_rust.toolchain(
|
||||
versions = ["nightly/2025-09-18"],
|
||||
)
|
||||
|
||||
# Keep Windows exec tools on MSVC so Bazel helper binaries link correctly, but
|
||||
# lint crate targets as `windows-gnullvm` to preserve the repo's actual cfgs.
|
||||
# Build Windows exec tools and lint targets with the same `windows-gnullvm`
|
||||
# ABI so proc macros, build scripts, and the lint driver share one hermetic
|
||||
# LLVM/MinGW toolchain.
|
||||
nightly_rust.repository_set(
|
||||
name = "rust_windows_x86_64",
|
||||
name = "rust_windows_x86_64_gnullvm",
|
||||
dev_components = True,
|
||||
edition = "2024",
|
||||
exec_compatible_with = [
|
||||
"@platforms//cpu:x86_64",
|
||||
"@platforms//os:windows",
|
||||
"@rules_rs//rs/experimental/platforms/constraints:windows_msvc",
|
||||
"@rules_rs//rs/experimental/platforms/constraints:windows_gnullvm",
|
||||
],
|
||||
exec_triple = "x86_64-pc-windows-msvc",
|
||||
target_compatible_with = [
|
||||
"@platforms//cpu:x86_64",
|
||||
"@platforms//os:windows",
|
||||
"@rules_rs//rs/experimental/platforms/constraints:windows_msvc",
|
||||
],
|
||||
target_triple = "x86_64-pc-windows-msvc",
|
||||
versions = ["nightly/2025-09-18"],
|
||||
)
|
||||
nightly_rust.repository_set(
|
||||
name = "rust_windows_x86_64",
|
||||
exec_triple = "x86_64-pc-windows-gnullvm",
|
||||
target_compatible_with = [
|
||||
"@platforms//cpu:x86_64",
|
||||
"@platforms//os:windows",
|
||||
"@rules_rs//rs/experimental/platforms/constraints:windows_gnullvm",
|
||||
],
|
||||
target_triple = "x86_64-pc-windows-gnullvm",
|
||||
versions = ["nightly/2025-09-18"],
|
||||
)
|
||||
use_repo(nightly_rust, "rust_toolchains")
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# What: use a working Windows direct linker for `rules_rs` exec toolchains and
|
||||
# What: use Rust's bundled direct linker for Windows MSVC exec toolchains and
|
||||
# preserve the Windows stdlib link flags the stable wrapper was dropping.
|
||||
# Scope: Windows-only linker metadata for the generated `rules_rs` toolchains.
|
||||
# Scope: Windows-only linker metadata for the generated `rules_rs` toolchains;
|
||||
# Windows gnullvm keeps using the selected hermetic C++ toolchain driver.
|
||||
|
||||
diff --git a/rs/experimental/toolchains/declare_rustc_toolchains.bzl b/rs/experimental/toolchains/declare_rustc_toolchains.bzl
|
||||
--- a/rs/experimental/toolchains/declare_rustc_toolchains.bzl
|
||||
@@ -9,8 +10,8 @@ diff --git a/rs/experimental/toolchains/declare_rustc_toolchains.bzl b/rs/experi
|
||||
rust_toolchain(
|
||||
name = rust_toolchain_name,
|
||||
rust_doc = "{}rustdoc".format(rustc_repo_label),
|
||||
+ linker = "{}rust-lld".format(rustc_repo_label) if exec_triple.system == "windows" else None,
|
||||
+ linker_type = "direct" if exec_triple.system == "windows" else None,
|
||||
+ linker = "{}rust-lld".format(rustc_repo_label) if exec_triple.abi == "msvc" else None,
|
||||
+ linker_type = "direct" if exec_triple.abi == "msvc" else None,
|
||||
rust_std = select(rust_std_select),
|
||||
rustc = "{}rustc".format(rustc_repo_label),
|
||||
cargo = "{}cargo".format(cargo_repo_label),
|
||||
@@ -39,7 +40,7 @@ diff --git a/rs/experimental/toolchains/declare_rustc_toolchains.bzl b/rs/experi
|
||||
diff --git a/rs/private/rustc_repository.bzl b/rs/private/rustc_repository.bzl
|
||||
--- a/rs/private/rustc_repository.bzl
|
||||
+++ b/rs/private/rustc_repository.bzl
|
||||
@@ -7,10 +7,24 @@ load(
|
||||
@@ -7,10 +7,26 @@ load(
|
||||
)
|
||||
load(":rust_repository_utils.bzl", "RUST_REPOSITORY_COMMON_ATTR", "download_and_extract")
|
||||
+
|
||||
@@ -55,11 +56,13 @@ diff --git a/rs/private/rustc_repository.bzl b/rs/private/rustc_repository.bzl
|
||||
exec_triple = triple(rctx.attr.triple)
|
||||
download_and_extract(rctx, "rustc", "rustc", exec_triple)
|
||||
build_content = [BUILD_for_compiler(exec_triple)]
|
||||
+ if exec_triple.system == "windows":
|
||||
+ lld_link = rctx.which("lld-link.exe")
|
||||
+ if lld_link == None:
|
||||
+ fail("lld-link.exe not found on PATH")
|
||||
+ rctx.symlink(lld_link, "bin/lld-link.exe")
|
||||
+ if exec_triple.abi == "msvc":
|
||||
+ # Keep the `lld-link.exe` basename so the multi-call Rust LLD binary
|
||||
+ # selects its COFF driver without importing a linker from PATH.
|
||||
+ rctx.symlink(
|
||||
+ "lib/rustlib/{}/bin/rust-lld.exe".format(exec_triple.str),
|
||||
+ "bin/lld-link.exe",
|
||||
+ )
|
||||
+ build_content.append(_WINDOWS_EXEC_LINKER_BUILD)
|
||||
if includes_rust_analyzer_proc_macro_srv(rctx.attr.version, rctx.attr.iso_date):
|
||||
build_content.append(BUILD_for_rust_analyzer_proc_macro_srv(exec_triple))
|
||||
|
||||
Reference in New Issue
Block a user