[codex] Add rust_test sharding support#13
Merged
dzbarsky merged 1 commit intohermeticbuild:mainfrom Apr 15, 2026
Merged
Conversation
|
|
||
| return providers | ||
|
|
||
| def _maybe_wrap_sharded_test(ctx, providers, toolchain): |
There was a problem hiding this comment.
would it be cleaner to have rustc_compile_action() return a dict of named providers instead of a positional list? Then rust_test can look up DefaultInfo / crate_info / test_crate_info directly instead of sniffing provider shape/order.
providers = rustc_compile_action(...)
default_info = providers["DefaultInfo"]
crate_info = providers.get("crate_info") or providers.get("test_crate_info")
if hasattr(crate_info, "crate"):
crate_info = crate_info.crate
test_binary = crate_info.output
providers["DefaultInfo"] = DefaultInfo(
files = default_info.files,
runfiles = default_info.default_runfiles.merge(ctx.runfiles(files = [test_binary])),
executable = wrapper,
)
return list(providers.values())
Port the sharding wrapper feature from bazelbuild#3774 into the hermeticbuild fork. This updates rustc_compile_action to return a dict of named providers so rust_test can replace DefaultInfo without provider-shape sniffing when experimental_enable_sharding is set. Co-authored-by: Brian Duff <bduff@linkedin.com> Co-authored-by: Codex <noreply@openai.com>
b0a7f0d to
1f3dd3b
Compare
dzbarsky
pushed a commit
that referenced
this pull request
Apr 15, 2026
Port the sharding wrapper feature from bazelbuild#3774 into the hermeticbuild fork. This updates rustc_compile_action to return a dict of named providers so rust_test can replace DefaultInfo without provider-shape sniffing when experimental_enable_sharding is set. Co-authored-by: Brian Duff <bduff@linkedin.com> Co-authored-by: Codex <noreply@openai.com>
dzbarsky
pushed a commit
that referenced
this pull request
Apr 16, 2026
Port the sharding wrapper feature from bazelbuild#3774 into the hermeticbuild fork. This updates rustc_compile_action to return a dict of named providers so rust_test can replace DefaultInfo without provider-shape sniffing when experimental_enable_sharding is set. Co-authored-by: Brian Duff <bduff@linkedin.com> Co-authored-by: Codex <noreply@openai.com>
dzbarsky
pushed a commit
that referenced
this pull request
Apr 16, 2026
Port the sharding wrapper feature from bazelbuild#3774 into the hermeticbuild fork. The implementation wraps rust_test executables when experimental_enable_sharding is set while keeping rustc_compile_action's existing provider-list API for internal and extension callers. rust_test now scans the returned providers to replace DefaultInfo for the wrapper, so extensions such as prost and wasm-bindgen continue to consume rustc_compile_action without API churn. Co-authored-by: Brian Duff <bduff@linkedin.com> Co-authored-by: Codex <noreply@openai.com>
dzbarsky
pushed a commit
that referenced
this pull request
Apr 16, 2026
Port the sharding wrapper feature from bazelbuild#3774 into the hermeticbuild fork. The implementation wraps rust_test executables when experimental_enable_sharding is set while keeping rustc_compile_action's existing provider-list API for internal and extension callers. rust_test now scans the returned providers to replace DefaultInfo for the wrapper, so extensions such as prost and wasm-bindgen continue to consume rustc_compile_action without API churn. Co-authored-by: Brian Duff <bduff@linkedin.com> Co-authored-by: Codex <noreply@openai.com>
zbarsky-openai
added a commit
to openai/codex
that referenced
this pull request
Apr 17, 2026
## Why This branch brings the Bazel module pins for `rules_rs` and `llvm` up to the latest BCR releases and aligns the root direct dependencies with the versions the module graph already resolves to. That gives us a few concrete wins: - picks up newer upstream fixes in the `rules_rs` / `rules_rust` stack, including work around repo-rule nondeterminism and default Cargo binary target generation - picks up test sharding support from the newer `rules_rust` stack ([hermeticbuild/rules_rust#13](hermeticbuild/rules_rust#13)) - picks up newer built-in knowledge for common system crates like `gio-sys`, `glib-sys`, `gobject-sys`, `libgit2-sys`, and `libssh2-sys`, which gives us a future path to reduce custom build-script handling - reduces local patch maintenance by dropping fixes that are now upstream and rebasing the remaining Windows patch stack onto a newer upstream base - removes the direct-dependency warnings from `bazel-lock-check` by making the root pins match the resolved graph ## What Changed - bump `rules_rs` from `0.0.43` to `0.0.58` - bump `llvm` from `0.6.8` to `0.7.1` - bump `bazel_skylib` from `1.8.2` to `1.9.0` so the root direct dep matches the resolved graph - regenerate `MODULE.bazel.lock` for the updated module graph - refresh the remaining Windows-specific patch stack against the newer upstream sources: - `patches/rules_rs_windows_gnullvm_exec.patch` - `patches/rules_rs_windows_exec_linker.patch` - `patches/rules_rust_windows_exec_std.patch` - `patches/rules_rust_windows_msvc_direct_link_args.patch` - remove patches that are no longer needed because the underlying fixes are upstream now: - `patches/rules_rs_delete_git_worktree_pointer.patch` - `patches/rules_rust_repository_set_exec_constraints.patch` ## Validation - `just bazel-lock-update` - `just bazel-lock-check` --------- Co-authored-by: Codex <noreply@openai.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ports the
rust_testsharding feature from bazelbuild#3774 into the hermeticbuild fork.This adds an opt-in
experimental_enable_shardingattribute forrust_test. When enabled with the libtest harness, the rule swaps the test executable for a generated wrapper script that:TEST_SHARD_STATUS_FILEso Bazel recognizes sharding support--list --format terseTEST_SHARD_INDEXandTEST_TOTAL_SHARDS--exactThe wrapper partitions tests deterministically from libtest's listing order. It keeps a zero-based index for every listed test and runs a test in a shard when:
For example, with 4 shards, tests at indices
0, 4, 8, ...run in shard 0; indices1, 5, 9, ...run in shard 1; and so on.The implementation is adapted for this fork by making
rustc_compile_action()return a dict of named providers. Rule implementations convert that dict back to a provider list at their return boundary, whilerust_testcan look up and replaceDefaultInfodirectly when sharding is enabled.Expected Codex Usage
Once Codex consumes this fork update, the plan is to expose a small per-target sharding config in the Codex
codex_rust_cratemacro rather than sharding every Rust test target. The initial use case is the largecodex-coretest targets:For generated integration-test targets like
core-all-test, the macro can pass bothexperimental_enable_sharding = Trueandshard_count = 8directly to the generatedrust_test.For
core-unit-tests, Codex wraps the Rust unit-test binary in aworkspace_root_testlauncher so tests execute from the repo root. That means the outerworkspace_root_testtarget needsshard_count = 8so Bazel schedules separate shards, while the innercore-unit-tests-binrust_testneedsexperimental_enable_sharding = Trueso the executable that the launcher runs honorsTEST_SHARD_INDEXandTEST_TOTAL_SHARDS.Validation
bazel test //test/unit/test_sharding:test_sharding_test_suitebazel test --cache_test_results=no --incompatible_check_sharding_support //test/unit/test_sharding:sharded_integration_testbazel test //test/unit/test_sharding:test_sharding_test_suite //test/unit/consistent_crate_name:consistent_crate_name_test_suite //test/unit/force_all_deps_direct:force_all_deps_direct_test_suite //test/unit/pipelined_compilation:pipelined_compilation_test_suitebazel build //rust/private:bzl_lib(cd extensions/prost && bazel build //private:bzl_lib)(cd extensions/wasm_bindgen && bazel build //private:bzl_lib)