Skip to content
Merged
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
21 changes: 19 additions & 2 deletions cpython-unix/build-main.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def main():
"--no-docker",
action="store_true",
default=True if sys.platform == "darwin" else False,
help="Disable building in Docker",
help="Disable building in Docker on Linux hosts.",
)
parser.add_argument(
"--serial",
Expand Down Expand Up @@ -129,9 +129,26 @@ def main():

musl = "musl" in target_triple

# Linux targets can be built on a macOS host using Docker.
building_linux_from_macos = sys.platform == "darwin" and "linux" in target_triple
if building_linux_from_macos:
print("Note: Using Docker to build for Linux on macOS")
args.no_docker = False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels a little dubious as an implementation. I'd expect us not to mutate args and I'd expect --no-docker to cause a failure in this case?


env = dict(os.environ)

env["PYBUILD_HOST_PLATFORM"] = host_platform
# When building Linux targets from macOS using Docker, map to the equivalent
# Linux host platform.
effective_host_platform = host_platform
if building_linux_from_macos:
if host_platform == "macos_arm64":
effective_host_platform = "linux_aarch64"
else:
raise Exception(f"Unhandled macOS platform: {host_platform}")
print(
f"Building Linux target from macOS using Docker ({effective_host_platform} toolchain)"
)
env["PYBUILD_HOST_PLATFORM"] = effective_host_platform
env["PYBUILD_TARGET_TRIPLE"] = target_triple
env["PYBUILD_BUILD_OPTIONS"] = args.options
env["PYBUILD_PYTHON_SOURCE"] = python_source
Expand Down
3 changes: 2 additions & 1 deletion cpython-unix/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def add_target_env(env, build_platform, target_triple, build_env, build_options)
if build_platform.startswith("linux_"):
machine = platform.machine()

if machine == "aarch64":
# arm64 allows building for Linux on a macOS host using Docker
if machine == "aarch64" or machine == "arm64":
env["BUILD_TRIPLE"] = "aarch64-unknown-linux-gnu"
env["TARGET_TRIPLE"] = target_triple
elif machine == "x86_64":
Expand Down
2 changes: 2 additions & 0 deletions cpython-unix/targets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ aarch64-unknown-linux-gnu:
host_platforms:
- linux_x86_64
- linux_aarch64
- macos_arm64
pythons_supported:
- '3.10'
- '3.11'
Expand Down Expand Up @@ -919,6 +920,7 @@ aarch64-unknown-linux-musl:
host_platforms:
- linux_x86_64
- linux_aarch64
- macos_arm64
pythons_supported:
- '3.10'
- '3.11'
Expand Down
5 changes: 5 additions & 0 deletions docs/building.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ As are various other targets::
$ ./build-linux.py --target riscv64-unknown-linux-gnu
$ ./build-linux.py --target s390x-unknown-linux-gnu

Additionally, an arm64 macOS host can be used to build Linux aarch64 targets
using Docker::

$ ./build-linux.py --target aarch64-unknown-linux-gnu

macOS
=====

Expand Down