From fe21968368266db25a02e473db5bc805b2113b59 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sat, 27 Apr 2024 18:51:17 -0400 Subject: [PATCH] Set MACOSX_DEPLOYMENT_TARGET in macOS builds --- .github/workflows/workflow.yml | 24 ++++++++++++++++++++++++ hatch_build.py | 23 +++++++++++++---------- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 77b9f7c..0b39475 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -10,6 +10,10 @@ on: types: - published +concurrency: + group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number || github.sha }} + cancel-in-progress: true + jobs: build_macos_wheels: name: macOS (${{ matrix.os }}) @@ -29,6 +33,7 @@ jobs: python -m whisper_cpp -h CIBW_ARCHS_MACOS: "native" CIBW_BUILD: "cp312-*" + MACOSX_DEPLOYMENT_TARGET: ${{ matrix.os == 'macos-13' && '10.12' || '11.0' }} - uses: actions/upload-artifact@v4 with: @@ -84,6 +89,25 @@ jobs: name: cibw-sdist path: dist/*.tar.gz + # Verify that the x86_64 wheels work on macOS 11. + test_macos_11: + name: Test macOS 11 + runs-on: macos-11 + needs: build_macos_wheels + steps: + - uses: actions/checkout@v4 + + - uses: actions/download-artifact@v4 + with: + name: cibw-wheels-macos-13-0 + path: wheelhouse + + - name: Install wheel + run: pip install wheelhouse/*.whl + + - name: Test wheel + run: python -m whisper_cpp -h + upload_pypi: needs: [ build_macos_wheels, build_linux_wheels, build_sdist ] runs-on: ubuntu-latest diff --git a/hatch_build.py b/hatch_build.py index 96c9d53..d635991 100644 --- a/hatch_build.py +++ b/hatch_build.py @@ -67,16 +67,19 @@ def _infer_tag(self) -> str: tag = next(sys_tags()) tag_platform = tag.platform - archflags = os.environ.get("ARCHFLAGS", "") + # On macOS, set the version based on `MACOSX_DEPLOYMENT_TARGET`. if sys.platform == "darwin": - if archflags and sys.version_info[:2] >= (3, 8): - import platform - import re - - archs = re.findall(r"-arch (\S+)", archflags) - if archs: - current_arch = platform.mac_ver()[2] - new_arch = "universal2" if set(archs) == {"x86_64", "arm64"} else archs[0] - tag_platform = f"{tag_platform[: tag_platform.rfind(current_arch)]}{new_arch}" + macosx_deployment_target = os.environ.get("MACOSX_DEPLOYMENT_TARGET") + if macosx_deployment_target: + # Extract the architecture from, e.g., `macosx_14_0_arm64`. + if tag_platform.endswith("_arm64"): + tag_arch = "arm64" + elif tag_platform.endswith("_x86_64"): + tag_arch = "x86_64" + else: + raise ValueError(f"Unknown macOS arch: {tag_platform}") + + # Reconstruct the platform tag with the architecture. + tag_platform = f"macosx_{macosx_deployment_target.replace('.', '_')}_{tag_arch}" return f"py3-none-{tag_platform}"