-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Description
Motivation
The mechanism by which execution platforms are determined for actions is toolchain selection. Traditionally, Bazel didn't define any toolchain requirements for the test exec group, which is the implicitly defined exec group owning the action that executes a test. This resulted in tests being run on the first registered execution platform, which may not match the target platform in cross-platform builds and thus frequently resulted in execution time failures such as "exec format" errors.
Description
All test rules without an explicitly defined test exec group have a mandatory toolchain requirement for @bazel_tools//tools/test:default_test_toolchain_type. With --@bazel_tools//tools/test:incompatible_use_default_test_toolchain, the default toolchain registered for this type matches any execution platform that satisfies all constraints provided by the target platform. With the flag disabled, the default toolchain registered for this type does not require any constraints, thus retaining the legacy behavior of selecting the first registered execution platform.
Incompatible Flag
--@bazel_tools//tools/test:incompatible_use_default_test_toolchain
Migration Guide
Most projects should not require any migration as any new analysis errors should arise only in situations that would have previously resulted in test failures at runtime.
Action is recommended in the following cases:
- If you previously used
--use_target_platform_for_tests, remove all usages of the flag and instead ensure that your target platforms are also registered as execution platforms (e.g. viaregister_execution_platformsinMODULE.bazelor--extra_execution_platforms). - If you maintain test rules that can execute tests on platforms that do not match all target platform constraints (e.g. shell tests that can run on any Unix platform), explicitly define a
testexec group to override the default behavior. You can add a mandatory toolchain requirement and register toolchains for its type that model your intended translation of target platform to execution platform constraints.
In which Bazel LTS version will this incompatible change be enabled?
Bazel 9
Additional Context
No response
TODO List
No response