mirror of
https://github.com/openai/codex.git
synced 2026-04-24 14:45:27 +00:00
bazel: use native rust test sharding
Configure the large Rust test targets with Bazel's native shard_count while keeping rules_rust's stable test-name hash bucket assignment. This depends on hermeticbuild/rules_rs#94, which pins the rules_rust stable sharding stack, and keeps the original test labels so BuildBuddy can render Bazel's native sharded test UI. Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
31
MODULE.bazel
31
MODULE.bazel
@@ -1,8 +1,9 @@
|
||||
module(name = "codex")
|
||||
|
||||
bazel_dep(name = "bazel_skylib", version = "1.8.2")
|
||||
bazel_dep(name = "bazel_skylib", version = "1.9.0")
|
||||
bazel_dep(name = "platforms", version = "1.0.0")
|
||||
bazel_dep(name = "llvm", version = "0.6.8")
|
||||
bazel_dep(name = "llvm", version = "0.7.0")
|
||||
|
||||
# The upstream LLVM archive contains a few unix-only symlink entries and is
|
||||
# missing a couple of MinGW compatibility archives that windows-gnullvm needs
|
||||
# during extraction and linking, so patch it until upstream grows native support.
|
||||
@@ -13,6 +14,7 @@ single_version_override(
|
||||
"//patches:llvm_windows_symlink_extract.patch",
|
||||
],
|
||||
)
|
||||
|
||||
# Abseil picks a MinGW pthread TLS path that does not match our hermetic
|
||||
# windows-gnullvm toolchain; force it onto the portable C++11 thread-local path.
|
||||
single_version_override(
|
||||
@@ -79,21 +81,25 @@ bazel_dep(name = "apple_support", version = "2.1.0")
|
||||
bazel_dep(name = "rules_cc", version = "0.2.16")
|
||||
bazel_dep(name = "rules_platform", version = "0.1.0")
|
||||
bazel_dep(name = "rules_rs", version = "0.0.43")
|
||||
|
||||
# `rules_rs` 0.0.43 does not model `windows-gnullvm` as a distinct Windows exec
|
||||
# platform, so patch it until upstream grows that support for both x86_64 and
|
||||
# aarch64.
|
||||
single_version_override(
|
||||
# platform, and it pins a `rules_rust` commit before stable hash-based test
|
||||
# sharding. Override it with hermeticbuild/rules_rs#94 while that is pending,
|
||||
# then keep the local Windows patches on top.
|
||||
archive_override(
|
||||
module_name = "rules_rs",
|
||||
integrity = "sha256-hzxHW/XFJEAkbtQ1CswMHq2PYXp9DLbEdE5eTHiWlj0=",
|
||||
patch_strip = 1,
|
||||
patches = [
|
||||
"//patches:rules_rs_windows_gnullvm_exec.patch",
|
||||
"//patches:rules_rs_delete_git_worktree_pointer.patch",
|
||||
"//patches:rules_rs_windows_exec_linker.patch",
|
||||
],
|
||||
version = "0.0.43",
|
||||
strip_prefix = "rules_rs-cc1e8d106622845d726a4fb3b21f7cdd61a0fa4b",
|
||||
urls = ["https://github.com/bolinfest/rules_rs/archive/cc1e8d106622845d726a4fb3b21f7cdd61a0fa4b.tar.gz"],
|
||||
)
|
||||
|
||||
rules_rust = use_extension("@rules_rs//rs/experimental:rules_rust.bzl", "rules_rust")
|
||||
|
||||
# Build-script probe binaries inherit CFLAGS/CXXFLAGS from Bazel's C++
|
||||
# toolchain. On `windows-gnullvm`, llvm-mingw does not ship
|
||||
# `libssp_nonshared`, so strip the forwarded stack-protector flags there.
|
||||
@@ -108,7 +114,6 @@ rules_rust.patch(
|
||||
"//patches:rules_rust_windows_exec_bin_target.patch",
|
||||
"//patches:rules_rust_windows_exec_std.patch",
|
||||
"//patches:rules_rust_windows_exec_rustc_dev_rlib.patch",
|
||||
"//patches:rules_rust_repository_set_exec_constraints.patch",
|
||||
],
|
||||
strip = 1,
|
||||
)
|
||||
@@ -119,22 +124,23 @@ nightly_rust = use_extension(
|
||||
"rust",
|
||||
)
|
||||
nightly_rust.toolchain(
|
||||
versions = ["nightly/2025-09-18"],
|
||||
dev_components = True,
|
||||
edition = "2024",
|
||||
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.
|
||||
nightly_rust.repository_set(
|
||||
name = "rust_windows_x86_64",
|
||||
dev_components = True,
|
||||
edition = "2024",
|
||||
exec_triple = "x86_64-pc-windows-msvc",
|
||||
exec_compatible_with = [
|
||||
"@platforms//cpu:x86_64",
|
||||
"@platforms//os:windows",
|
||||
"@rules_rs//rs/experimental/platforms/constraints:windows_msvc",
|
||||
],
|
||||
exec_triple = "x86_64-pc-windows-msvc",
|
||||
target_compatible_with = [
|
||||
"@platforms//cpu:x86_64",
|
||||
"@platforms//os:windows",
|
||||
@@ -162,6 +168,7 @@ toolchains.toolchain(
|
||||
use_repo(toolchains, "default_rust_toolchains")
|
||||
|
||||
register_toolchains("@default_rust_toolchains//:all")
|
||||
|
||||
register_toolchains("@rust_toolchains//:all")
|
||||
|
||||
crate = use_extension("@rules_rs//rs:extensions.bzl", "crate")
|
||||
@@ -233,7 +240,6 @@ crate.annotation(
|
||||
"//patches:aws-lc-sys_windows_msvc_memcmp_probe.patch",
|
||||
],
|
||||
)
|
||||
|
||||
crate.annotation(
|
||||
# The build script only validates embedded source/version metadata.
|
||||
crate = "rustc_apfloat",
|
||||
@@ -241,6 +247,7 @@ crate.annotation(
|
||||
)
|
||||
|
||||
inject_repo(crate, "zstd")
|
||||
|
||||
use_repo(crate, "argument_comment_lint_crates")
|
||||
|
||||
bazel_dep(name = "bzip2", version = "1.0.8.bcr.3")
|
||||
@@ -310,7 +317,9 @@ crate.annotation(
|
||||
)
|
||||
|
||||
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
|
||||
http_file = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
|
||||
|
||||
new_local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "new_local_repository")
|
||||
|
||||
new_local_repository(
|
||||
|
||||
94
MODULE.bazel.lock
generated
94
MODULE.bazel.lock
generated
File diff suppressed because one or more lines are too long
@@ -4,5 +4,9 @@ codex_rust_crate(
|
||||
name = "app-server",
|
||||
crate_name = "codex_app_server",
|
||||
integration_test_timeout = "long",
|
||||
test_shard_counts = {
|
||||
"app-server-all-test": 8,
|
||||
"app-server-unit-tests": 8,
|
||||
},
|
||||
test_tags = ["no-sandbox"],
|
||||
)
|
||||
|
||||
@@ -10,28 +10,35 @@ filegroup(
|
||||
|
||||
codex_rust_crate(
|
||||
name = "core",
|
||||
crate_name = "codex_core",
|
||||
compile_data = glob(
|
||||
include = ["**"],
|
||||
allow_empty = True,
|
||||
exclude = [
|
||||
"**/* *",
|
||||
"BUILD.bazel",
|
||||
"Cargo.toml",
|
||||
],
|
||||
allow_empty = True,
|
||||
) + [
|
||||
"//codex-rs:node-version.txt",
|
||||
],
|
||||
rustc_env = {
|
||||
# Keep manifest-root path lookups inside the Bazel execroot for code
|
||||
# that relies on env!("CARGO_MANIFEST_DIR").
|
||||
"CARGO_MANIFEST_DIR": "codex-rs/core",
|
||||
},
|
||||
crate_name = "codex_core",
|
||||
extra_binaries = [
|
||||
"//codex-rs/linux-sandbox:codex-linux-sandbox",
|
||||
"//codex-rs/rmcp-client:test_stdio_server",
|
||||
"//codex-rs/rmcp-client:test_streamable_http_server",
|
||||
"//codex-rs/responses-api-proxy:codex-responses-api-proxy",
|
||||
"//codex-rs/cli:codex",
|
||||
],
|
||||
integration_compile_data_extra = [
|
||||
"//codex-rs/apply-patch:apply_patch_tool_instructions.md",
|
||||
"templates/realtime/backend_prompt.md",
|
||||
],
|
||||
integration_test_timeout = "long",
|
||||
rustc_env = {
|
||||
# Keep manifest-root path lookups inside the Bazel execroot for code
|
||||
# that relies on env!("CARGO_MANIFEST_DIR").
|
||||
"CARGO_MANIFEST_DIR": "codex-rs/core",
|
||||
},
|
||||
test_data_extra = [
|
||||
"config.schema.json",
|
||||
] + glob([
|
||||
@@ -47,13 +54,10 @@ codex_rust_crate(
|
||||
# succeeds without this workaround.
|
||||
"//:AGENTS.md",
|
||||
],
|
||||
test_shard_counts = {
|
||||
"core-all-test": 8,
|
||||
"core-unit-tests": 8,
|
||||
},
|
||||
test_tags = ["no-sandbox"],
|
||||
unit_test_timeout = "long",
|
||||
extra_binaries = [
|
||||
"//codex-rs/linux-sandbox:codex-linux-sandbox",
|
||||
"//codex-rs/rmcp-client:test_stdio_server",
|
||||
"//codex-rs/rmcp-client:test_streamable_http_server",
|
||||
"//codex-rs/responses-api-proxy:codex-responses-api-proxy",
|
||||
"//codex-rs/cli:codex",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -2,26 +2,29 @@ load("//:defs.bzl", "MACOS_WEBRTC_RUSTC_LINK_FLAGS", "codex_rust_crate")
|
||||
|
||||
codex_rust_crate(
|
||||
name = "tui",
|
||||
crate_name = "codex_tui",
|
||||
compile_data = glob(
|
||||
include = ["**"],
|
||||
allow_empty = True,
|
||||
exclude = [
|
||||
"**/* *",
|
||||
"BUILD.bazel",
|
||||
"Cargo.toml",
|
||||
],
|
||||
allow_empty = True,
|
||||
) + [
|
||||
"//codex-rs/collaboration-mode-templates:templates/default.md",
|
||||
"//codex-rs/collaboration-mode-templates:templates/plan.md",
|
||||
],
|
||||
crate_name = "codex_tui",
|
||||
extra_binaries = [
|
||||
"//codex-rs/cli:codex",
|
||||
],
|
||||
integration_compile_data_extra = ["src/test_backend.rs"],
|
||||
rustc_flags_extra = MACOS_WEBRTC_RUSTC_LINK_FLAGS,
|
||||
test_data_extra = glob([
|
||||
"src/**/*.rs",
|
||||
"src/**/snapshots/**",
|
||||
]) + ["//codex-rs/core:model_availability_nux_fixtures"],
|
||||
integration_compile_data_extra = ["src/test_backend.rs"],
|
||||
extra_binaries = [
|
||||
"//codex-rs/cli:codex",
|
||||
],
|
||||
rustc_flags_extra = MACOS_WEBRTC_RUSTC_LINK_FLAGS,
|
||||
test_shard_counts = {
|
||||
"tui-unit-tests": 8,
|
||||
},
|
||||
)
|
||||
|
||||
37
defs.bzl
37
defs.bzl
@@ -1,8 +1,8 @@
|
||||
load("@crates//:data.bzl", "DEP_DATA")
|
||||
load("@crates//:defs.bzl", "all_crate_deps")
|
||||
load("@rules_platform//platform_data:defs.bzl", "platform_data")
|
||||
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", "rust_proc_macro", "rust_test")
|
||||
load("@rules_rust//cargo/private:cargo_build_script_wrapper.bzl", "cargo_build_script")
|
||||
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", "rust_proc_macro", "rust_test")
|
||||
|
||||
PLATFORMS = [
|
||||
"linux_arm64_musl",
|
||||
@@ -140,6 +140,7 @@ def codex_rust_crate(
|
||||
integration_test_args = [],
|
||||
integration_test_timeout = None,
|
||||
test_data_extra = [],
|
||||
test_shard_counts = {},
|
||||
test_tags = [],
|
||||
unit_test_timeout = None,
|
||||
extra_binaries = []):
|
||||
@@ -174,6 +175,10 @@ def codex_rust_crate(
|
||||
integration_test_timeout: Optional Bazel timeout for integration test
|
||||
targets generated from `tests/*.rs`.
|
||||
test_data_extra: Extra runtime data for tests.
|
||||
test_shard_counts: Mapping from generated test target name to Bazel
|
||||
shard count. Matching tests use native Bazel sharding on the
|
||||
original test label, while rules_rust assigns each Rust test case
|
||||
to a stable bucket by hashing the test name.
|
||||
test_tags: Tags applied to unit + integration test targets.
|
||||
Typically used to disable the sandbox, but see https://bazel.build/reference/be/common-definitions#common.tags
|
||||
unit_test_timeout: Optional Bazel timeout for the unit-test target
|
||||
@@ -246,7 +251,13 @@ def codex_rust_crate(
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
unit_test_name = name + "-unit-tests"
|
||||
unit_test_binary = name + "-unit-tests-bin"
|
||||
unit_test_shard_count = _test_shard_count(test_shard_counts, unit_test_name)
|
||||
unit_test_binary_kwargs = {}
|
||||
if unit_test_shard_count:
|
||||
unit_test_binary_kwargs["experimental_enable_sharding"] = True
|
||||
|
||||
rust_test(
|
||||
name = unit_test_binary,
|
||||
crate = name,
|
||||
@@ -265,14 +276,17 @@ def codex_rust_crate(
|
||||
rustc_env = rustc_env,
|
||||
data = test_data_extra,
|
||||
tags = test_tags + ["manual"],
|
||||
**unit_test_binary_kwargs
|
||||
)
|
||||
|
||||
unit_test_kwargs = {}
|
||||
if unit_test_timeout:
|
||||
unit_test_kwargs["timeout"] = unit_test_timeout
|
||||
if unit_test_shard_count:
|
||||
unit_test_kwargs["shard_count"] = unit_test_shard_count
|
||||
|
||||
workspace_root_test(
|
||||
name = name + "-unit-tests",
|
||||
name = unit_test_name,
|
||||
env = test_env,
|
||||
test_bin = ":" + unit_test_binary,
|
||||
workspace_root_marker = "//codex-rs/utils/cargo-bin:repo_root.marker",
|
||||
@@ -318,6 +332,13 @@ def codex_rust_crate(
|
||||
if not test_name.endswith("-test"):
|
||||
test_name += "-test"
|
||||
|
||||
test_kwargs = {}
|
||||
test_kwargs.update(integration_test_kwargs)
|
||||
test_shard_count = _test_shard_count(test_shard_counts, test_name)
|
||||
if test_shard_count:
|
||||
test_kwargs["experimental_enable_sharding"] = True
|
||||
test_kwargs["shard_count"] = test_shard_count
|
||||
|
||||
rust_test(
|
||||
name = test_name,
|
||||
crate_name = test_crate_name,
|
||||
@@ -339,5 +360,15 @@ def codex_rust_crate(
|
||||
# execute from the repo root and can misplace integration snapshots.
|
||||
env = cargo_env,
|
||||
tags = test_tags,
|
||||
**integration_test_kwargs
|
||||
**test_kwargs
|
||||
)
|
||||
|
||||
def _test_shard_count(test_shard_counts, test_name):
|
||||
shard_count = test_shard_counts.get(test_name)
|
||||
if shard_count == None:
|
||||
return None
|
||||
|
||||
if shard_count < 1:
|
||||
fail("test_shard_counts[{}] must be a positive integer".format(test_name))
|
||||
|
||||
return shard_count
|
||||
|
||||
@@ -10,7 +10,6 @@ exports_files([
|
||||
"rules_rust_windows_exec_bin_target.patch",
|
||||
"rules_rust_windows_exec_std.patch",
|
||||
"rules_rust_windows_process_wrapper_skip_temp_outputs.patch",
|
||||
"rules_rust_repository_set_exec_constraints.patch",
|
||||
"rules_rust_windows_msvc_direct_link_args.patch",
|
||||
"rules_rust_windows_gnullvm_build_script.patch",
|
||||
"rules_rs_windows_gnullvm_exec.patch",
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
diff --git a/rs/private/crate_git_repository.bzl b/rs/private/crate_git_repository.bzl
|
||||
--- a/rs/private/crate_git_repository.bzl
|
||||
+++ b/rs/private/crate_git_repository.bzl
|
||||
@@ -35,6 +35,14 @@
|
||||
"HEAD"
|
||||
])
|
||||
if result.return_code != 0:
|
||||
fail(result.stderr)
|
||||
|
||||
+ # Remove .git worktree pointer file. It contains an absolute path to
|
||||
+ # the bazel output base which is machine-specific and non-deterministic.
|
||||
+ # Leaving it in pollutes compile_data globs and causes AC misses.
|
||||
+ #
|
||||
+ # Note that bazelbuild/rules_rust ignores .git (among other paths) during splicing:
|
||||
+ # https://github.com/bazelbuild/rules_rust/blob/ca4915c0210bcd240152a5333ecb24d266bda144/crate_universe/src/splicing/splicer.rs#L42
|
||||
+ rctx.delete(root.get_child(".git"))
|
||||
+
|
||||
if strip_prefix:
|
||||
dest_link = dest_dir.get_child(strip_prefix)
|
||||
if not dest_link.exists:
|
||||
@@ -3,10 +3,9 @@
|
||||
# Scope: Windows-only linker metadata for the generated `rules_rs` toolchains.
|
||||
|
||||
diff --git a/rs/experimental/toolchains/declare_rustc_toolchains.bzl b/rs/experimental/toolchains/declare_rustc_toolchains.bzl
|
||||
index 67e491c..3f1cff5 100644
|
||||
--- a/rs/experimental/toolchains/declare_rustc_toolchains.bzl
|
||||
+++ b/rs/experimental/toolchains/declare_rustc_toolchains.bzl
|
||||
@@ -50,6 +50,8 @@ def declare_rustc_toolchains(
|
||||
@@ -54,6 +54,8 @@ def declare_rustc_toolchains(
|
||||
rust_toolchain(
|
||||
name = rust_toolchain_name,
|
||||
rust_doc = "{}rustdoc".format(rustc_repo_label),
|
||||
@@ -15,10 +14,11 @@ index 67e491c..3f1cff5 100644
|
||||
rust_std = select(rust_std_select),
|
||||
rustc = "{}rustc".format(rustc_repo_label),
|
||||
cargo = "{}cargo".format(cargo_repo_label),
|
||||
@@ -82,7 +84,20 @@ def declare_rustc_toolchains(
|
||||
stdlib_linkflags = select({
|
||||
"@platforms//os:freebsd": ["-lexecinfo", "-lpthread"],
|
||||
"@platforms//os:macos": ["-lSystem", "-lresolv"],
|
||||
@@ -100,8 +102,21 @@ def declare_rustc_toolchains(
|
||||
"@platforms//os:netbsd": ["-lpthread", "-lrt"],
|
||||
"@platforms//os:nixos": ["-ldl", "-lpthread"],
|
||||
"@platforms//os:openbsd": ["-lpthread"],
|
||||
"@platforms//os:ios": ["-lSystem", "-lobjc", "-Wl,-framework,Security", "-Wl,-framework,Foundation", "-lresolv"],
|
||||
- # TODO: windows
|
||||
+ "@rules_rs//rs/experimental/platforms/constraints:windows_gnullvm": [
|
||||
+ "advapi32.lib",
|
||||
@@ -38,16 +38,11 @@ index 67e491c..3f1cff5 100644
|
||||
}),
|
||||
default_edition = edition,
|
||||
diff --git a/rs/private/rustc_repository.bzl b/rs/private/rustc_repository.bzl
|
||||
index f4f0286..6558bb2 100644
|
||||
--- a/rs/private/rustc_repository.bzl
|
||||
+++ b/rs/private/rustc_repository.bzl
|
||||
@@ -1,13 +1,28 @@
|
||||
load("@rules_rust//rust/platform:triple.bzl", "triple")
|
||||
load(
|
||||
"@rules_rust//rust/private:repository_utils.bzl",
|
||||
"BUILD_for_compiler",
|
||||
@@ -6,10 +6,25 @@ load(
|
||||
)
|
||||
load(":rust_repository_utils.bzl", "download_and_extract", "RUST_REPOSITORY_COMMON_ATTR")
|
||||
load(":rust_repository_utils.bzl", "RUST_REPOSITORY_COMMON_ATTR", "download_and_extract")
|
||||
|
||||
+_WINDOWS_EXEC_LINKER_BUILD = """
|
||||
+filegroup(
|
||||
@@ -60,14 +55,14 @@ index f4f0286..6558bb2 100644
|
||||
def _rustc_repository_impl(rctx):
|
||||
exec_triple = triple(rctx.attr.triple)
|
||||
download_and_extract(rctx, "rustc", "rustc", exec_triple)
|
||||
- rctx.file("BUILD.bazel", BUILD_for_compiler(exec_triple))
|
||||
+ build_file = BUILD_for_compiler(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")
|
||||
+ build_file += _WINDOWS_EXEC_LINKER_BUILD
|
||||
+ rctx.file("BUILD.bazel", build_file)
|
||||
|
||||
return rctx.repo_metadata(reproducible = True)
|
||||
+ 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))
|
||||
rctx.file("BUILD.bazel", "\n".join(build_content))
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
# Scope: experimental platform/toolchain naming only; no Cargo target changes.
|
||||
|
||||
diff --git a/rs/experimental/platforms/triples.bzl b/rs/experimental/platforms/triples.bzl
|
||||
index 3ca3bb1..dd15656 100644
|
||||
--- a/rs/experimental/platforms/triples.bzl
|
||||
+++ b/rs/experimental/platforms/triples.bzl
|
||||
@@ -30,7 +30,9 @@ SUPPORTED_EXEC_TRIPLES = [
|
||||
@@ -16,12 +15,11 @@ index 3ca3bb1..dd15656 100644
|
||||
"aarch64-apple-darwin",
|
||||
]
|
||||
diff --git a/rs/experimental/toolchains/declare_rustc_toolchains.bzl b/rs/experimental/toolchains/declare_rustc_toolchains.bzl
|
||||
index b9a0ce1..67e491c 100644
|
||||
--- a/rs/experimental/toolchains/declare_rustc_toolchains.bzl
|
||||
+++ b/rs/experimental/toolchains/declare_rustc_toolchains.bzl
|
||||
@@ -10,6 +10,11 @@ def _channel(version):
|
||||
return "beta"
|
||||
return "stable"
|
||||
@@ -16,6 +16,11 @@ def _rustc_flags_to_select(rustc_flags_by_triple):
|
||||
{"//conditions:default": []},
|
||||
)
|
||||
|
||||
+def _exec_triple_suffix(exec_triple):
|
||||
+ if exec_triple.system == "windows":
|
||||
@@ -31,7 +29,7 @@ index b9a0ce1..67e491c 100644
|
||||
def declare_rustc_toolchains(
|
||||
*,
|
||||
version,
|
||||
@@ -23,15 +28,14 @@ def declare_rustc_toolchains(
|
||||
@@ -31,15 +36,14 @@ def declare_rustc_toolchains(
|
||||
|
||||
for triple in execs:
|
||||
exec_triple = _parse_triple(triple)
|
||||
@@ -50,7 +48,7 @@ index b9a0ce1..67e491c 100644
|
||||
version_key,
|
||||
)
|
||||
|
||||
@@ -90,11 +94,8 @@ def declare_rustc_toolchains(
|
||||
@@ -114,11 +118,8 @@ def declare_rustc_toolchains(
|
||||
target_key = sanitize_triple(target_triple)
|
||||
|
||||
native.toolchain(
|
||||
@@ -65,7 +63,6 @@ index b9a0ce1..67e491c 100644
|
||||
target_settings = [
|
||||
"@rules_rust//rust/toolchain/channel:" + channel,
|
||||
diff --git a/rs/experimental/toolchains/declare_rustfmt_toolchains.bzl b/rs/experimental/toolchains/declare_rustfmt_toolchains.bzl
|
||||
index a219209..ecb6b05 100644
|
||||
--- a/rs/experimental/toolchains/declare_rustfmt_toolchains.bzl
|
||||
+++ b/rs/experimental/toolchains/declare_rustfmt_toolchains.bzl
|
||||
@@ -1,8 +1,13 @@
|
||||
@@ -111,12 +108,63 @@ index a219209..ecb6b05 100644
|
||||
- "@platforms//cpu:" + exec_triple.arch,
|
||||
- ],
|
||||
+ name = "{}_rustfmt_{}".format(triple_suffix, version_key),
|
||||
+ exec_compatible_with = triple_to_constraint_set(triple),
|
||||
target_compatible_with = [],
|
||||
target_settings = [
|
||||
"@rules_rust//rust/toolchain/channel:" + channel,
|
||||
diff --git a/rs/experimental/toolchains/declare_rust_analyzer_toolchains.bzl b/rs/experimental/toolchains/declare_rust_analyzer_toolchains.bzl
|
||||
--- a/rs/experimental/toolchains/declare_rust_analyzer_toolchains.bzl
|
||||
+++ b/rs/experimental/toolchains/declare_rust_analyzer_toolchains.bzl
|
||||
@@ -3,9 +3,14 @@ load(
|
||||
"@rules_rust//rust/private:repository_utils.bzl",
|
||||
"includes_rust_analyzer_proc_macro_srv",
|
||||
)
|
||||
-load("//rs/experimental/platforms:triples.bzl", "SUPPORTED_EXEC_TRIPLES")
|
||||
+load("//rs/experimental/platforms:triples.bzl", "SUPPORTED_EXEC_TRIPLES", "triple_to_constraint_set")
|
||||
load("//rs/experimental/toolchains:toolchain_utils.bzl", "sanitize_version")
|
||||
|
||||
+def _exec_triple_suffix(exec_triple):
|
||||
+ if exec_triple.system == "windows":
|
||||
+ return "{}_{}_{}".format(exec_triple.system, exec_triple.arch, exec_triple.abi)
|
||||
+ return "{}_{}".format(exec_triple.system, exec_triple.arch)
|
||||
+
|
||||
def _channel(version):
|
||||
if version.startswith("nightly"):
|
||||
return "nightly"
|
||||
@@ -32,15 +37,14 @@ def declare_rust_analyzer_toolchains(
|
||||
|
||||
for triple in execs:
|
||||
exec_triple = _parse_triple(triple)
|
||||
- triple_suffix = exec_triple.system + "_" + exec_triple.arch
|
||||
+ triple_suffix = _exec_triple_suffix(exec_triple)
|
||||
|
||||
rustc_repo_label = "@rustc_{}_{}//:".format(triple_suffix, rust_analyzer_version_key)
|
||||
rust_analyzer_repo_label = "@rust_analyzer_{}_{}//:".format(triple_suffix, rust_analyzer_version_key)
|
||||
rust_src_repo_label = "@rust_src_{}//lib/rustlib/src:rustc_srcs".format(rust_analyzer_version_key)
|
||||
|
||||
- rust_analyzer_toolchain_name = "{}_{}_{}_rust_analyzer_toolchain".format(
|
||||
- exec_triple.system,
|
||||
- exec_triple.arch,
|
||||
+ rust_analyzer_toolchain_name = "{}_{}_rust_analyzer_toolchain".format(
|
||||
+ triple_suffix,
|
||||
version_key,
|
||||
)
|
||||
|
||||
@@ -59,11 +63,8 @@ def declare_rust_analyzer_toolchains(
|
||||
rust_analyzer_toolchain(**rust_analyzer_toolchain_kwargs)
|
||||
|
||||
native.toolchain(
|
||||
- name = "{}_{}_rust_analyzer_{}".format(exec_triple.system, exec_triple.arch, version_key),
|
||||
- exec_compatible_with = [
|
||||
- "@platforms//os:" + exec_triple.system,
|
||||
- "@platforms//cpu:" + exec_triple.arch,
|
||||
- ],
|
||||
+ name = "{}_rust_analyzer_{}".format(triple_suffix, version_key),
|
||||
+ exec_compatible_with = triple_to_constraint_set(triple),
|
||||
target_compatible_with = [],
|
||||
target_settings = [
|
||||
"@rules_rust//rust/toolchain/channel:" + channel,
|
||||
diff --git a/rs/experimental/toolchains/module_extension.bzl b/rs/experimental/toolchains/module_extension.bzl
|
||||
index 7bb0205..ace556b 100644
|
||||
--- a/rs/experimental/toolchains/module_extension.bzl
|
||||
+++ b/rs/experimental/toolchains/module_extension.bzl
|
||||
@@ -37,6 +37,11 @@ def _normalize_arch_name(arch):
|
||||
@@ -131,7 +179,7 @@ index 7bb0205..ace556b 100644
|
||||
def _sanitize_path_fragment(path):
|
||||
return path.replace("/", "_").replace(":", "_")
|
||||
|
||||
@@ -181,7 +186,7 @@ def _toolchains_impl(mctx):
|
||||
@@ -219,7 +224,7 @@ def _toolchains_impl(mctx):
|
||||
for triple in SUPPORTED_EXEC_TRIPLES:
|
||||
exec_triple = _parse_triple(triple)
|
||||
|
||||
@@ -140,7 +188,7 @@ index 7bb0205..ace556b 100644
|
||||
rustc_name = "rustc_{}_{}".format(triple_suffix, version_key)
|
||||
|
||||
rustc_repository(
|
||||
@@ -230,7 +235,7 @@ def _toolchains_impl(mctx):
|
||||
@@ -268,7 +273,7 @@ def _toolchains_impl(mctx):
|
||||
|
||||
for triple in SUPPORTED_EXEC_TRIPLES:
|
||||
exec_triple = _parse_triple(triple)
|
||||
@@ -149,3 +197,12 @@ index 7bb0205..ace556b 100644
|
||||
|
||||
rustfmt_repository(
|
||||
name = "rustfmt_{}_{}".format(triple_suffix, version_key),
|
||||
@@ -283,7 +288,7 @@ def _toolchains_impl(mctx):
|
||||
|
||||
for triple in SUPPORTED_EXEC_TRIPLES:
|
||||
exec_triple = _parse_triple(triple)
|
||||
- triple_suffix = exec_triple.system + "_" + exec_triple.arch
|
||||
+ triple_suffix = _exec_triple_suffix(exec_triple)
|
||||
|
||||
rust_analyzer_repository(
|
||||
name = "rust_analyzer_{}_{}".format(triple_suffix, version_key),
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
# What: let `rules_rust` repository_set entries specify an explicit exec-platform
|
||||
# constraint set.
|
||||
# Why: codex needs Windows nightly lint toolchains to run helper binaries on an
|
||||
# MSVC exec platform while still targeting `windows-gnullvm` crates.
|
||||
|
||||
diff --git a/rust/extensions.bzl b/rust/extensions.bzl
|
||||
--- a/rust/extensions.bzl
|
||||
+++ b/rust/extensions.bzl
|
||||
@@ -52,6 +52,7 @@ def _rust_impl(module_ctx):
|
||||
"allocator_library": repository_set.allocator_library,
|
||||
"dev_components": repository_set.dev_components,
|
||||
"edition": repository_set.edition,
|
||||
+ "exec_compatible_with": [str(v) for v in repository_set.exec_compatible_with] if repository_set.exec_compatible_with else None,
|
||||
"exec_triple": repository_set.exec_triple,
|
||||
"extra_target_triples": {repository_set.target_triple: [str(v) for v in repository_set.target_compatible_with]},
|
||||
"name": repository_set.name,
|
||||
@@ -166,6 +167,9 @@ _COMMON_TAG_KWARGS = {
|
||||
|
||||
_RUST_REPOSITORY_SET_TAG_ATTRS = {
|
||||
+ "exec_compatible_with": attr.label_list(
|
||||
+ doc = "Execution platform constraints for this repository_set.",
|
||||
+ ),
|
||||
"exec_triple": attr.string(
|
||||
doc = "Exec triple for this repository_set.",
|
||||
),
|
||||
"name": attr.string(
|
||||
@@ -7,7 +7,7 @@
|
||||
diff --git a/rust/toolchain.bzl b/rust/toolchain.bzl
|
||||
--- a/rust/toolchain.bzl
|
||||
+++ b/rust/toolchain.bzl
|
||||
@@ -209,6 +209,7 @@ def _generate_sysroot(
|
||||
@@ -209,6 +209,7 @@
|
||||
clippy = None,
|
||||
cargo_clippy = None,
|
||||
llvm_tools = None,
|
||||
@@ -15,7 +15,7 @@ diff --git a/rust/toolchain.bzl b/rust/toolchain.bzl
|
||||
rust_std = None,
|
||||
rustfmt = None,
|
||||
linker = None):
|
||||
@@ -312,7 +313,15 @@ def _generate_sysroot(
|
||||
@@ -312,7 +313,15 @@
|
||||
|
||||
# Made available to support $(location) expansion in stdlib_linkflags and extra_rustc_flags.
|
||||
transitive_file_sets.append(depset(ctx.files.rust_std))
|
||||
@@ -31,7 +31,7 @@ diff --git a/rust/toolchain.bzl b/rust/toolchain.bzl
|
||||
# Declare a file in the root of the sysroot to make locating the sysroot easy
|
||||
sysroot_anchor = ctx.actions.declare_file("{}/rust.sysroot".format(name))
|
||||
ctx.actions.write(
|
||||
@@ -323,6 +332,7 @@ def _generate_sysroot(
|
||||
@@ -323,6 +332,7 @@
|
||||
"cargo-clippy: {}".format(cargo_clippy),
|
||||
"linker: {}".format(linker),
|
||||
"llvm_tools: {}".format(llvm_tools),
|
||||
@@ -39,7 +39,7 @@ diff --git a/rust/toolchain.bzl b/rust/toolchain.bzl
|
||||
"rust_std: {}".format(rust_std),
|
||||
"rustc_lib: {}".format(rustc_lib),
|
||||
"rustc: {}".format(rustc),
|
||||
@@ -340,6 +350,7 @@ def _generate_sysroot(
|
||||
@@ -340,6 +350,7 @@
|
||||
cargo_clippy = sysroot_cargo_clippy,
|
||||
clippy = sysroot_clippy,
|
||||
linker = sysroot_linker,
|
||||
@@ -47,7 +47,7 @@ diff --git a/rust/toolchain.bzl b/rust/toolchain.bzl
|
||||
rust_std = sysroot_rust_std,
|
||||
rustc = sysroot_rustc,
|
||||
rustc_lib = sysroot_rustc_lib,
|
||||
@@ -410,12 +421,14 @@ def _rust_toolchain_impl(ctx):
|
||||
@@ -410,12 +421,14 @@
|
||||
)
|
||||
|
||||
rust_std = ctx.attr.rust_std
|
||||
@@ -62,7 +62,7 @@ diff --git a/rust/toolchain.bzl b/rust/toolchain.bzl
|
||||
rust_std = rust_std,
|
||||
rustfmt = ctx.file.rustfmt,
|
||||
clippy = ctx.file.clippy_driver,
|
||||
@@ -452,7 +465,7 @@ def _rust_toolchain_impl(ctx):
|
||||
@@ -452,7 +465,7 @@
|
||||
|
||||
expanded_stdlib_linkflags = _expand_flags(ctx, "stdlib_linkflags", rust_std[rust_common.stdlib_info].srcs, make_variables)
|
||||
expanded_extra_rustc_flags = _expand_flags(ctx, "extra_rustc_flags", rust_std[rust_common.stdlib_info].srcs, make_variables)
|
||||
@@ -71,7 +71,7 @@ diff --git a/rust/toolchain.bzl b/rust/toolchain.bzl
|
||||
|
||||
linking_context = cc_common.create_linking_context(
|
||||
linker_inputs = depset([
|
||||
@@ -793,6 +806,10 @@ rust_toolchain = rule(
|
||||
@@ -804,6 +817,10 @@
|
||||
doc = "The Rust standard library.",
|
||||
mandatory = True,
|
||||
),
|
||||
@@ -85,23 +85,23 @@ diff --git a/rust/toolchain.bzl b/rust/toolchain.bzl
|
||||
diff --git a/rust/private/repository_utils.bzl b/rust/private/repository_utils.bzl
|
||||
--- a/rust/private/repository_utils.bzl
|
||||
+++ b/rust/private/repository_utils.bzl
|
||||
@@ -341,6 +341,7 @@ rust_toolchain(
|
||||
name = "{toolchain_name}",
|
||||
rust_doc = "//:rustdoc",
|
||||
rust_std = "//:rust_std-{target_triple}",
|
||||
@@ -360,6 +360,7 @@
|
||||
staticlib_ext = "{staticlib_ext}",
|
||||
dylib_ext = "{dylib_ext}",
|
||||
stdlib_linkflags = [{stdlib_linkflags}],
|
||||
+ exec_rust_std = {exec_rust_std_label},
|
||||
rustc = "//:rustc",
|
||||
linker = {linker_label},
|
||||
linker_type = {linker_type},
|
||||
@@ -384,6 +385,7 @@ def BUILD_for_rust_toolchain(
|
||||
include_llvm_tools,
|
||||
include_linker,
|
||||
default_edition = "{default_edition}",
|
||||
exec_triple = "{exec_triple}",
|
||||
target_triple = "{target_triple}",
|
||||
@@ -389,6 +390,7 @@
|
||||
include_llvm_tools = False,
|
||||
include_linker = False,
|
||||
include_objcopy = False,
|
||||
+ exec_rust_std_label = None,
|
||||
stdlib_linkflags = None,
|
||||
extra_rustc_flags = None,
|
||||
extra_exec_rustc_flags = None,
|
||||
@@ -405,6 +407,7 @@ def BUILD_for_rust_toolchain(
|
||||
@@ -412,6 +414,7 @@
|
||||
include_llvm_tools (bool): Whether llvm-tools are present in the toolchain.
|
||||
include_linker (bool): Whether a linker is available in the toolchain.
|
||||
include_objcopy (bool): Whether rust-objcopy is available in the toolchain.
|
||||
@@ -109,7 +109,7 @@ diff --git a/rust/private/repository_utils.bzl b/rust/private/repository_utils.b
|
||||
stdlib_linkflags (list, optional): Overridden flags needed for linking to rust
|
||||
stdlib, akin to BAZEL_LINKLIBS. Defaults to
|
||||
None.
|
||||
@@ -453,6 +456,7 @@ def BUILD_for_rust_toolchain(
|
||||
@@ -465,6 +468,7 @@
|
||||
staticlib_ext = system_to_staticlib_ext(target_triple.system),
|
||||
dylib_ext = system_to_dylib_ext(target_triple.system),
|
||||
allocator_library = repr(allocator_library_label),
|
||||
@@ -120,7 +120,7 @@ diff --git a/rust/private/repository_utils.bzl b/rust/private/repository_utils.b
|
||||
diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl
|
||||
--- a/rust/private/rustc.bzl
|
||||
+++ b/rust/private/rustc.bzl
|
||||
@@ -1011,7 +1011,10 @@ def construct_arguments(
|
||||
@@ -999,7 +999,10 @@
|
||||
if build_metadata and not use_json_output:
|
||||
fail("build_metadata requires parse_json_output")
|
||||
|
||||
@@ -135,7 +135,7 @@ diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl
|
||||
diff --git a/rust/repositories.bzl b/rust/repositories.bzl
|
||||
--- a/rust/repositories.bzl
|
||||
+++ b/rust/repositories.bzl
|
||||
@@ -536,6 +536,18 @@ def _rust_toolchain_tools_repository_impl(ctx):
|
||||
@@ -574,6 +574,18 @@
|
||||
build_components.append(rust_stdlib_content)
|
||||
sha256s.update(rust_stdlib_sha256)
|
||||
|
||||
@@ -154,7 +154,7 @@ diff --git a/rust/repositories.bzl b/rust/repositories.bzl
|
||||
stdlib_linkflags = None
|
||||
if "BAZEL_RUST_STDLIB_LINKFLAGS" in ctx.os.environ:
|
||||
stdlib_linkflags = ctx.os.environ["BAZEL_RUST_STDLIB_LINKFLAGS"].split(":")
|
||||
@@ -552,6 +564,7 @@ def _rust_toolchain_tools_repository_impl(ctx):
|
||||
@@ -590,6 +602,7 @@
|
||||
include_llvm_tools = include_llvm_tools,
|
||||
include_linker = include_linker,
|
||||
include_objcopy = include_objcopy,
|
||||
@@ -162,12 +162,7 @@ diff --git a/rust/repositories.bzl b/rust/repositories.bzl
|
||||
extra_rustc_flags = ctx.attr.extra_rustc_flags,
|
||||
extra_exec_rustc_flags = ctx.attr.extra_exec_rustc_flags,
|
||||
opt_level = ctx.attr.opt_level if ctx.attr.opt_level else None,
|
||||
@@ -575,8 +588,16 @@ def _rust_toolchain_tools_repository_impl(ctx):
|
||||
if ctx.attr.dev_components:
|
||||
rustc_dev_sha256 = load_rustc_dev_nightly(
|
||||
ctx = ctx,
|
||||
target_triple = target_triple,
|
||||
version = version,
|
||||
@@ -608,6 +621,14 @@
|
||||
iso_date = iso_date,
|
||||
)
|
||||
sha256s.update(rustc_dev_sha256)
|
||||
@@ -179,3 +174,6 @@ diff --git a/rust/repositories.bzl b/rust/repositories.bzl
|
||||
+ iso_date = iso_date,
|
||||
+ )
|
||||
+ sha256s.update(exec_rustc_dev_sha256)
|
||||
|
||||
ctx.file("WORKSPACE.bazel", """workspace(name = "{}")""".format(
|
||||
ctx.name,
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
# What: keep Windows direct-linker arguments in forms link.exe/lld-link accept.
|
||||
# Scope: Windows direct-driver link arg filtering and runtime library handling.
|
||||
|
||||
--- a/rust/private/rustc.bzl
|
||||
+++ b/rust/private/rustc.bzl
|
||||
@@ -501,11 +501,41 @@
|
||||
@@ -501,11 +501,24 @@
|
||||
filtered_args.append(version)
|
||||
# Keep library search path flags
|
||||
|
||||
|
||||
+ elif processed_arg == "-L" and i + 1 < len(link_args):
|
||||
+ path = link_args[i + 1]
|
||||
+ if ld_is_direct_driver and toolchain.target_os == "windows":
|
||||
+ skip_next = True
|
||||
+ continue
|
||||
+ filtered_args.extend([processed_arg, path])
|
||||
+ filtered_args.extend([processed_arg, link_args[i + 1]])
|
||||
+ skip_next = True
|
||||
+
|
||||
elif processed_arg.startswith("-L"):
|
||||
@@ -26,37 +28,51 @@
|
||||
filtered_args.append(processed_arg)
|
||||
if processed_arg == "--sysroot" and i + 1 < len(link_args):
|
||||
# Two-part argument, keep the next arg too
|
||||
@@ -2305,7 +2335,7 @@
|
||||
return crate.metadata.dirname
|
||||
return crate.output.dirname
|
||||
@@ -2266,8 +2279,10 @@
|
||||
use_pic,
|
||||
ambiguous_libs,
|
||||
get_lib_name,
|
||||
+ for_windows = False,
|
||||
for_darwin = False,
|
||||
- flavor_msvc = False):
|
||||
+ flavor_msvc = False,
|
||||
+ use_direct_driver = False):
|
||||
"""_summary_
|
||||
|
||||
-def _portable_link_flags(lib, use_pic, ambiguous_libs, get_lib_name, for_windows = False, for_darwin = False, flavor_msvc = False):
|
||||
+def _portable_link_flags(lib, use_pic, ambiguous_libs, get_lib_name, for_windows = False, for_darwin = False, flavor_msvc = False, use_direct_driver = False):
|
||||
artifact = get_preferred_artifact(lib, use_pic)
|
||||
if ambiguous_libs and artifact.path in ambiguous_libs:
|
||||
artifact = ambiguous_libs[artifact.path]
|
||||
@@ -2344,6 +2344,11 @@
|
||||
artifact.basename.startswith("test-") or artifact.basename.startswith("std-")
|
||||
Args:
|
||||
@@ -2275,8 +2290,10 @@
|
||||
use_pic (_type_): _description_
|
||||
ambiguous_libs (_type_): _description_
|
||||
get_lib_name (_type_): _description_
|
||||
+ for_windows (bool, optional): _description_. Defaults to False.
|
||||
for_darwin (bool, optional): _description_. Defaults to False.
|
||||
flavor_msvc (bool, optional): _description_. Defaults to False.
|
||||
+ use_direct_driver (bool, optional): _description_. Defaults to False.
|
||||
|
||||
Returns:
|
||||
_type_: _description_
|
||||
@@ -2320,6 +2337,11 @@
|
||||
):
|
||||
return [] if for_darwin else ["-lstatic=%s" % get_lib_name(artifact)]
|
||||
+
|
||||
|
||||
+ if for_windows and use_direct_driver and not artifact.basename.endswith(".lib"):
|
||||
+ return [
|
||||
+ "-Clink-arg={}".format(artifact.path),
|
||||
+ ]
|
||||
|
||||
+
|
||||
if flavor_msvc:
|
||||
return [
|
||||
@@ -2381,7 +2386,7 @@
|
||||
"-lstatic=%s" % get_lib_name(artifact),
|
||||
@@ -2356,7 +2378,7 @@
|
||||
])
|
||||
elif include_link_flags:
|
||||
get_lib_name = get_lib_name_for_windows if flavor_msvc else get_lib_name_default
|
||||
- ret.extend(_portable_link_flags(lib, use_pic, ambiguous_libs, get_lib_name, flavor_msvc = flavor_msvc))
|
||||
+ ret.extend(_portable_link_flags(lib, use_pic, ambiguous_libs, get_lib_name, flavor_msvc = flavor_msvc, use_direct_driver = use_direct_driver))
|
||||
- ret.extend(portable_link_flags(lib, use_pic, ambiguous_libs, get_lib_name, flavor_msvc = flavor_msvc))
|
||||
+ ret.extend(portable_link_flags(lib, use_pic, ambiguous_libs, get_lib_name, for_windows = True, flavor_msvc = flavor_msvc, use_direct_driver = use_direct_driver))
|
||||
|
||||
# Windows toolchains can inherit POSIX defaults like -pthread from C deps,
|
||||
# which fails to link with the MinGW/LLD toolchain. Drop them here.
|
||||
@@ -2453,14 +2483,21 @@
|
||||
@@ -2532,14 +2554,21 @@
|
||||
else:
|
||||
# For all other crate types we want to link C++ runtime library statically
|
||||
# (for example libstdc++.a or libc++.a).
|
||||
@@ -74,16 +90,9 @@
|
||||
format_each = "-Lnative=%s",
|
||||
)
|
||||
if include_link_flags:
|
||||
- args.add_all(
|
||||
args.add_all(
|
||||
- cc_toolchain.static_runtime_lib(feature_configuration = feature_configuration),
|
||||
- map_each = get_lib_name,
|
||||
- format_each = "-lstatic=%s",
|
||||
- )
|
||||
+ args.add_all(
|
||||
+ runtime_libs,
|
||||
+ map_each = get_lib_name,
|
||||
+ format_each = "-lstatic=%s",
|
||||
+ )
|
||||
|
||||
def _get_dirname(file):
|
||||
"""A helper function for `_add_native_link_flags`.
|
||||
map_each = get_lib_name,
|
||||
format_each = "-lstatic=%s",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user