Skip to content

Commit

Permalink
fix: filter-out unsupported PyPy cross-compilation configs
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeut committed Jan 8, 2023
1 parent dd4ae8d commit 008e3dd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Expand Up @@ -73,7 +73,6 @@ jobs:
output-dir: wheelhouse
env:
CIBW_ARCHS_MACOS: x86_64 universal2 arm64
CIBW_SKIP: pp*-macosx_arm64

- uses: actions/upload-artifact@v3
with:
Expand Down
17 changes: 17 additions & 0 deletions cibuildwheel/macos.py
Expand Up @@ -83,6 +83,23 @@ def get_python_configurations(
if any(c.identifier.endswith(a.value) for a in architectures)
]

# filter-out some cross-compilation configs with PyPy:
# can't build arm64 on x86_64
# rosetta allows to build x86_64 on arm64
pypy_architectures = (
architectures
& {
"arm64": {Architecture.arm64, Architecture.x86_64},
"x86_64": {Architecture.x86_64},
}[platform.machine()]
)
python_configurations = [
c
for c in python_configurations
if (not c.identifier.startswith("pp"))
or any(c.identifier.endswith(a.value) for a in pypy_architectures)
]

# skip builds as required by BUILD/SKIP
return [c for c in python_configurations if build_selector(c.identifier)]

Expand Down
18 changes: 14 additions & 4 deletions test/test_macos_archs.py
Expand Up @@ -65,7 +65,7 @@ def test_cross_compiled_test(tmp_path, capfd, build_universal2):
actual_wheels = utils.cibuildwheel_run(
project_dir,
add_env={
"CIBW_BUILD": "cp39-*",
"CIBW_BUILD": "cp39-*" if build_universal2 else "*p39-*",
"CIBW_TEST_COMMAND": '''python -c "import platform; print('running tests on ' + platform.machine())"''',
"CIBW_ARCHS": "universal2" if build_universal2 else "x86_64 arm64",
"CIBW_BUILD_VERBOSITY": "3",
Expand All @@ -76,7 +76,8 @@ def test_cross_compiled_test(tmp_path, capfd, build_universal2):

assert DEPLOYMENT_TARGET_TOO_LOW_WARNING not in captured.err

if platform.machine() == "x86_64":
platform_machine = platform.machine()
if platform_machine == "x86_64":
# ensure that tests were run on only x86_64
assert "running tests on x86_64" in captured.out
assert "running tests on arm64" not in captured.out
Expand All @@ -89,15 +90,24 @@ def test_cross_compiled_test(tmp_path, capfd, build_universal2):
assert (
"While arm64 wheels can be built on x86_64, they cannot be tested" in captured.err
)
elif platform.machine() == "arm64":
elif platform_machine == "arm64":
# ensure that tests were run on both x86_64 and arm64
assert "running tests on x86_64" in captured.out
assert "running tests on arm64" in captured.out
assert (
"While universal2 wheels can be built on x86_64, the arm64 part of them cannot currently be tested"
not in captured.err
)
assert (
"While arm64 wheels can be built on x86_64, they cannot be tested" not in captured.err
)

if build_universal2:
expected_wheels = [w for w in ALL_MACOS_WHEELS if "cp39" in w and "universal2" in w]
else:
expected_wheels = [w for w in ALL_MACOS_WHEELS if "cp39" in w and "universal2" not in w]
expected_wheels = [w for w in ALL_MACOS_WHEELS if "p39-" in w and "universal2" not in w]
if platform_machine == "x86_64":
expected_wheels = [w for w in expected_wheels if not ("pp39" in w and "arm64" in w)]

assert set(actual_wheels) == set(expected_wheels)

Expand Down

0 comments on commit 008e3dd

Please sign in to comment.