Skip to content

feat(toolchains): add toolchain_target_settings to python.override#3731

Open
novas0x2a wants to merge 1 commit intobazel-contrib:mainfrom
novas0x2a:feat/toolchain-target-settings
Open

feat(toolchains): add toolchain_target_settings to python.override#3731
novas0x2a wants to merge 1 commit intobazel-contrib:mainfrom
novas0x2a:feat/toolchain-target-settings

Conversation

@novas0x2a
Copy link
Copy Markdown

@novas0x2a novas0x2a commented Apr 23, 2026

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_settings attribute to python.override
that appends the given config_setting labels to the target_settings
of every toolchain registered by the module extension:

python.override(
    toolchain_target_settings = ["@@//:python_toolchain_family_prebuilt"],
)

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.

Note: toolchain_target_settings is popped from the config default
dict before it reaches python_register_toolchains(), so it doesn't
leak into the python_repository kwargs.

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

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread python/private/python.bzl Outdated
@novas0x2a novas0x2a force-pushed the feat/toolchain-target-settings branch from 274814e to 691a089 Compare April 23, 2026 20:52
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
@novas0x2a novas0x2a force-pushed the feat/toolchain-target-settings branch from 691a089 to 80eac09 Compare April 23, 2026 22:30
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.

feature: avoid a fallback to the default-registered toolchains when using config_settings

1 participant