Skip to content

fix(interpreter): drop exec_compatible_with from Python interpreter toolchain#924

Merged
gregmagolan merged 1 commit into
mainfrom
fix_crossbuild_interpreter_toolchain
Apr 6, 2026
Merged

fix(interpreter): drop exec_compatible_with from Python interpreter toolchain#924
gregmagolan merged 1 commit into
mainfrom
fix_crossbuild_interpreter_toolchain

Conversation

@gregmagolan
Copy link
Copy Markdown
Member

@gregmagolan gregmagolan commented Apr 6, 2026

Problem

The BCR presubmit fails on Bazel 9 for //cases/uv-deps-650/crossbuild:crossbuild_compile_pyc_test:

While resolving toolchains for target //cases/uv-deps-650/crossbuild:app_bin:
No matching toolchains found for types:
  @@bazel_tools//tools/python:toolchain_type

The toolchain resolution debug log shows why — when evaluating app_bin for an arm64 target on an x86_64 exec host, the arm64 Python interpreter toolchain is rejected with:

Rejected toolchain python_3_12_aarch64_unknown_linux_gnu; mismatching values: aarch64

This is Bazel 9 enforcing exec_compatible_with strictly. The aarch64 Python interpreter was registered with exec_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:

toolchain(
    name = "python_3_12_aarch64_unknown_linux_gnu",
    exec_compatible_with = ["@platforms//os:linux", "@platforms//cpu:aarch64"],  # WRONG
    target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:aarch64"],
    ...
    toolchain_type = "@bazel_tools//tools/python:toolchain_type",
)

Setting exec_compatible_with on a @bazel_tools//tools/python:toolchain_type toolchain 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. compileall in whl_install). That toolchain correctly uses exec_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_with from the @bazel_tools//tools/python:toolchain_type registration. target_compatible_with alone is sufficient to select the right interpreter for the target platform.

Test plan

  • All e2e tests continue to pass (native builds unaffected — target constraint still selects the right interpreter)
  • //cases/uv-deps-650/crossbuild:crossbuild_compile_pyc_test still passes (whl_install exec interpreter still resolved via exec_tools_toolchain_type)

…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>
@gregmagolan gregmagolan marked this pull request as draft April 6, 2026 18:29
@aspect-workflows
Copy link
Copy Markdown

aspect-workflows Bot commented Apr 6, 2026

Bazel 8 (Test)

All tests were cache hits

112 tests (100.0%) were fully cached saving 56s.


Bazel 9 (Test)

All tests were cache hits

112 tests (100.0%) were fully cached saving 60s.


Bazel 8 (Test)

e2e

Buildkite build #3121 is running...


Bazel 9 (Test)

e2e

Buildkite build #3121 is running...


Bazel 8 (Test)

examples/uv_pip_compile

All tests were cache hits

1 test (100.0%) was fully cached saving 444ms.

@gregmagolan gregmagolan force-pushed the fix_crossbuild_interpreter_toolchain branch from 43cab1c to b96d0d0 Compare April 6, 2026 19:46
@gregmagolan gregmagolan marked this pull request as ready for review April 6, 2026 19:47
@gregmagolan gregmagolan requested a review from kormide April 6, 2026 19:48
@gregmagolan gregmagolan merged commit 08e6f3c into main Apr 6, 2026
6 checks passed
@gregmagolan gregmagolan deleted the fix_crossbuild_interpreter_toolchain branch April 6, 2026 19:50
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.

2 participants