Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion py/private/py_pex_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
42 changes: 42 additions & 0 deletions py/tests/py-pex-binary/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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",
],
)
13 changes: 4 additions & 9 deletions py/tools/pex/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
)


Expand Down
Loading