Skip to content

Commit 92cb1d8

Browse files
mayeuthenryiiijoerick
authored
feat: add PyPy macOS arm64 (#1372)
* feat: add PyPy macOS arm64 * fix: use PyPy 7.3.11 * fix: filter-out unsupported PyPy cross-compilation configs * Add quiet notice about the auto-skipping of arm64 pp builds on x86_64 Signed-off-by: Henry Schreiner <[email protected]> Co-authored-by: Henry Schreiner <[email protected]> Co-authored-by: Joe Rickerby <[email protected]>
1 parent 06c4927 commit 92cb1d8

File tree

8 files changed

+70
-16
lines changed

8 files changed

+70
-16
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ What does it do?
3232
| CPython 3.10 ||||| ✅² ||||||
3333
| CPython 3.11 ||||| ✅² ||||||
3434
| PyPy 3.7 v7.3 || N/A || N/A | N/A | ✅¹ | ✅¹ | ✅¹ | N/A | N/A |
35-
| PyPy 3.8 v7.3 || N/A || N/A | N/A | ✅¹ | ✅¹ | ✅¹ | N/A | N/A |
36-
| PyPy 3.9 v7.3 || N/A || N/A | N/A | ✅¹ | ✅¹ | ✅¹ | N/A | N/A |
35+
| PyPy 3.8 v7.3 || ✅⁴ || N/A | N/A | ✅¹ | ✅¹ | ✅¹ | N/A | N/A |
36+
| PyPy 3.9 v7.3 || ✅⁴ || N/A | N/A | ✅¹ | ✅¹ | ✅¹ | N/A | N/A |
3737

3838
<sup>¹ PyPy is only supported for manylinux wheels.</sup><br>
3939
<sup>² Windows arm64 support is experimental.</sup><br>
4040
<sup>³ Alpine 3.14 and very briefly 3.15's default python3 [was not able to load](https://github.com/pypa/cibuildwheel/issues/934) musllinux wheels. This has been fixed; please upgrade the python package if using Alpine from before the fix.</sup><br>
41+
<sup>⁴ Cross-compilation not supported with PyPy - to build these wheels you need to run cibuildwheel on an Apple Silicon machine.</sup><br>
4142

4243
- Builds manylinux, musllinux, macOS 10.9+, and Windows wheels for CPython and PyPy
4344
- Works on GitHub Actions, Azure Pipelines, Travis CI, AppVeyor, CircleCI, GitLab CI, and Cirrus CI

bin/update_pythons.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ def update_version_windows(self, spec: Specifier) -> ConfigWinCP:
159159
)
160160

161161
def update_version_macos(self, spec: Specifier) -> ConfigMacOS:
162-
if self.arch != "64":
163-
msg = "Other archs not supported yet on macOS"
162+
if self.arch not in {"64", "ARM64"}:
163+
msg = f"'{self.arch}' arch not supported yet on macOS"
164164
raise RuntimeError(msg)
165165

166166
releases = [r for r in self.releases if spec.contains(r["python_version"])]
@@ -172,12 +172,14 @@ def update_version_macos(self, spec: Specifier) -> ConfigMacOS:
172172

173173
release = releases[-1]
174174
version = release["python_version"]
175-
identifier = f"pp{version.major}{version.minor}-macosx_x86_64"
175+
arch = "x86_64" if self.arch == "64" else self.arch.lower()
176+
identifier = f"pp{version.major}{version.minor}-macosx_{arch}"
176177

178+
arch = "x64" if self.arch == "64" else self.arch.lower()
177179
(url,) = (
178180
rf["download_url"]
179181
for rf in release["files"]
180-
if "" in rf["platform"] == "darwin" and rf["arch"] == "x64"
182+
if "" in rf["platform"] == "darwin" and rf["arch"] == arch
181183
)
182184

