fix(interpreter): drop exec_compatible_with from Python interpreter toolchain#924
Merged
Merged
Conversation
…oolchain The `@bazel_tools//tools/python:toolchain_type` toolchain represents an interpreter that runs **on the target platform** (inside the virtualenv), not on the exec host. Setting `exec_compatible_with = platform_constraints` was incorrect and prevented cross-compilation: when building an arm64 image on an amd64 host, the arm64 interpreter toolchain was rejected because the exec platform (amd64) did not satisfy the arm64 exec constraint, leaving no matching toolchain for `@@bazel_tools//tools/python:toolchain_type`. `target_compatible_with` alone is sufficient to select the right interpreter for the target; exec constraints belong only on toolchains whose binaries run during the build (i.e. the separate `exec_tools_toolchain_type`). Fixes the BCR presubmit failure in `//cases/uv-deps-650/crossbuild:crossbuild_compile_pyc_test`. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
43cab1c to
b96d0d0
Compare
kormide
approved these changes
Apr 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Problem
The BCR presubmit fails on Bazel 9 for
//cases/uv-deps-650/crossbuild:crossbuild_compile_pyc_test:The toolchain resolution debug log shows why — when evaluating
app_binfor an arm64 target on an x86_64 exec host, the arm64 Python interpreter toolchain is rejected with:This is Bazel 9 enforcing
exec_compatible_withstrictly. The aarch64 Python interpreter was registered withexec_compatible_with = ["@platforms//cpu:aarch64", ...], which doesn't match the x86_64 exec platform. Bazel 8 ignored this mismatch; Bazel 9 enforces it.Root cause
Since the original python-build-standalone
(PBS) interpreter commit (
b2feee5), every Python interpreter toolchain has been registered with:Setting
exec_compatible_withon a@bazel_tools//tools/python:toolchain_typetoolchain is semantically wrong. The Python interpreter here is a runtime dependency — it ends up inside the virtualenv and runs on the target machine, not on the build host. The exec platform constraint is irrelevant and actively harmful during cross-compilation.This is distinct from
exec_tools_toolchain_type, which represents the interpreter that runs build actions (e.g.compileallinwhl_install). That toolchain correctly usesexec_compatible_with— it must run on the exec host, and #903 was specifically designed to handle this case properly. This fix does not touch that path.Fix
Remove
exec_compatible_withfrom the@bazel_tools//tools/python:toolchain_typeregistration.target_compatible_withalone is sufficient to select the right interpreter for the target platform.Test plan
//cases/uv-deps-650/crossbuild:crossbuild_compile_pyc_teststill passes (whl_install exec interpreter still resolved viaexec_tools_toolchain_type)