diff --git a/py/private/py_pex_binary.bzl b/py/private/py_pex_binary.bzl index 9ee01fee..5721274c 100644 --- a/py/private/py_pex_binary.bzl +++ b/py/private/py_pex_binary.bzl @@ -101,7 +101,6 @@ def _py_python_pex_impl(ctx): ) args.add(binary[DefaultInfo].files_to_run.executable, format = "--executable=%s") args.add(ctx.attr.python_shebang, format = "--python-shebang=%s") - args.add(py_toolchain.python, format = "--python=%s") py_version = py_toolchain.interpreter_version_info args.add_all( diff --git a/py/tests/py-pex-binary/BUILD.bazel b/py/tests/py-pex-binary/BUILD.bazel index 3107a127..780d2c19 100644 --- a/py/tests/py-pex-binary/BUILD.bazel +++ b/py/tests/py-pex-binary/BUILD.bazel @@ -1,4 +1,6 @@ load("@aspect_bazel_lib//lib:testing.bzl", "assert_contains") +load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_binary") +load("@bazel_skylib//rules:build_test.bzl", "build_test") load("//py:defs.bzl", "py_binary", "py_pex_binary") # Test that both single-file modules (six) and multi-file modules (cowsay) work with py_pex_binary. @@ -32,3 +34,43 @@ assert_contains( actual = "print_modules_pex.out", expected = "Mooo!,cowsay-6.1/cowsay/__init__.py,six-1.16.0/six.py", ) + +# Cross-compilation to Linux can work. +# TODO(https://github.com/aspect-build/rules_py/issues/625): support arbitrary cross-compilation. + +# At least one of these platforms is a cross-compile, no matter where we run. +platform( + name = "arm64_linux", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:aarch64", + ], +) + +platform( + name = "amd64_linux", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ], +) + +platform_transition_binary( + name = "print_modules_pex_arm64_linux", + binary = ":print_modules_pex", + target_platform = ":arm64_linux", +) + +platform_transition_binary( + name = "print_modules_pex_amd64_linux", + binary = ":print_modules_pex", + target_platform = ":amd64_linux", +) + +build_test( + name = "cross_builds", + targets = [ + ":print_modules_pex_arm64_linux", + ":print_modules_pex_amd64_linux", + ], +) diff --git a/py/tools/pex/main.py b/py/tools/pex/main.py index 5c699fd7..7a188495 100644 --- a/py/tools/pex/main.py +++ b/py/tools/pex/main.py @@ -9,7 +9,6 @@ import sys from pex.pex_builder import Check,PEXBuilder -from pex.interpreter import PythonInterpreter from pex.interpreter_constraints import InterpreterConstraint from pex.layout import Layout from pex.dist_metadata import Distribution @@ -37,13 +36,6 @@ def __call__(self, parser, namespace, value, option_str=None): "immediately and not save it to a file.", ) -parser.add_argument( - "--python", - dest="python", - required=True -) - - parser.add_argument( "--python-version-constraint", dest="constraints", @@ -128,7 +120,10 @@ def __call__(self, parser, namespace, value, option_str=None): pex_builder = PEXBuilder( - interpreter=PythonInterpreter.from_binary(options.python), + # Build the PEX artifact using the current interpreter; we know it works in cfg=exec + # because that's how we're already running. Interpreters inferred by other means might + # not work in cross-builds. + interpreter=None, )