183185
return ConfigMacOS(
@@ -251,6 +253,7 @@ def __init__(self) -> None:
251253

252254
self.macos_cpython = CPythonVersions()
253255
self.macos_pypy = PyPyVersions("64")
256+
self.macos_pypy_arm64 = PyPyVersions("ARM64")
254257

255258
def update_config(self, config: dict[str, str]) -> None:
256259
identifier = config["identifier"]
@@ -261,11 +264,14 @@ def update_config(self, config: dict[str, str]) -> None:
261264
config_update: AnyConfig | None = None
262265

263266
# We need to use ** in update due to MyPy (probably a bug)
264-
if "macos" in identifier:
267+
if "macosx" in identifier:
265268
if identifier.startswith("cp"):
266269
config_update = self.macos_cpython.update_version_macos(identifier, version, spec)
267270
elif identifier.startswith("pp"):
268-
config_update = self.macos_pypy.update_version_macos(spec)
271+
if "macosx_x86_64" in identifier:
272+
config_update = self.macos_pypy.update_version_macos(spec)
273+
elif "macosx_arm64" in identifier:
274+
config_update = self.macos_pypy_arm64.update_version_macos(spec)
269275
elif "win32" in identifier:
270276
if identifier.startswith("cp"):
271277
config_update = self.windows_32.update_version_windows(spec)

cibuildwheel/logger.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ def step_end_with_error(self, error: BaseException | str) -> None:
126126
self.step_end(success=False)
127127
self.error(error)
128128

129+
def quiet(self, message: str) -> None:
130+
c = self.colors
131+
print(f"{c.gray}{message}{c.end}", file=sys.stderr)
132+
129133
def notice(self, message: str) -> None:
130134
if self.fold_mode == "github":
131135
print(f"::notice::{message}\n", file=sys.stderr)

cibuildwheel/macos.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,31 @@ def get_python_configurations(
8484
]
8585

8686
# skip builds as required by BUILD/SKIP
87-
return [c for c in python_configurations if build_selector(c.identifier)]
87+
python_configurations = [c for c in python_configurations if build_selector(c.identifier)]
88+
89+
# filter-out some cross-compilation configs with PyPy:
90+
# can't build arm64 on x86_64
91+
# rosetta allows to build x86_64 on arm64
92+
if platform.machine() == "x86_64":
93+
python_configurations_before = set(python_configurations)
94+
python_configurations = [
95+
c
96+
for c in python_configurations
97+
if not (c.identifier.startswith("pp") and c.identifier.endswith("arm64"))
98+
]
99+
removed_elements = python_configurations_before - set(python_configurations)
100+
if removed_elements:
101+
ids = ", ".join(c.identifier for c in removed_elements)
102+
log.quiet(
103+
unwrap(
104+
f"""
105+
Note: {ids} {'was' if len(removed_elements) == 1 else 'were'}
106+
selected, but can't be built on x86_64 so will be skipped automatically.
107+
"""
108+
)
109+
)
110+
111+
return python_configurations
88112

89113

90114
def install_cpython(tmp: Path, version: str, url: str) -> Path:

cibuildwheel/resources/build-platforms.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ python_configurations = [
8989
{ identifier = "cp311-macosx_universal2", version = "3.11", url = "https://www.python.org/ftp/python/3.11.1/python-3.11.1-macos11.pkg" },
9090
{ identifier = "pp37-macosx_x86_64", version = "3.7", url = "https://downloads.python.org/pypy/pypy3.7-v7.3.9-osx64.tar.bz2" },
9191
{ identifier = "pp38-macosx_x86_64", version = "3.8", url = "https://downloads.python.org/pypy/pypy3.8-v7.3.11-macos_x86_64.tar.bz2" },
92+
{ identifier = "pp38-macosx_arm64", version = "3.8", url = "https://downloads.python.org/pypy/pypy3.8-v7.3.11-macos_arm64.tar.bz2" },
9293
{ identifier = "pp39-macosx_x86_64", version = "3.9", url = "https://downloads.python.org/pypy/pypy3.9-v7.3.11-macos_x86_64.tar.bz2" },
94+
{ identifier = "pp39-macosx_arm64", version = "3.9", url = "https://downloads.python.org/pypy/pypy3.9-v7.3.11-macos_arm64.tar.bz2" },
9395
]
9496

9597
[windows]

docs/options.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ When setting the options, you can use shell-style globbing syntax, as per [fnmat
227227
| Python 3.10 | cp310-macosx_x86_64<br/>cp310-macosx_universal2<br/>cp310-macosx_arm64 | cp310-win_amd64<br/>cp310-win32<br/>cp310-win_arm64 | cp310-manylinux_x86_64<br/>cp310-manylinux_i686<br/>cp310-musllinux_x86_64<br/>cp310-musllinux_i686 | cp310-manylinux_aarch64<br/>cp310-manylinux_ppc64le<br/>cp310-manylinux_s390x<br/>cp310-musllinux_aarch64<br/>cp310-musllinux_ppc64le<br/>cp310-musllinux_s390x |
228228
| Python 3.11 | cp311-macosx_x86_64<br/>cp311-macosx_universal2<br/>cp311-macosx_arm64 | cp311-win_amd64<br/>cp311-win32<br/>cp311-win_arm64 | cp311-manylinux_x86_64<br/>cp311-manylinux_i686<br/>cp311-musllinux_x86_64<br/>cp311-musllinux_i686 | cp311-manylinux_aarch64<br/>cp311-manylinux_ppc64le<br/>cp311-manylinux_s390x<br/>cp311-musllinux_aarch64<br/>cp311-musllinux_ppc64le<br/>cp311-musllinux_s390x |
229229
| PyPy3.7 v7.3 | pp37-macosx_x86_64 | pp37-win_amd64 | pp37-manylinux_x86_64<br/>pp37-manylinux_i686 | pp37-manylinux_aarch64 |
230-
| PyPy3.8 v7.3 | pp38-macosx_x86_64 | pp38-win_amd64 | pp38-manylinux_x86_64<br/>pp38-manylinux_i686 | pp38-manylinux_aarch64 |
231-
| PyPy3.9 v7.3 | pp39-macosx_x86_64 | pp39-win_amd64 | pp39-manylinux_x86_64<br/>pp39-manylinux_i686 | pp39-manylinux_aarch64 |
230+
| PyPy3.8 v7.3 | pp38-macosx_x86_64<br/>pp38-macosx_arm64 | pp38-win_amd64 | pp38-manylinux_x86_64<br/>pp38-manylinux_i686 | pp38-manylinux_aarch64 |
231+
| PyPy3.9 v7.3 | pp39-macosx_x86_64<br/>pp39-macosx_arm64 | pp39-win_amd64 | pp39-manylinux_x86_64<br/>pp39-manylinux_i686 | pp39-manylinux_aarch64 |
232232

233233
The list of supported and currently selected build identifiers can also be retrieved by passing the `--print-build-identifiers` flag to cibuildwheel.
234234
The format is `python_tag-platform_tag`, with tags similar to those in [PEP 425](https://www.python.org/dev/peps/pep-0425/#details).

test/test_macos_archs.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def test_cross_compiled_test(tmp_path, capfd, build_universal2):
6565
actual_wheels = utils.cibuildwheel_run(
6666
project_dir,
6767
add_env={
68-
"CIBW_BUILD": "cp39-*",
68+
"CIBW_BUILD": "cp39-*" if build_universal2 else "*p39-*",
6969
"CIBW_TEST_COMMAND": '''python -c "import platform; print('running tests on ' + platform.machine())"''',
7070
"CIBW_ARCHS": "universal2" if build_universal2 else "x86_64 arm64",
7171
"CIBW_BUILD_VERBOSITY": "3",
@@ -76,7 +76,8 @@ def test_cross_compiled_test(tmp_path, capfd, build_universal2):
7676

7777
assert DEPLOYMENT_TARGET_TOO_LOW_WARNING not in captured.err
7878

79-
if platform.machine() == "x86_64":
79+
platform_machine = platform.machine()
80+
if platform_machine == "x86_64":
8081
# ensure that tests were run on only x86_64
8182
assert "running tests on x86_64" in captured.out
8283
assert "running tests on arm64" not in captured.out
@@ -89,15 +90,24 @@ def test_cross_compiled_test(tmp_path, capfd, build_universal2):
8990
assert (
9091
"While arm64 wheels can be built on x86_64, they cannot be tested" in captured.err
9192
)
92-
elif platform.machine() == "arm64":
93+
elif platform_machine == "arm64":
9394
# ensure that tests were run on both x86_64 and arm64
9495
assert "running tests on x86_64" in captured.out
9596
assert "running tests on arm64" in captured.out
97+
assert (
98+
"While universal2 wheels can be built on x86_64, the arm64 part of them cannot currently be tested"
99+
not in captured.err
100+
)
101+
assert (
102+
"While arm64 wheels can be built on x86_64, they cannot be tested" not in captured.err
103+
)
96104

97105
if build_universal2:
98106
expected_wheels = [w for w in ALL_MACOS_WHEELS if "cp39" in w and "universal2" in w]
99107
else:
100-
expected_wheels = [w for w in ALL_MACOS_WHEELS if "cp39" in w and "universal2" not in w]
108+
expected_wheels = [w for w in ALL_MACOS_WHEELS if "p39-" in w and "universal2" not in w]
109+
if platform_machine == "x86_64":
110+
expected_wheels = [w for w in expected_wheels if not ("pp39" in w and "arm64" in w)]
101111

102112
assert set(actual_wheels) == set(expected_wheels)
103113

test/utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,14 @@ def expected_wheels(
177177

178178
if platform == "macos" and machine_arch == "arm64":
179179
# arm64 macs are only supported by cp38+
180-
python_abi_tags = ["cp38-cp38", "cp39-cp39", "cp310-cp310", "cp311-cp311"]
180+
python_abi_tags = [
181+
"cp38-cp38",
182+
"cp39-cp39",
183+
"cp310-cp310",
184+
"cp311-cp311",
185+
"pp38-pypy38_pp73",
186+
"pp39-pypy39_pp73",
187+
]
181188

182189
wheels = []
183190

0 commit comments

Comments
 (0)