From 33c442a7be927a907033c033d737a4b37621000e Mon Sep 17 00:00:00 2001 From: mayeut Date: Sun, 8 Jan 2023 13:09:48 +0100 Subject: [PATCH] fix: filter-out unsupported PyPy cross-compilation configs --- .github/workflows/test.yml | 1 - cibuildwheel/macos.py | 17 +++++++++++++++++ test/test_macos_archs.py | 18 ++++++++++++++---- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c91baaa90..36ed2511b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: diff --git a/cibuildwheel/macos.py b/cibuildwheel/macos.py index 48239b9ec..17cf5354f 100644 --- a/cibuildwheel/macos.py +++ b/cibuildwheel/macos.py @@ -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": {"arm64", "x86_64"}, + "x86_64": {"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)] diff --git a/test/test_macos_archs.py b/test/test_macos_archs.py index f03fea921..4d03dfc52 100644 --- a/test/test_macos_archs.py +++ b/test/test_macos_archs.py @@ -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", @@ -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 @@ -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)