From e2445c241f40cd7d74a8aaa2bac09bc04e55342f Mon Sep 17 00:00:00 2001 From: mayeut Date: Sun, 18 Jul 2021 16:26:10 +0200 Subject: [PATCH] feat: add universal2 support --- .github/workflows/build.yml | 2 +- noxfile.py | 14 ++++++++++---- pyproject.toml | 1 + scripts/repair_wheel.py | 26 +++++++++++++++++++++++++- 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7efbbea..a7800af 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -43,7 +43,7 @@ jobs: - os: windows-2016 arch: "x86" - os: macos-10.15 - arch: "x86_64" + arch: "universal2" steps: - uses: actions/checkout@v2 diff --git a/noxfile.py b/noxfile.py index a7c0587..e21080b 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,15 +1,21 @@ # -*- coding: utf-8 -*- import argparse +import sys from pathlib import Path import nox nox.options.sessions = ["lint", "build", "tests"] -BUILD_ENV = { - "MACOSX_DEPLOYMENT_TARGET": "10.9", -} - +if sys.platform.startswith("darwin"): + BUILD_ENV = { + "MACOSX_DEPLOYMENT_TARGET": "10.9", + "CMAKE_OSX_ARCHITECTURES": "arm64;x86_64", + "CFLAGS": "-save-temps", + "CXXFLAGS": "-save-temps", + } +else: + BUILD_ENV = {} built = "" diff --git a/pyproject.toml b/pyproject.toml index 2bda4f9..c15bd03 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,6 +19,7 @@ manylinux-i686-image = "manylinux1" [tool.cibuildwheel.macos.environment] MACOSX_DEPLOYMENT_TARGET = "10.9" +CMAKE_OSX_ARCHITECTURES = "arm64;x86_64" [tool.cibuildwheel.windows] before-all = [ diff --git a/scripts/repair_wheel.py b/scripts/repair_wheel.py index 11c3723..3513660 100644 --- a/scripts/repair_wheel.py +++ b/scripts/repair_wheel.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import argparse +import re import shutil import subprocess import sys @@ -43,7 +44,7 @@ def main(): subprocess.run(["auditwheel", "repair", "-w", str(tmpdir), str(file)], check=True, stdout=subprocess.PIPE) elif os_ == "macos": subprocess.run( - ["delocate-wheel", "--require-archs", "x86_64", "-w", str(tmpdir), str(file)], + ["delocate-wheel", "--require-archs", "x86_64,arm64", "-w", str(tmpdir), str(file)], check=True, stdout=subprocess.PIPE, ) @@ -54,11 +55,34 @@ def main(): assert len(files) == 1, files file = files[0] + # we need to handle macOS universal2 & arm64 here for now, let's use additional_platforms for this. + additional_platforms = [] + if os_ == "macos": + # first, get the target macOS deployment target from the wheel + match = re.match(r"^.*-macosx_(\d+)_(\d+)_x86_64\.whl$", file.name) + assert match is not None + target = tuple(map(int, match.groups())) + + # let's add universal2 platform for this wheel. + additional_platforms = ["macosx_{}_{}_universal2".format(*target)] + + # given pip support for universal2 was added after arm64 introduction + # let's also add arm64 platform. + arm64_target = target + if arm64_target < (11, 0): + arm64_target = (11, 0) + additional_platforms.append("macosx_{}_{}_arm64".format(*arm64_target)) + + if target < (11, 0): + # They're were also issues with pip not picking up some universal2 wheels, tag twice + additional_platforms.append("macosx_11_0_universal2") + # make this a py2.py3 wheel convert_to_generic_platform_wheel( str(file), out_dir=str(wheelhouse), py2_py3=True, + additional_platforms=additional_platforms, )