bazel: shard selected rust tests

Use the merged hermeticbuild rules_rust sharding support and configure the generated core, app-server, and tui test targets that benefit from sharding for eight shards.

Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
Michael Bolin
2026-04-15 14:57:21 -07:00
co-authored by Codex
parent 9e2fc31854
commit 94665c46ea
10 changed files with 283 additions and 167 deletions
+87 -102
View File
@@ -4,7 +4,90 @@
# The toolchain sysroot must therefore carry both stdlib trees so rustc can
# resolve the correct one for each `--target`.
diff --git a/rust/private/repository_utils.bzl b/rust/private/repository_utils.bzl
index ad8aea481..341ed70bb 100644
--- a/rust/private/repository_utils.bzl
+++ b/rust/private/repository_utils.bzl
@@ -342,6 +342,7 @@ rust_toolchain(
name = "{toolchain_name}",
rust_doc = "//:rustdoc",
rust_std = "//:rust_std-{target_triple}",
+ exec_rust_std = {exec_rust_std_label},
rustc = "//:rustc",
linker = {linker_label},
linker_type = {linker_type},
@@ -389,6 +390,7 @@ def BUILD_for_rust_toolchain(
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,
@@ -412,6 +414,7 @@ def BUILD_for_rust_toolchain(
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.
+ exec_rust_std_label (str, optional): Label for an exec-side stdlib when it differs from rust_std.
stdlib_linkflags (list, optional): Overridden flags needed for linking to rust
stdlib, akin to BAZEL_LINKLIBS. Defaults to
None.
@@ -465,6 +468,7 @@ def BUILD_for_rust_toolchain(
staticlib_ext = system_to_staticlib_ext(target_triple.system),
dylib_ext = system_to_dylib_ext(target_triple.system),
allocator_library = repr(allocator_library_label),
+ exec_rust_std_label = repr(exec_rust_std_label),
global_allocator_library = repr(global_allocator_library_label),
stdlib_linkflags = stdlib_linkflags,
default_edition = default_edition,
diff --git a/rust/repositories.bzl b/rust/repositories.bzl
index e4bd37f4c..66bd95bde 100644
--- a/rust/repositories.bzl
+++ b/rust/repositories.bzl
@@ -574,6 +574,18 @@ def _rust_toolchain_tools_repository_impl(ctx):
build_components.append(rust_stdlib_content)
sha256s.update(rust_stdlib_sha256)
+ exec_rust_std_label = None
+ if exec_triple.str != target_triple.str:
+ exec_rust_stdlib_content, exec_rust_stdlib_sha256 = load_rust_stdlib(
+ ctx = ctx,
+ target_triple = exec_triple,
+ version = version,
+ iso_date = iso_date,
+ )
+ build_components.append(exec_rust_stdlib_content)
+ sha256s.update(exec_rust_stdlib_sha256)
+ exec_rust_std_label = "//:rust_std-{}".format(exec_triple.str)
+
stdlib_linkflags = None
if "BAZEL_RUST_STDLIB_LINKFLAGS" in ctx.os.environ:
stdlib_linkflags = ctx.os.environ["BAZEL_RUST_STDLIB_LINKFLAGS"].split(":")
@@ -590,6 +602,7 @@ def _rust_toolchain_tools_repository_impl(ctx):
include_llvm_tools = include_llvm_tools,
include_linker = include_linker,
include_objcopy = include_objcopy,
+ exec_rust_std_label = exec_rust_std_label,
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,
@@ -608,6 +621,14 @@ def _rust_toolchain_tools_repository_impl(ctx):
iso_date = iso_date,
)
sha256s.update(rustc_dev_sha256)
+ if exec_triple.str != target_triple.str:
+ exec_rustc_dev_sha256 = load_rustc_dev_nightly(
+ ctx = ctx,
+ target_triple = exec_triple,
+ version = version,
+ iso_date = iso_date,
+ )
+ sha256s.update(exec_rustc_dev_sha256)
ctx.file("WORKSPACE.bazel", """workspace(name = "{}")""".format(
ctx.name,
diff --git a/rust/toolchain.bzl b/rust/toolchain.bzl
index 10465b5a7..6e322535c 100644
--- a/rust/toolchain.bzl
+++ b/rust/toolchain.bzl
@@ -209,6 +209,7 @@ def _generate_sysroot(
@@ -15,16 +98,15 @@ diff --git a/rust/toolchain.bzl b/rust/toolchain.bzl
rust_std = None,
rustfmt = None,
linker = None):
@@ -312,7 +313,15 @@ def _generate_sysroot(
@@ -313,6 +314,14 @@ def _generate_sysroot(
# Made available to support $(location) expansion in stdlib_linkflags and extra_rustc_flags.
transitive_file_sets.append(depset(ctx.files.rust_std))
+
+ sysroot_exec_rust_std = None
+ if exec_rust_std:
+ sysroot_exec_rust_std = _symlink_sysroot_tree(ctx, name, exec_rust_std)
+ transitive_file_sets.extend([sysroot_exec_rust_std])
+
+ # Made available to support $(location) expansion in extra_exec_rustc_flags.
+ transitive_file_sets.append(depset(ctx.files.exec_rust_std))
+
@@ -71,7 +153,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 @@ rust_toolchain = rule(
doc = "The Rust standard library.",
mandatory = True,
),
@@ -82,100 +164,3 @@ diff --git a/rust/toolchain.bzl b/rust/toolchain.bzl
"rustc": attr.label(
doc = "The location of the `rustc` binary. Can be a direct source or a filegroup containing one item.",
allow_single_file = True,
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}",
+ 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,
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(
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.
+ exec_rust_std_label (str, optional): Label for an exec-side stdlib when it differs from rust_std.
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(
staticlib_ext = system_to_staticlib_ext(target_triple.system),
dylib_ext = system_to_dylib_ext(target_triple.system),
allocator_library = repr(allocator_library_label),
+ exec_rust_std_label = repr(exec_rust_std_label),
global_allocator_library = repr(global_allocator_library_label),
stdlib_linkflags = stdlib_linkflags,
default_edition = default_edition,
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(
if build_metadata and not use_json_output:
fail("build_metadata requires parse_json_output")
- use_exec_target = is_exec_configuration(ctx) and crate_info.type == "bin"
+ # Exec-configuration crates (build scripts, proc-macros, and their
+ # dependencies) must all target the exec triple so they can link against
+ # each other and the exec-side standard library.
+ use_exec_target = is_exec_configuration(ctx)
output_dir = getattr(crate_info.output, "dirname", None)
linker_script = getattr(file, "linker_script", None)
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):
build_components.append(rust_stdlib_content)
sha256s.update(rust_stdlib_sha256)
+ exec_rust_std_label = None
+ if exec_triple.str != target_triple.str:
+ exec_rust_stdlib_content, exec_rust_stdlib_sha256 = load_rust_stdlib(
+ ctx = ctx,
+ target_triple = exec_triple,
+ version = version,
+ iso_date = iso_date,
+ )
+ build_components.append(exec_rust_stdlib_content)
+ sha256s.update(exec_rust_stdlib_sha256)
+ exec_rust_std_label = "//:rust_std-{}".format(exec_triple.str)
+
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):
include_llvm_tools = include_llvm_tools,
include_linker = include_linker,
include_objcopy = include_objcopy,
+ exec_rust_std_label = exec_rust_std_label,
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,
iso_date = iso_date,
)
sha256s.update(rustc_dev_sha256)
+ if exec_triple.str != target_triple.str:
+ exec_rustc_dev_sha256 = load_rustc_dev_nightly(
+ ctx = ctx,
+ target_triple = exec_triple,
+ version = version,
+ iso_date = iso_date,
+ )
+ sha256s.update(exec_rustc_dev_sha256)