Skip to content

Conversation

@brianduff
Copy link

Problem

rust_test targets don't support Bazel's native test sharding. When shard_count is set on a rust_test:

  • Without --incompatible_check_sharding_support: all tests run N times (once per shard)
  • With --incompatible_check_sharding_support: the test fails because Rust's libtest harness doesn't read TEST_SHARD_INDEX/TEST_TOTAL_SHARDS environment variables

Solution

This PR adds opt-in sharding support via a new experimental_enable_sharding attribute. When enabled, tests are executed via a wrapper script that:

  1. Detects sharding via TEST_TOTAL_SHARDS environment variable
  2. Touches TEST_SHARD_STATUS_FILE to advertise sharding support to Bazel
  3. Enumerates tests using libtest's --list --format terse flag
  4. Partitions tests by index % TEST_TOTAL_SHARDS == TEST_SHARD_INDEX
  5. Runs only the tests assigned to the current shard using --exact

Usage

rust_test(
    name = "my_test",
    srcs = ["my_test.rs"],
    shard_count = 4,
    experimental_enable_sharding = True,
)

@brianduff brianduff marked this pull request as draft December 12, 2025 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant