Skip to content

A custom platform name in single_version_platform_override breaks the @python_X_Y_Z aliases #4472

Open

Description

@vadikmironov

🐞 bug report

Affected Rule

The issue is caused by the rule: the python bzlmod extension, when python.single_version_platform_override registers a runtime under a custom platform name. The failure is in the alias repos it generates (@python_X_Y, @python_X_Y_Z), in python/private/toolchain_aliases.bzl.

Is this a regression?

No. It is already present in 1.5.0, the release that added custom platform names (#2880). I also see it in 2.4.6 and on main at 062a81c.

Description

single_version_platform_override can register a runtime under a custom platform name and gate it with target_settings, as the "Registering custom runtimes" docs describe. Once a Python version has such a runtime, every alias target of that version (@python_3_14_4//:python_headers, :files, :python3, and so on) fails to analyze. It fails with the flag set and without it.

toolchain_aliases() builds the select() of each alias from all the platform names of the version, but it creates config settings only for the names in PLATFORMS (python/versions.bzl). The custom name ends up as a select() key with no config setting behind it.

🔬 Minimal Reproduction

https://github.com/vadikmironov/rules_python-custom-platform-alias-repro

bazel build //:python_headers

//:python_headers is an alias of @python_3_14_4//:python_headers. The relevant part of MODULE.bazel:

python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(python_version = "3.14.4")
python.single_version_platform_override(
    platform = "linux-x86-stripped",
    python_version = "3.14.4",
    sha256 = "fe9a9c32d13870af632cbac3dfc7528ae53597e94472aa4c7d6a42e8166136cd",
    target_compatible_with = [
        "@platforms//os:linux",
        "@platforms//cpu:x86_64",
    ],
    target_settings = ["@@//:is_stripped_runtime"],
    urls = ["https://github.com/astral-sh/python-build-standalone/releases/download/20260414/cpython-3.14.4+20260414-x86_64-unknown-linux-gnu-install_only_stripped.tar.gz"],
)
use_repo(python, "python_3_14_4")

The build completes when the single_version_platform_override call is removed.

🔥 Exception or Error


ERROR: .../external/rules_python++python+python_3_14_4/BUILD.bazel:32:18: @@rules_python++python+python_3_14_4//:linux-x86-stripped is not a valid select() condition for @@rules_python++python+python_3_14_4//:python_headers.
ERROR: Analysis of target '//:python_headers' failed; build aborted: Analysis failed

🌍 Your Environment

Operating System:

  
Debian 13 (trixie) on WSL2, x86_64
  

Output of bazel version:

  
Bazelisk version: v1.29.0
Build label: 9.3.2
  

Rules_python version:

  
2.4.6. Also main at 062a81c4, and 1.5.0 (with Python 3.13.3, Bazel 9.3.2 and 8.4.2).
  

Anything else relevant?

I ran into this while writing the test for #4471. The existing //tests/toolchains:custom_platform_toolchain_test does not hit it, because its custom platform is on 3.13.1 and nothing builds @python_3_13_1//.... With a custom platform on the newest 3.14, //tests/toolchains:build_test fails, because it builds @python_3_14//:python_headers.

Limiting the select() to the names that have a config setting makes the repro build. But then, with the flag set, the alias points at the regular runtime and not at the custom one.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions