Skip to content

Latest commit

 

History

History
97 lines (81 loc) · 4.09 KB

2024-04-26-platform-exec-settings.md

File metadata and controls

97 lines (81 loc) · 4.09 KB
created last updated status reviewers title authors discussion thread
2024-04-26
2024-05-08
approved
gregestren
Selectively Enabling Execution Platforms
katre

Overview

Currently, execution platforms are registered in the WORKSPACE or MODULE.bazel files, or added via the --extra_execution_platforms flag. At that point they are available for toolchain resolution and to be used for rules and actions.

In some cases, this is too restrictive: there are projects that are currently using transitions to change the value of --extra_execution_platforms and add new execution platforms mid-build. Also, because of the semantics of the flag, repeated use of --extra_execution_platforms overrides previous values, instead of accumulating them.

The similar ways of registering toolchains has a way around this: the toolchain rule has an attribute called target_settings, which is a list of targets that provide ConfigMatchingProvider (such as config_setting). When a toolchain specifies target_settings, the toolchain is only available if all of the settings are true for the current configuration.

Proposal

To allow execution platforms to control whether they are active, a new attribute will be added, named required_settings, which will take targets that provide ConfigMatchingProvider. When the list of execution platforms is evaluated during toolchain resolution, each execution platform will check the enabled settings and any that don't match the configuration will be skipped (and reported if toolchain resolution debugging is active).

This attribute has no influence on whether a platform can be used as a target platform (ie, with the --platforms flag).

Example of platform settings

config_setting(
    name = "extra_logging_enabled",
    flag_values = { "//flag:extra_logging": "True" },
)

CONSTRAINT_VALUES = [ ... ]

platform(
    name = "remote_extra_logging",
    constraint_values = CONSTRAINT_VALUES,
    exec_properties = ...,
    required_settings = [
        ":extra_logging_enabled",
    ],
)

platform(
    name = "remote",
    constraint_values = CONSTRAINT_VALUES,
    exec_properties = ...,
)

If both of these platforms are available (either via register_execution_platforms or --extra_toolchains), and the default for the --//flag:extra_logging flag is False, then the remote platform will be used because the required_settings will not match. Once the flag is set, the required_settings will match, and the remote_extra_logging platform will be available (and is registered before the other).

In this case, to be very specific, an additional config_setting could be defined as the opposite of extra_logging_enabled and used to guard remote to ensure that only one of the two can ever be enabled at the same time.

Implementation

The implementation will mirror the implementation for toolchain.target_settings, by accumulating the ConfigMatchingProvider instances and storing them in the [PlatformInfo] provider. Then they will be checked during toolchain resolution to produce the list of usable execution platforms.