Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set MACOSX_DEPLOYMENT_TARGET in macOS builds #8

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }})
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
23 changes: 13 additions & 10 deletions hatch_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"