From 4c4ea7637832e23dda3893c4a4988d65e1b3333c Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Thu, 13 Mar 2025 13:40:47 +0800 Subject: [PATCH 1/6] Modify cibuildwheel configuration to support iOS. --- pyproject.toml | 6 +++++- setup.py | 17 +++++++++++++++++ tests/test_main.py | 4 ++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 7c67494a..a61e75f3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,8 +5,12 @@ build-backend = "setuptools.build_meta" [tool.cibuildwheel] enable = ["cpython-freethreading", "pypy"] test-requires = "-r requirements-test.txt" -test-command = "pytest {project}/tests" +test-command = "pytest tests" test-skip = "*-win_arm64" # silence warnings for windows ARM64 +test-sources = [ + "tests", +] +safe-tools = ["cmake"] build-verbosity = 1 manylinux-i686-image = "manylinux2014" manylinux-pypy_i686-image = "manylinux2014" diff --git a/setup.py b/setup.py index 9342b6f2..02850305 100644 --- a/setup.py +++ b/setup.py @@ -129,7 +129,24 @@ def get_cmake_extra_config(plat_name: str | None, build_type: str) -> tuple[bool extra_config.append(f"-DCMAKE_OSX_ARCHITECTURES={arch}") else: log.warning("`%s` is not a known value for CMAKE_OSX_ARCHITECTURES", arch) + elif sys.platform == "ios": + if platform_module.ios_ver().is_simulator: + sdk = "iphonesimulator" + else: + sdk = "iphoneos" + sysroot = subprocess.check_output( + ["xcrun", "--show-sdk-path", "--sdk", sdk] + ).strip().decode("latin1") + arch = "x86_64" if platform_module.machine() == "x86_64" else "aarch64" + ios_min_ver = os.getenv("IPHONEOS_DEPLOYMENT_TARGET", "13.0") + extra_config.extend([ + "-DCMAKE_SYSTEM_NAME=iOS", + f"-DCMAKE_SYSTEM_PROCESSOR={arch}", + f"-DCMAKE_OSX_DEPLOYMENT_TARGET={ios_min_ver}", + f"-DCMAKE_OSX_SYSROOT={sysroot}", + "-DBUILD_SHARED_LIBS=NO", + ]) return is_msvc, extra_config diff --git a/tests/test_main.py b/tests/test_main.py index 7d709017..9d64c5c1 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -138,6 +138,10 @@ def test_decode( assert captured.out == b"hello world !/?\n" +@pytest.mark.skipif( + sys.platform == "ios", + reason="Subprocess tests don't work on iOS", +) def test_subprocess() -> None: import subprocess From 192a93381b6a098f63a9bfa43bd8691e55223b2e Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Thu, 13 Mar 2025 14:10:31 +0800 Subject: [PATCH 2/6] Update CI configuration to build iOS wheels. --- .github/workflows/build-upload.yml | 32 +++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build-upload.yml b/.github/workflows/build-upload.yml index b984c90b..fa77e8bf 100644 --- a/.github/workflows/build-upload.yml +++ b/.github/workflows/build-upload.yml @@ -25,25 +25,38 @@ jobs: - uses: pre-commit/action@v3.0.1 build_wheels: - name: Build ${{ matrix.archs }} ${{ matrix.build }} wheels on ${{ matrix.os }} + name: Build ${{ matrix.archs }} ${{ matrix.build }} wheels on ${{ matrix.platform }} needs: [lint] - runs-on: "${{ matrix.os }}${{ startsWith(matrix.archs, 'aarch64') && '-arm' || '' }}" + runs-on: "${{ matrix.runs-on }}${{ startsWith(matrix.archs, 'aarch64') && '-arm' || '' }}" strategy: matrix: - os: [ubuntu-24.04] + platform: [linux] archs: ["x86_64, i686", "aarch64, armv7l", "ppc64le", "s390x"] build: ["manylinux", "musllinux"] include: - - os: windows-2019 + - runs-on: ubuntu-24.04 + + - platform: "windows" + runs-on: windows-2019 archs: "AMD64" - - os: windows-2019 + - platform: "windows" + runs-on: windows-2019 archs: "x86" - - os: windows-2019 + - platform: "windows" + runs-on: windows-2019 archs: "ARM64" - - os: macos-13 + - platform: "macos" + runs-on: macos-13 archs: "x86_64" - - os: macos-14 + - platform: "macos" + runs-on: macos-14 archs: "arm64" + - platform: "ios" + runs-on: macos-13 + archs: "x86_64_iphonesimulator" + - platform: "ios" + runs-on: macos-latest + archs: "arm64_iphonesimulator,arm64_iphoneos" steps: - name: Set git to use LF @@ -71,13 +84,14 @@ jobs: - name: Build wheels uses: pypa/cibuildwheel@v2.23.0 env: + CIBW_PLATFORM: "${{ matrix.platform }}" CIBW_ARCHS: "${{ matrix.archs }}" CIBW_BUILD: "${{ matrix.build && '*-' || ''}}${{ matrix.build }}*" CIBW_ENABLE: "${{ startsWith(github.ref, 'refs/tags/v') && '' || 'cpython-prerelease'}}" - uses: actions/upload-artifact@v4 with: - name: "cibw-wheels ${{ matrix.build || matrix.os }} ${{ matrix.archs }}" + name: "cibw-wheels ${{ matrix.build || matrix.platform }} ${{ matrix.archs }}" path: ./wheelhouse/*.whl build_sdist: From 4734370f2f0c6308ef8016692d2492a410101549 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Fri, 14 Mar 2025 10:24:33 +0800 Subject: [PATCH 3/6] Turn up verbosity on pytest execution. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index a61e75f3..fdef6590 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta" [tool.cibuildwheel] enable = ["cpython-freethreading", "pypy"] test-requires = "-r requirements-test.txt" -test-command = "pytest tests" +test-command = "pytest tests -vv" test-skip = "*-win_arm64" # silence warnings for windows ARM64 test-sources = [ "tests", From c886065298202a98861e29380a602f4cd6e294eb Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Fri, 14 Mar 2025 10:24:51 +0800 Subject: [PATCH 4/6] Presumptively bump the cibuildwheel version. --- .github/workflows/build-upload.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-upload.yml b/.github/workflows/build-upload.yml index fa77e8bf..9aefadfd 100644 --- a/.github/workflows/build-upload.yml +++ b/.github/workflows/build-upload.yml @@ -82,7 +82,7 @@ jobs: python-version: 3.8 - name: Build wheels - uses: pypa/cibuildwheel@v2.23.0 + uses: pypa/cibuildwheel@v3.0.0 env: CIBW_PLATFORM: "${{ matrix.platform }}" CIBW_ARCHS: "${{ matrix.archs }}" From d846faed2ea6b983474a4f645d6b819c951e5e07 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 14 Mar 2025 02:33:02 +0000 Subject: [PATCH 5/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- setup.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/setup.py b/setup.py index 02850305..2cd6c331 100644 --- a/setup.py +++ b/setup.py @@ -134,19 +134,23 @@ def get_cmake_extra_config(plat_name: str | None, build_type: str) -> tuple[bool sdk = "iphonesimulator" else: sdk = "iphoneos" - sysroot = subprocess.check_output( - ["xcrun", "--show-sdk-path", "--sdk", sdk] - ).strip().decode("latin1") + sysroot = ( + subprocess.check_output(["xcrun", "--show-sdk-path", "--sdk", sdk]) + .strip() + .decode("latin1") + ) arch = "x86_64" if platform_module.machine() == "x86_64" else "aarch64" ios_min_ver = os.getenv("IPHONEOS_DEPLOYMENT_TARGET", "13.0") - extra_config.extend([ - "-DCMAKE_SYSTEM_NAME=iOS", - f"-DCMAKE_SYSTEM_PROCESSOR={arch}", - f"-DCMAKE_OSX_DEPLOYMENT_TARGET={ios_min_ver}", - f"-DCMAKE_OSX_SYSROOT={sysroot}", - "-DBUILD_SHARED_LIBS=NO", - ]) + extra_config.extend( + [ + "-DCMAKE_SYSTEM_NAME=iOS", + f"-DCMAKE_SYSTEM_PROCESSOR={arch}", + f"-DCMAKE_OSX_DEPLOYMENT_TARGET={ios_min_ver}", + f"-DCMAKE_OSX_SYSROOT={sysroot}", + "-DBUILD_SHARED_LIBS=NO", + ] + ) return is_msvc, extra_config From ae7728cccfa88c4b90b8fa50bf66766c97dc3e5c Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Fri, 14 Mar 2025 10:35:10 +0800 Subject: [PATCH 6/6] Placate ruff linting. --- setup.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 2cd6c331..a184e6ae 100644 --- a/setup.py +++ b/setup.py @@ -130,10 +130,7 @@ def get_cmake_extra_config(plat_name: str | None, build_type: str) -> tuple[bool else: log.warning("`%s` is not a known value for CMAKE_OSX_ARCHITECTURES", arch) elif sys.platform == "ios": - if platform_module.ios_ver().is_simulator: - sdk = "iphonesimulator" - else: - sdk = "iphoneos" + sdk = "iphonesimulator" if platform_module.ios_ver().is_simulator else "iphoneos" sysroot = ( subprocess.check_output(["xcrun", "--show-sdk-path", "--sdk", sdk]) .strip()