Skip to content

Commit

Permalink
feat: add universal2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeut committed Jul 18, 2021
1 parent 1613767 commit 3574512
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- os: windows-2016
arch: "x86"
- os: macos-10.15
arch: "x86_64"
arch: "universal2"

steps:
- uses: actions/checkout@v2
Expand Down
14 changes: 10 additions & 4 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -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 = ""

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
26 changes: 25 additions & 1 deletion scripts/repair_wheel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import argparse
import re
import shutil
import subprocess
import sys
Expand Down Expand Up @@ -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,
)
Expand All @@ -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,
)


Expand Down

0 comments on commit 3574512

Please sign in to comment.