Skip to content

Commit ad3fa54

Browse files
committed
Make universal2 wheels on macos
1 parent 6611533 commit ad3fa54

File tree

3 files changed

+55
-24
lines changed

3 files changed

+55
-24
lines changed

.github/workflows/build-macos.yml

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,41 +57,29 @@ jobs:
5757
# path: ${{ github.workspace }}/pygame_mac_deps_${{ matrix.macarch }}
5858

5959
build:
60-
name: ${{ matrix.macarch }}
60+
name: universal2
6161
needs: deps
62-
runs-on: ${{ matrix.os }}
63-
strategy:
64-
fail-fast: false # if a particular matrix build fails, don't skip the rest
65-
matrix:
66-
include:
67-
- { macarch: arm64, os: macos-15 }
68-
- { macarch: x86_64, os: macos-15 }
62+
runs-on: macos-15
6963

7064
env:
71-
MAC_ARCH: ${{ matrix.macarch }}
72-
7365
# Explicitly tell CIBW what the wheel arch deployment target should be
7466
# There seems to be no better way to set this than this env
7567
# We need this because our minimum is 10.11, different from default
7668
# of 10.9 on x86s
7769
# Related issue: https://github.com/pypa/cibuildwheel/issues/952
78-
_PYTHON_HOST_PLATFORM: ${{ matrix.macarch == 'x86_64' && 'macosx-10.11-x86_64' || 'macosx-11.0-arm64'}}
70+
_PYTHON_HOST_PLATFORM: 'macosx-10.11-universal2'
7971

8072
# Similarly, we need to tell CIBW that the wheel's linking steps
8173
# should be for 10.11 on x86
82-
MACOSX_DEPLOYMENT_TARGET: ${{ matrix.macarch == 'x86_64' && '10.11' || '11.0' }}
74+
MACOSX_DEPLOYMENT_TARGET: '10.11'
8375

84-
CIBW_ARCHS: ${{ matrix.macarch }}
76+
CIBW_ARCHS: universal2
8577

8678
# Setup macOS dependencies
8779
CIBW_BEFORE_ALL: |
8880
cd buildconfig/macdependencies
89-
cp -r ${{ github.workspace }}/pygame_mac_deps_${{ matrix.macarch }} ${{ github.workspace }}/pygame_mac_deps
9081
bash ./install_mac_deps.sh
9182
92-
CIBW_BEFORE_BUILD: |
93-
cp -r ${{ github.workspace }}/pygame_mac_deps_${{ matrix.macarch }} ${{ github.workspace }}/pygame_mac_deps
94-
9583
# To remove any speculations about the wheel not being self-contained
9684
CIBW_BEFORE_TEST: rm -rf ${{ github.workspace }}/pygame_mac_deps
9785

@@ -104,12 +92,18 @@ jobs:
10492
path: ~/Library/Caches/pip # This cache path is only right on mac
10593
key: pip-cache-${{ matrix.macarch }}-${{ matrix.os }}
10694

107-
- name: Fetch Mac deps
108-
id: macdep-cache
95+
- name: Fetch Mac deps (x86_64)
10996
uses: actions/cache@v4.3.0
11097
with:
111-
path: ${{ github.workspace }}/pygame_mac_deps_${{ matrix.macarch }}
112-
key: macdep-${{ hashFiles('buildconfig/manylinux-build/**') }}-${{ hashFiles('buildconfig/macdependencies/*.sh') }}-${{ matrix.macarch }}
98+
path: ${{ github.workspace }}/pygame_mac_deps_x86_64
99+
key: macdep-${{ hashFiles('buildconfig/manylinux-build/**') }}-${{ hashFiles('buildconfig/macdependencies/*.sh') }}-x86_64
100+
fail-on-cache-miss: true
101+
102+
- name: Fetch Mac deps (arm64)
103+
uses: actions/cache@v4.3.0
104+
with:
105+
path: ${{ github.workspace }}/pygame_mac_deps_arm64
106+
key: macdep-${{ hashFiles('buildconfig/manylinux-build/**') }}-${{ hashFiles('buildconfig/macdependencies/*.sh') }}-arm64
113107
fail-on-cache-miss: true
114108

115109
- name: Install uv for speed

buildconfig/macdependencies/install_mac_deps.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import shutil
6+
import subprocess
67
import sys
78
from pathlib import Path
89

@@ -30,6 +31,38 @@ def rmpath(path: Path, verbose: bool = False):
3031
shutil.rmtree(path)
3132

3233

34+
def merge_dylibs(out_dir: Path, x86_dir: Path, arm_dir: Path, verbose: bool = False):
35+
"""
36+
Merge .dylib files from x86_64 into a copy of arm64 folder.
37+
- Moves arm_dir to out_dir.
38+
- For each .dylib in x86_dir, merges it with the arm64 one if present,
39+
otherwise just copies it over.
40+
- Deletes x86_dir after merging.
41+
"""
42+
shutil.move(arm_dir, out_dir)
43+
if verbose:
44+
print(f"- Moved {arm_dir} -> {out_dir}")
45+
46+
for x86_file in x86_dir.rglob("*.dylib"):
47+
rel_path = x86_file.relative_to(x86_dir)
48+
out_file = out_dir / rel_path
49+
if out_file.exists():
50+
subprocess.run(
51+
["lipo", "-create", "-output", out_file, out_file, x86_file], check=True
52+
)
53+
if verbose:
54+
print(f"- Merged: {rel_path}")
55+
else:
56+
out_file.parent.mkdir(parents=True, exist_ok=True)
57+
shutil.copy2(x86_file, out_file)
58+
if verbose:
59+
print(f"- Copied x86-only: {rel_path}")
60+
61+
shutil.rmtree(x86_dir)
62+
if verbose:
63+
print(f"- Deleted {x86_dir}")
64+
65+
3366
def symtree(srcdir: Path, destdir: Path, verbose: bool = False):
3467
"""
3568
This function creates symlinks pointing to srcdir, from destdir, such that
@@ -57,5 +90,7 @@ def symtree(srcdir: Path, destdir: Path, verbose: bool = False):
5790

5891
destpath.symlink_to(path)
5992

60-
61-
symtree(Path(sys.argv[1]), Path("/usr/local"), verbose=True)
93+
if __name__ == "__main__":
94+
out_dir, x86_dir, arm_dir = map(Path, sys.argv[1:])
95+
merge_dylibs(out_dir, x86_dir, arm_dir, verbose=True)
96+
symtree(out_dir, Path("/usr/local"), verbose=True)

buildconfig/macdependencies/install_mac_deps.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
set -e -x
33

44
bash ./clean_usr_local.sh
5-
sudo python3 install_mac_deps.py ${GITHUB_WORKSPACE}/pygame_mac_deps_${MAC_ARCH}
5+
sudo python3 install_mac_deps.py ${GITHUB_WORKSPACE}/pygame_mac_deps \
6+
${GITHUB_WORKSPACE}/pygame_mac_deps_x86_64 \
7+
${GITHUB_WORKSPACE}/pygame_mac_deps_arm64

0 commit comments

Comments
 (0)