feat(toolchains): add toolchain_target_settings to python.override#3731
feat(toolchains): add toolchain_target_settings to python.override#3731novas0x2a wants to merge 1 commit intobazel-contrib:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a toolchain_target_settings attribute to the python.override module extension tag, enabling users to globally append config_setting labels to the target_settings of all toolchains registered by the extension. This feature is particularly useful for gating default toolchains behind custom build settings to prevent unintended fallbacks. The PR includes the necessary logic in the extension implementation, updated documentation, and new integration and unit tests. Feedback was provided to clarify the documentation regarding how these global settings interact with toolchains that already have specific target_settings defined, ensuring users understand that the settings are appended rather than ignored.
274814e to
691a089
Compare
Users who register custom toolchain families (e.g. gated behind a string_flag like "custom" vs "prebuilt") have no way to prevent the default-registered toolchains from acting as a silent fallback. When a user requests a custom toolchain at a version they didn't register, Bazel's toolchain resolution quietly falls back to the default prebuilt toolchain instead of producing an error. Add a `toolchain_target_settings` attribute to `python.override` that appends the given config_setting labels to the `target_settings` of every toolchain registered by the module extension. This lets users gate the default toolchains behind a config_setting so they only resolve when explicitly selected, giving a clean separation between toolchain families. These settings are appended to the `target_settings` of all toolchains registered by the extension, including any that already have settings from `python.single_version_platform_override`. Toolchains registered outside the extension (e.g. via `local_runtime_toolchains_repo`) are not affected. Fixes bazel-contrib#3673
691a089 to
80eac09
Compare
Users who register custom toolchain families (e.g. gated behind a
string_flag like "custom" vs "prebuilt") have no way to prevent the
default-registered toolchains from acting as a silent fallback. When a
user requests a custom toolchain at a version they didn't register,
Bazel's toolchain resolution quietly falls back to the default prebuilt
toolchain instead of producing an error.
This adds a
toolchain_target_settingsattribute topython.overridethat appends the given
config_settinglabels to thetarget_settingsof every toolchain registered by the module extension:
These settings are appended to the
target_settingsof all toolchainsregistered by the extension, including any that already have settings
from
python.single_version_platform_override. Toolchains registeredoutside the extension (e.g. via
local_runtime_toolchains_repo) are notaffected.
Note:
toolchain_target_settingsis popped from the configdefaultdict before it reaches
python_register_toolchains(), so it doesn'tleak into the
python_repositorykwargs.Integration test passes across the full Bazel version matrix (7.7.0,
8.5.1, 9.0.0rc1). Verified the test fails without the fix (default
toolchain silently resolves as fallback).
Fixes #3673