bazel icon indicating copy to clipboard operation
bazel copied to clipboard

Filter spawn strategies by execution platform

Open Silic0nS0ldier opened this issue 1 year ago • 14 comments

This PR implements part of the Execution Platform Scoped Spawn Strategies proposal.

It adds a new flag --allowed_strategies_by_exec_platform which permits filtering spawn strategies for spawns execution platform.

Example

# //.bazelrc
# Default strategies (order sensitive)
build --spawn_strategy=remote,worker,sandboxed,local

# Mnemonic targeted strategy override (order sensitive)
build --strategy=BAR=remote,sandboxed

# Host platform allowed strategies
build --allowed_strategies_by_exec_platform=@platforms//host:host=local,sandboxed,worker

# Remote platform allowed strategies
build --allowed_strategies_by_exec_platform=//:remote_platform=remote

For an action with mnemonic FOO configured for the host platform (@platforms//host:host), it will resolve worker,sandboxed,local as it's spawn strategy candidates.

  • remote was eliminated as a candidate (not in allow list for platform).
  • Order from --spawn_strategy was preserved.

For an action with mnemonic BAR configured for the host platform (@platforms//host:host), it will resolve sandboxed as it's spawn strategy candidate.

  • remote was eliminated as a candidate (not in allow list for platform).
  • Mnemonic override applied, leaving sandboxed as the final candidate.

For an action with mnemonic BAR configured for the remote platform (//:remote_platform), it will resolve remote as it's spawn strategy candidate.

  • sandboxed was eliminated as a candidate (not in allow list for platform).
  • Mnemonic override applied, leaving remote as the final candidate.

If no spawn strategy candidate remains after filtering, the standard error will be logged.

ERROR: /workspaces/___/BUILD.bazel:3:22: _description_ [for tool] failed: _mnemonic_ spawn \
cannot be executed with any of the available strategies: []. Your --spawn_strategy, \
--genrule_strategy, --strategy and/or --allowed_strategies_by_exec_platform flags are probably \
too strict. Visit https://github.com/bazelbuild/bazel/issues/7480 for advice

Silic0nS0ldier avatar Nov 11 '24 03:11 Silic0nS0ldier

cc @katre

Silic0nS0ldier avatar Nov 11 '24 03:11 Silic0nS0ldier

@Silic0nS0ldier Can you please fix the test failures? (It looks like the execution platform is null in a bunch of places.)

tjgq avatar Nov 19 '24 17:11 tjgq

@tjgq The null platform issue is fixed by https://github.com/bazelbuild/bazel/pull/23231 which this is dependent on.

Silic0nS0ldier avatar Nov 19 '24 23:11 Silic0nS0ldier

What's the status of this PR?

meisterT avatar May 07 '25 11:05 meisterT

I didn't have much time to focus on this recently, but I do now.

PR has been rebased and prior feedback implemented. This is now ready for review.

Silic0nS0ldier avatar Jun 28 '25 07:06 Silic0nS0ldier

@gregestren This is ready for review.

Silic0nS0ldier avatar Jul 12 '25 05:07 Silic0nS0ldier

@meteorcloudy Can you reassign this to @gregestren and ping him about it? Thanks.

katre avatar Jul 20 '25 16:07 katre

@Silic0nS0ldier What's the status? Happy to help if you need any!

fmeum avatar Nov 13 '25 18:11 fmeum

Waiting for review.

Silic0nS0ldier avatar Nov 13 '25 18:11 Silic0nS0ldier

@gregestren I'll do a review pass soon. Let's try to get this into Bazel 9 as it nicely complements the new default test toolchain to finally make "what's executed where" work

fmeum avatar Nov 13 '25 18:11 fmeum

@bazel-io fork 9.0.0

fmeum avatar Nov 13 '25 18:11 fmeum

Checking in: I'll do a proper review Monday. Thanks for your ongoing patience @Silic0nS0ldier

gregestren avatar Nov 14 '25 22:11 gregestren

Some internal tests are failing and blocking merging. I'll look into them and report back: keeping Bazel 9 cutoff timelines in mind.

gregestren avatar Dec 08 '25 21:12 gregestren

Some internal tests are failing and blocking merging. I'll look into them and report back: keeping Bazel 9 cutoff timelines in mind.

Internal PR adjusted and now in the merge queue. Had to:

  • register the filter values with Google's version of BazelStrategyModule
  • add exec platforms to internal tests
  • adjust execution_strategies_test for slightly different strategy names

Also applied a few code lints and BUILD dependency cleanups.

This'll get merged as soon as we get internal approvals.

gregestren avatar Dec 09 '25 19:12 gregestren