-
Notifications
You must be signed in to change notification settings - Fork 14
392 lines (347 loc) · 13.3 KB
/
build-wheels.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
name: Build Python wheels
on:
push:
branches: [main]
tags: ["*"]
pull_request:
paths:
# build wheels in PR if this file changed
- '.github/workflows/build-wheels.yml'
# build wheels in PR if any of the build system files changed
- '**/VERSION'
- '**/setup.py'
- '**/pyproject.toml'
- '**/MANIFEST.in'
- '**/Cargo.toml'
- '**/CMakeLists.txt'
- '**/build.rs'
concurrency:
group: wheels-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
env:
FEATOMIC_NO_LOCAL_DEPS: "1"
jobs:
build-wheels:
runs-on: ${{ matrix.os }}
name: ${{ matrix.name }}
strategy:
matrix:
include:
- name: x86_64 Linux
os: ubuntu-22.04
rust-target: x86_64-unknown-linux-gnu
cibw-arch: x86_64
- name: arm64 Linux
os: ubuntu-22.04
rust-target: aarch64-unknown-linux-gnu
cibw-arch: aarch64
- name: x86_64 macOS
os: macos-13
rust-target: x86_64-apple-darwin
cibw-arch: x86_64
- name: M1 macOS
os: macos-14
rust-target: aarch64-apple-darwin
cibw-arch: arm64
- name: x86_64 Windows
os: windows-2019
rust-target: x86_64-pc-windows-msvc
cibw-arch: AMD64
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: setup rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
target: ${{ matrix.rust-target }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: install dependencies
run: python -m pip install cibuildwheel twine
- name: Set up QEMU for docker
if: matrix.os == 'ubuntu-22.04'
uses: docker/setup-qemu-action@v3
- name: build manylinux with rust docker image
if: matrix.os == 'ubuntu-22.04'
run: docker build -t rustc-manylinux2014_${{ matrix.cibw-arch }} python/scripts/rustc-manylinux2014_${{ matrix.cibw-arch }}
- name: build featomic wheel
run: python -m cibuildwheel python/featomic
env:
CIBW_BUILD: cp312-*
CIBW_SKIP: "*musllinux*"
CIBW_ARCHS: ${{ matrix.cibw-arch }}
CIBW_BUILD_VERBOSITY: 1
CIBW_MANYLINUX_X86_64_IMAGE: rustc-manylinux2014_x86_64
CIBW_MANYLINUX_AARCH64_IMAGE: rustc-manylinux2014_aarch64
CIBW_REPAIR_WHEEL_COMMAND_MACOS: "delocate-wheel --ignore-missing-dependencies --require-archs {delocate_archs} -w {dest_dir} -v {wheel}"
CIBW_REPAIR_WHEEL_COMMAND_LINUX: "auditwheel repair --exclude libmetatensor.so -w {dest_dir} {wheel}"
CIBW_ENVIRONMENT: >
MACOSX_DEPLOYMENT_TARGET=11
FEATOMIC_NO_LOCAL_DEPS=1
- uses: actions/upload-artifact@v4
with:
name: wheel-${{ matrix.os }}-${{ matrix.cibw-arch }}
path: ./wheelhouse/*.whl
build-torch-wheels:
runs-on: ${{ matrix.os }}
name: ${{ matrix.name }} (torch v${{ matrix.torch-version }})
strategy:
matrix:
torch-version: ['2.1', '2.2', '2.3', '2.4', '2.5']
arch: ['arm64', 'x86_64']
os: ['ubuntu-22.04', 'macos-13', 'macos-14', 'windows-2019']
exclude:
# remove mismatched arch for macOS
- {os: macos-14, arch: x86_64}
- {os: macos-13, arch: arm64}
# no arm64-windows build
- {os: windows-2019, arch: arm64}
# arch x86_64 on macos is only supported for torch <2.3
- {os: macos-13, arch: x86_64, torch-version: '2.3'}
- {os: macos-13, arch: x86_64, torch-version: '2.4'}
- {os: macos-13, arch: x86_64, torch-version: '2.5'}
include:
# add `cibw-arch` and `rust-target` to the different configurations
- name: x86_64 Linux
os: ubuntu-22.04
arch: x86_64
rust-target: x86_64-unknown-linux-gnu
cibw-arch: x86_64
- name: arm64 Linux
os: ubuntu-22.04
arch: arm64
rust-target: aarch64-unknown-linux-gnu
cibw-arch: aarch64
- name: x86_64 macOS
os: macos-13
arch: x86_64
rust-target: x86_64-apple-darwin
cibw-arch: x86_64
- name: arm64 macOS
os: macos-14
arch: arm64
rust-target: aarch64-apple-darwin
cibw-arch: arm64
- name: x86_64 Windows
os: windows-2019
arch: x86_64
rust-target: x86_64-pc-windows-msvc
cibw-arch: AMD64
# add the right python version for each torch version
- {torch-version: '2.1', python-version: '3.11', cibw-python: 'cp311-*'}
- {torch-version: '2.2', python-version: '3.12', cibw-python: 'cp312-*'}
- {torch-version: '2.3', python-version: '3.12', cibw-python: 'cp312-*'}
- {torch-version: '2.4', python-version: '3.12', cibw-python: 'cp312-*'}
- {torch-version: '2.5', python-version: '3.12', cibw-python: 'cp312-*'}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: setup rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
target: ${{ matrix.rust-target }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: install dependencies
run: python -m pip install cibuildwheel
- name: Set up QEMU for docker
if: matrix.os == 'ubuntu-22.04'
uses: docker/setup-qemu-action@v3
- name: build manylinux with rust docker image
if: matrix.os == 'ubuntu-22.04'
run: docker buildx build -t rustc-manylinux2014_${{ matrix.cibw-arch }} python/scripts/rustc-manylinux2014_${{ matrix.cibw-arch }}
- name: build featomic-torch wheel
run: python -m cibuildwheel python/featomic_torch
env:
CIBW_BUILD: ${{ matrix.cibw-python}}
CIBW_SKIP: "*musllinux*"
CIBW_ARCHS: ${{ matrix.cibw-arch }}
CIBW_BUILD_VERBOSITY: 1
CIBW_MANYLINUX_X86_64_IMAGE: rustc-manylinux2014_x86_64
CIBW_MANYLINUX_AARCH64_IMAGE: rustc-manylinux2014_aarch64
# FEATOMIC_NO_LOCAL_DEPS is set to 1 when building a tag of
# featomic-torch, which will force to use the version of featomic
# already released on PyPI. Otherwise, this will use the version of
# featomic from git checkout (in case there are unreleased breaking
# changes). This means we can not release breaking changes in featomic
# and v-torch by putting a tag on the same commit. Instead featomic
# must be fully released before we start the build of featomic-torch
# wheels.
CIBW_ENVIRONMENT: >
FEATOMIC_NO_LOCAL_DEPS=${{ startsWith(github.ref, 'refs/tags/featomic-torch-v') && '1' || '0' }}
FEATOMIC_TORCH_BUILD_WITH_TORCH_VERSION=${{ matrix.torch-version }}.*
PIP_EXTRA_INDEX_URL=https://download.pytorch.org/whl/cpu
MACOSX_DEPLOYMENT_TARGET=11
# do not complain for missing libtorch.so, libfeatomic.so, & co
CIBW_REPAIR_WHEEL_COMMAND_MACOS: |
delocate-wheel --ignore-missing-dependencies \
--require-archs {delocate_archs} \
-w {dest_dir} -v {wheel}
CIBW_REPAIR_WHEEL_COMMAND_LINUX: |
auditwheel repair --exclude libfeatomic.so \
--exclude libmetatensor.so \
--exclude libmetatensor_torch.so \
--exclude libtorch.so \
--exclude libtorch_cpu.so \
--exclude libc10.so \
-w {dest_dir} {wheel}
- uses: actions/upload-artifact@v4
with:
name: torch-single-version-wheel-${{ matrix.torch-version }}-${{ matrix.os }}-${{ matrix.arch }}
path: ./wheelhouse/*.whl
merge-torch-wheels:
needs: build-torch-wheels
runs-on: ubuntu-22.04
name: merge featomic-torch ${{ matrix.name }}
strategy:
matrix:
include:
- name: x86_64 Linux
os: ubuntu-22.04
arch: x86_64
- name: arm64 Linux
os: ubuntu-22.04
arch: arm64
- name: x86_64 macOS
os: macos-13
arch: x86_64
- name: arm64 macOS
os: macos-14
arch: arm64
- name: x86_64 Windows
os: windows-2019
arch: x86_64
steps:
- uses: actions/checkout@v4
- name: Download wheels
uses: actions/download-artifact@v4
with:
pattern: torch-single-version-wheel-*-${{ matrix.os }}-${{ matrix.arch }}
merge-multiple: false
path: dist
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: install dependencies
run: python -m pip install twine wheel
- name: merge wheels
run: |
# collect all torch versions used for the build
REQUIRES_TORCH=$(find dist -name "*.whl" -exec unzip -p {} "featomic_torch-*.dist-info/METADATA" \; | grep "Requires-Dist: torch")
MERGED_TORCH_REQUIRE=$(python scripts/create-torch-versions-range.py "$REQUIRES_TORCH")
echo MERGED_TORCH_REQUIRE=$MERGED_TORCH_REQUIRE
# unpack all single torch versions wheels in the same directory
mkdir dist/unpacked
find dist -name "*.whl" -print -exec python -m wheel unpack --dest dist/unpacked/ {} ';'
sed -i "s/Requires-Dist: torch.*/$MERGED_TORCH_REQUIRE/" dist/unpacked/featomic_torch-*/featomic_torch-*.dist-info/METADATA
echo "\n\n METADATA = \n\n"
cat dist/unpacked/featomic_torch-*/featomic_torch-*.dist-info/METADATA
# check the right metadata was added to the file. grep will exit with
# code `1` if the line is not found, which will stop CI
grep "$MERGED_TORCH_REQUIRE" dist/unpacked/featomic_torch-*/featomic_torch-*.dist-info/METADATA
# repack the directory as a new wheel
mkdir wheelhouse
python -m wheel pack --dest wheelhouse/ dist/unpacked/*
- name: check wheels with twine
run: twine check wheelhouse/*
- uses: actions/upload-artifact@v4
with:
name: torch-wheel-${{ matrix.os }}-${{ matrix.arch }}
path: ./wheelhouse/*.whl
build-sdist:
runs-on: ubuntu-22.04
name: sdist
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: build featomic sdist
run: |
pip install build
python -m build --sdist python/featomic
- name: build featomic-torch sdist
run: |
python -m build --sdist python/featomic_torch
- name: create C++ tarballs
run: |
./scripts/package-featomic.sh dist/cxx/
./scripts/package-featomic-torch.sh dist/cxx/
- uses: actions/upload-artifact@v4
with:
name: sdist
path: |
dist/*.tar.gz
dist/cxx/*.tar.gz
- name: upload sdist to GitHub release
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
with:
files: |
dist/*.tar.gz
dist/cxx/*.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
merge-and-release:
name: Merge and release wheels/sdists
needs: [build-wheels, merge-torch-wheels, build-sdist]
runs-on: ubuntu-22.04
permissions:
contents: write
steps:
- name: Download featomic wheels
uses: actions/download-artifact@v4
with:
path: wheels
pattern: wheel-*
merge-multiple: true
- name: Download featomic-torch wheels
uses: actions/download-artifact@v4
with:
path: wheels
pattern: torch-wheel-*
merge-multiple: true
- name: Download sdists
uses: actions/download-artifact@v4
with:
path: wheels
name: sdist
- name: Re-upload a single wheels artifact
uses: actions/upload-artifact@v4
with:
name: wheels
path: |
wheels/*
wheels/cxx/*
- name: upload to GitHub release (featomic)
if: startsWith(github.ref, 'refs/tags/featomic-v')
uses: softprops/action-gh-release@v2
with:
files: |
wheels/cxx/featomic-cxx-*.tar.gz
wheels/featomic-*
prerelease: ${{ contains(github.ref, '-rc') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: upload to GitHub release (featomic-torch)
if: startsWith(github.ref, 'refs/tags/featomic-torch-v')
uses: softprops/action-gh-release@v2
with:
files: |
wheels/cxx/featomic-torch-cxx-*.tar.gz
wheels/featomic_torch-*
prerelease: ${{ contains(github.ref, '-rc') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}