Skip to content

feat(pex): use exec interpreter for PEX builds, enabling cross-builds#880

Merged
arrdem merged 2 commits intomainfrom
arrdem/pex-cross-build-618
Mar 20, 2026
Merged

feat(pex): use exec interpreter for PEX builds, enabling cross-builds#880
arrdem merged 2 commits intomainfrom
arrdem/pex-cross-build-618

Conversation

@arrdem
Copy link
Collaborator

@arrdem arrdem commented Mar 20, 2026

Stacked on #881 — merge that first.

Takes over #618. The PEX builder previously required a target-configured Python interpreter, which fails in cross-arch builds since the target interpreter isn't runnable on the build host.

The fix removes the --python argument entirely — PEXBuilder(interpreter=None) works because rules_py already controls dependency resolution hermetically; PEX doesn't need to probe the interpreter for platform compatibility.

Also adds cross-arch build_test targets validating PEX builds for both linux_arm64 and linux_amd64 via platform_transition_filegroup.

Closes #618.

Changes are visible to end-users: yes

  • Searched for relevant documentation and updated as needed: no
  • Breaking change (forces users to change their own code or config): no
  • Suggested release notes appear below: yes

py_pex_binary now supports cross-architecture builds (e.g. building an arm64 PEX on an x86 host).

Test plan

  • New cross-arch build_test targets added
  • Existing py-pex-binary e2e tests pass

🤖 Generated with Claude Code

@aspect-workflows
Copy link

aspect-workflows bot commented Mar 20, 2026

Bazel 8 (Test)

All tests were cache hits

107 tests (100.0%) were fully cached saving 47s.


Bazel 9 (Test)

All tests were cache hits

107 tests (100.0%) were fully cached saving 1m 16s.


Bazel 8 (Test)

e2e

All tests were cache hits

41 tests (100.0%) were fully cached saving 33s.


Bazel 9 (Test)

e2e

All tests were cache hits

41 tests (100.0%) were fully cached saving 40s.


Bazel 8 (Test)

examples/uv_pip_compile

All tests were cache hits

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

@arrdem arrdem force-pushed the arrdem/pex-cross-build-618 branch from c9bedf3 to 4d47d05 Compare March 20, 2026 07:32
whl_install's compile_pyc uses `py_toolchain.interpreter` which is
resolved in target configuration. In cross-arch builds, the target
interpreter is not runnable on the build host.

Add a `resolved_py_toolchain` rule (analogous to `resolved_unpack_toolchain`)
that re-exports the Python toolchain, and reference it via `cfg="exec"` so
compileall gets a host-runnable interpreter. This is safe because .pyc
bytecode depends on Python version, not architecture.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…#618)

The PEX builder was being passed the target platform's interpreter, which
fails in cross-builds (e.g. building a Linux PEX on macOS) with "Exec
format error". Since rules_py already controls dependency resolution
hermetically, the PEX builder doesn't need the target interpreter — it
just needs to run on the build host.

Remove the --python flag from py_pex_binary and let PEXBuilder use the
current (cfg=exec) interpreter instead.

Based on the work by Peter Lobsinger in #618.

Co-Authored-By: Peter Lobsinger <peter@tecton.ai>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@arrdem arrdem force-pushed the arrdem/pex-cross-build-618 branch from 5820ab8 to e4b49b5 Compare March 20, 2026 07:38
@arrdem arrdem changed the base branch from main to arrdem/whl-install-exec-python-compileall March 20, 2026 07:38
arrdem added a commit that referenced this pull request Mar 20, 2026
…#881)

When `compile_pyc` is enabled, `whl_install` invokes `compileall` using
`py_toolchain.interpreter` which is resolved in **target**
configuration. In cross-arch builds (e.g. x86 host building for arm64),
the target interpreter isn't runnable on the build host, causing the
action to fail.

This adds a `resolved_py_toolchain` rule (following the existing
`resolved_unpack_toolchain` pattern) and references it via `cfg="exec"`
so compileall gets a host-runnable interpreter. This is safe because
`.pyc` bytecode depends on Python version, not architecture.

### Changes are visible to end-users: no

### Test plan

- Covered by existing test cases
- Cross-arch scenario validated in #880

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Base automatically changed from arrdem/whl-install-exec-python-compileall to main March 20, 2026 07:44
@arrdem arrdem merged commit 7909bc1 into main Mar 20, 2026
4 checks passed
@arrdem arrdem deleted the arrdem/pex-cross-build-618 branch March 20, 2026 07:45
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.

1 participant