Skip to content

Commit 2b3cbb4

Browse files
committed
add: build wheel macos yml
1 parent cdeeaf4 commit 2b3cbb4

1 file changed

Lines changed: 140 additions & 0 deletions

File tree

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
name: Build and Release dlib Wheels macOS
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
workflow_dispatch:
8+
inputs:
9+
create_release:
10+
description: "Create a release"
11+
required: false
12+
type: boolean
13+
default: false
14+
15+
jobs:
16+
build-macos:
17+
runs-on: ${{ matrix.os }}
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
os: [macos-13, macos-14] # macos-13 = Intel (x86_64), macos-14 = Apple Silicon (arm64)
22+
python-version: ["3.10", "3.11", "3.12", "3.13"]
23+
timeout-minutes: 60
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
28+
29+
- name: Set up Python ${{ matrix.python-version }}
30+
uses: actions/setup-python@v5
31+
with:
32+
python-version: ${{ matrix.python-version }}
33+
34+
- name: Install Homebrew dependencies
35+
run: |
36+
brew update
37+
brew install cmake boost openblas
38+
39+
- name: Install Python build tools
40+
run: |
41+
python -m pip install --upgrade pip
42+
pip install build wheel setuptools delocate
43+
44+
- name: Clone dlib
45+
run: |
46+
git clone --depth 1 https://github.com/davisking/dlib.git dlib_src
47+
48+
- name: Build wheel
49+
run: |
50+
cd dlib_src
51+
python setup.py bdist_wheel
52+
53+
if [ ! -f dist/*.whl ]; then
54+
echo "Wheel build failed - no wheel found in dist/"
55+
ls -la dist/ || echo "dist/ directory not found"
56+
exit 1
57+
fi
58+
59+
- name: Repair wheel with delocate
60+
run: |
61+
cd dlib_src
62+
mkdir -p dist_repaired/
63+
64+
# Use delocate to bundle dependencies
65+
delocate-wheel -w dist_repaired/ -v dist/*.whl
66+
67+
echo "Repaired wheels:"
68+
ls -lh dist_repaired/
69+
70+
- name: Set architecture for artifact name
71+
id: arch
72+
run: |
73+
if [ "${{ matrix.os }}" = "macos-13" ]; then
74+
echo "arch=x86_64" >> $GITHUB_OUTPUT
75+
else
76+
echo "arch=arm64" >> $GITHUB_OUTPUT
77+
fi
78+
79+
- name: Upload build artifact
80+
uses: actions/upload-artifact@v4
81+
with:
82+
name: dlib-py${{ matrix.python-version }}-macos-${{ steps.arch.outputs.arch }}
83+
path: dlib_src/dist_repaired/*.whl
84+
retention-days: 30
85+
86+
release:
87+
runs-on: ubuntu-latest
88+
needs: [build-macos]
89+
if: startsWith(github.ref, 'refs/tags/') || github.event.inputs.create_release == 'true'
90+
permissions:
91+
contents: write
92+
93+
steps:
94+
- name: Download all artifacts
95+
uses: actions/download-artifact@v4
96+
with:
97+
path: artifacts/
98+
99+
- name: Prepare wheels
100+
run: |
101+
mkdir -p wheels
102+
find artifacts -name "*.whl" -exec cp {} wheels/ \;
103+
echo "Built wheels:"
104+
ls -lh wheels/
105+
106+
# Count wheels by architecture
107+
x86_count=$(find wheels -name "*x86_64*.whl" | wc -l)
108+
arm64_count=$(find wheels -name "*arm64*.whl" | wc -l)
109+
echo "x86_64 (Intel) wheels: $x86_count"
110+
echo "arm64 (Apple Silicon) wheels: $arm64_count"
111+
112+
- name: Create Release
113+
uses: softprops/action-gh-release@v2
114+
with:
115+
name: Release ${{ github.event.inputs.create_release == 'true' && format('macOS Manual Release {0}', github.run_number) || github.ref_name }}
116+
tag_name: ${{ github.event.inputs.create_release == 'true' && format('macos-{0}', github.run_number) || github.ref_name }}
117+
body: |
118+
Prebuilt dlib wheels for macOS (Intel x86_64 and Apple Silicon arm64)
119+
120+
**Supported:**
121+
- **Architectures**: x86_64 (Intel), arm64 (Apple Silicon)
122+
- **Python versions**: 3.10, 3.11, 3.12, 3.13
123+
- **macOS versions**: 10.9+ (x86_64), 11.0+ (arm64)
124+
125+
**Installation:**
126+
```bash
127+
pip install dlib-*.whl
128+
```
129+
130+
Choose the wheel that matches your:
131+
- Python version (cp310, cp311, cp312, or cp313)
132+
- Architecture (x86_64 for Intel Macs, arm64 for Apple Silicon)
133+
134+
**System Requirements:**
135+
No additional dependencies needed - wheels are self-contained with bundled libraries.
136+
files: wheels/*.whl
137+
draft: false
138+
prerelease: false
139+
env:
140+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)