From b96d0d0bfd0654792ffe707949b019cdc0c6a05e Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Mon, 6 Apr 2026 11:26:55 -0700 Subject: [PATCH] fix(interpreter): drop exec_compatible_with from Python interpreter toolchain 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 --- py/private/interpreter/repository.bzl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/py/private/interpreter/repository.bzl b/py/private/interpreter/repository.bzl index f070cd51b..60d89f311 100644 --- a/py/private/interpreter/repository.bzl +++ b/py/private/interpreter/repository.bzl @@ -309,9 +309,15 @@ config_setting( exec_compatible_with = info["compatible_with"] + extra_exec_compatible content.append(""" +# The Python interpreter toolchain has no exec_compatible_with: the interpreter +# runs on the TARGET platform (inside the virtualenv), not on the exec host. +# Setting exec_compatible_with = platform_constraints would prevent this +# toolchain from being selected during cross-compilation (e.g. building an +# arm64 image on an amd64 host), because the exec platform (amd64) would not +# satisfy the arm64 exec constraint. The target_compatible_with constraint is +# sufficient to pick the right interpreter for the target. toolchain( name = "{name}", - exec_compatible_with = {exec_compatible_with}, target_compatible_with = {target_compatible_with}, target_settings = {target_settings}, toolchain = "@{repo}//:runtime_pair", @@ -323,7 +329,7 @@ toolchain( # binary on the build host regardless of the target platform being built for. toolchain( name = "{name}_exec_tools", - exec_compatible_with = {target_compatible_with}, + exec_compatible_with = {exec_compatible_with}, toolchain = "@{repo}//:exec_tools_toolchain", toolchain_type = "@aspect_rules_py//py/private/toolchain:exec_tools_toolchain_type", )