Skip to content

Commit 0711d66

Browse files
committed
feat: add universal2 support
1 parent 1613767 commit 0711d66

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
- os: windows-2016
4444
arch: "x86"
4545
- os: macos-10.15
46-
arch: "x86_64"
46+
arch: "universal2"
4747

4848
steps:
4949
- uses: actions/checkout@v2

noxfile.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
# -*- coding: utf-8 -*-
22
import argparse
3+
import sys
34
from pathlib import Path
45

56
import nox
67

78
nox.options.sessions = ["lint", "build", "tests"]
89

9-
BUILD_ENV = {
10-
"MACOSX_DEPLOYMENT_TARGET": "10.9",
11-
}
12-
10+
if sys.platform.startswith("darwin"):
11+
BUILD_ENV = {
12+
"MACOSX_DEPLOYMENT_TARGET": "10.9",
13+
"CMAKE_OSX_ARCHITECTURES": "arm64;x86_64",
14+
"CFLAGS": "-save-temps",
15+
"CXXFLAGS": "-save-temps",
16+
}
17+
else:
18+
BUILD_ENV = {}
1319

1420
built = ""
1521

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ manylinux-i686-image = "manylinux1"
1919

2020
[tool.cibuildwheel.macos.environment]
2121
MACOSX_DEPLOYMENT_TARGET = "10.9"
22+
CMAKE_OSX_ARCHITECTURES = "arm64;x86_64"
2223

2324
[tool.cibuildwheel.windows]
2425
before-all = [

scripts/repair_wheel.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def main():
4343
subprocess.run(["auditwheel", "repair", "-w", str(tmpdir), str(file)], check=True, stdout=subprocess.PIPE)
4444
elif os_ == "macos":
4545
subprocess.run(
46-
["delocate-wheel", "--require-archs", "x86_64", "-w", str(tmpdir), str(file)],
46+
["delocate-wheel", "--require-archs", "x86_64,arm64", "-w", str(tmpdir), str(file)],
4747
check=True,
4848
stdout=subprocess.PIPE,
4949
)
@@ -54,11 +54,34 @@ def main():
5454
assert len(files) == 1, files
5555
file = files[0]
5656

57+
# we need to handle macOS universal2 & arm64 here for now, let's use additional_platforms for this.
58+
additional_platforms = []
59+
if os_ == "macos":
60+
# first, get the target macOS deployment target from the wheel
61+
match = re.match(r"^.*-macosx_(\d+)_(\d+)_x86_64\.whl$", file.name)
62+
assert match is not None
63+
target = tuple(map(int, match.groups()))
64+
65+
# let's add universal2 platform for this wheel.
66+
additional_platforms = ["macosx_{}_{}_universal2".format(*target)]
67+
68+
# given pip support for universal2 was added after arm64 introduction
69+
# let's also add arm64 platform.
70+
arm64_target = target
71+
if arm64_target < (11, 0):
72+
arm64_target = (11, 0)
73+
additional_platforms.append("macosx_{}_{}_arm64".format(*arm64_target))
74+
75+
if target < (11, 0):
76+
# They're were also issues with pip not picking up some universal2 wheels, tag twice
77+
additional_platforms.append("macosx_11_0_universal2")
78+
5779
# make this a py2.py3 wheel
5880
convert_to_generic_platform_wheel(
5981
str(file),
6082
out_dir=str(wheelhouse),
6183
py2_py3=True,
84+
additional_platforms=additional_platforms,
6285
)
6386

6487

0 commit comments

Comments
 (0)