Skip to content

Commit 9c1463a

Browse files
authored
feat: add universal2 support (#63)
1 parent f803c5f commit 9c1463a

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

.github/workflows/build.yml

+1-1
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

+10-4
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

+1
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

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22
import argparse
3+
import re
34
import shutil
45
import subprocess
56
import sys
@@ -43,7 +44,7 @@ def main():
4344
subprocess.run(["auditwheel", "repair", "-w", str(tmpdir), str(file)], check=True, stdout=subprocess.PIPE)
4445
elif os_ == "macos":
4546
subprocess.run(
46-
["delocate-wheel", "--require-archs", "x86_64", "-w", str(tmpdir), str(file)],
47+
["delocate-wheel", "--require-archs", "x86_64,arm64", "-w", str(tmpdir), str(file)],
4748
check=True,
4849
stdout=subprocess.PIPE,
4950
)
@@ -54,11 +55,34 @@ def main():
5455
assert len(files) == 1, files
5556
file = files[0]
5657

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

6488

0 commit comments

Comments
 (0)