Skip to content

Commit 62f0b38

Browse files
committed
Build wheels on CI again
1 parent 767e824 commit 62f0b38

File tree

1 file changed

+338
-0
lines changed

1 file changed

+338
-0
lines changed

.github/workflows/build-wheels.yml

Lines changed: 338 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,338 @@
1+
name: Build Python wheels
2+
3+
on:
4+
push:
5+
tags: ["*"]
6+
pull_request:
7+
paths:
8+
# build wheels in PR if this file changed
9+
- '.github/workflows/build-wheels.yml'
10+
# build wheels in PR if any of the build system files changed
11+
- '**/VERSION'
12+
- '**/setup.py'
13+
- '**/pyproject.toml'
14+
- '**/MANIFEST.in'
15+
- '**/CMakeLists.txt'
16+
schedule:
17+
# check the build once a week on mondays
18+
- cron: '0 10 * * 1'
19+
20+
21+
concurrency:
22+
group: python-wheels-${{ github.ref }}
23+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
24+
25+
26+
jobs:
27+
# build-torch-wheels:
28+
# runs-on: ${{ matrix.os }}
29+
# name: ${{ matrix.name }} (torch v${{ matrix.torch-version }})
30+
# strategy:
31+
# matrix:
32+
# os: ['ubuntu-22.04', 'ubuntu-22.04-arm', 'macos-13', 'macos-14', 'windows-2022']
33+
# arch: ['arm64', 'x86_64']
34+
# torch-version: ['1.12', '1.13', '2.0', '2.1', '2.2', '2.3', '2.4', '2.5', '2.6']
35+
# exclude:
36+
# # remove mismatched arch-os combinations
37+
# - {os: macos-13, arch: arm64}
38+
# - {os: windows-2022, arch: arm64}
39+
# - {os: ubuntu-22.04, arch: arm64}
40+
# - {os: macos-14, arch: x86_64}
41+
# - {os: ubuntu-22.04-arm, arch: x86_64}
42+
# # arch arm64 on macos is only supported for torch >= 2.0
43+
# - {os: macos-14, arch: arm64, torch-version: '1.12'}
44+
# - {os: macos-14, arch: arm64, torch-version: '1.13'}
45+
# # arch x86_64 on macos is only supported for torch <2.3
46+
# - {os: macos-13, arch: x86_64, torch-version: '2.3'}
47+
# - {os: macos-13, arch: x86_64, torch-version: '2.4'}
48+
# - {os: macos-13, arch: x86_64, torch-version: '2.5'}
49+
# - {os: macos-13, arch: x86_64, torch-version: '2.6'}
50+
# include:
51+
# # add `cibw-arch` and `rust-target` to the different configurations
52+
# - name: x86_64 Linux
53+
# os: ubuntu-22.04
54+
# arch: x86_64
55+
# rust-target: x86_64-unknown-linux-gnu
56+
# cibw-arch: x86_64
57+
# - name: arm64 Linux
58+
# os: ubuntu-22.04-arm
59+
# arch: arm64
60+
# rust-target: aarch64-unknown-linux-gnu
61+
# cibw-arch: aarch64
62+
# - name: x86_64 macOS
63+
# os: macos-13
64+
# arch: x86_64
65+
# rust-target: x86_64-apple-darwin
66+
# cibw-arch: x86_64
67+
# - name: arm64 macOS
68+
# os: macos-14
69+
# arch: arm64
70+
# rust-target: aarch64-apple-darwin
71+
# cibw-arch: arm64
72+
# - name: x86_64 Windows
73+
# os: windows-2022
74+
# arch: x86_64
75+
# rust-target: x86_64-pc-windows-msvc
76+
# cibw-arch: AMD64
77+
# # add the right python version image for each torch version
78+
# - {torch-version: '1.12', cibw-python: 'cp310-*'}
79+
# - {torch-version: '1.13', cibw-python: 'cp310-*'}
80+
# - {torch-version: '2.0', cibw-python: 'cp311-*'}
81+
# - {torch-version: '2.1', cibw-python: 'cp311-*'}
82+
# - {torch-version: '2.2', cibw-python: 'cp312-*'}
83+
# - {torch-version: '2.3', cibw-python: 'cp312-*'}
84+
# - {torch-version: '2.4', cibw-python: 'cp312-*'}
85+
# - {torch-version: '2.5', cibw-python: 'cp312-*'}
86+
# - {torch-version: '2.6', cibw-python: 'cp312-*'}
87+
# # set the right manylinux image to use
88+
# - {torch-version: '1.12', manylinux-version: "2014"}
89+
# - {torch-version: '1.13', manylinux-version: "2014"}
90+
# - {torch-version: '2.0', manylinux-version: "2014"}
91+
# - {torch-version: '2.1', manylinux-version: "2014"}
92+
# - {torch-version: '2.2', manylinux-version: "2014"}
93+
# - {torch-version: '2.3', manylinux-version: "2014"}
94+
# - {torch-version: '2.4', manylinux-version: "2014"}
95+
# - {torch-version: '2.5', manylinux-version: "2014"}
96+
# # only torch >+ 2.6 on arm64-linux needs the newer manylinux
97+
# - {torch-version: '2.6', arch: "arm64", manylinux-version: "_2_28"}
98+
# - {torch-version: '2.6', arch: "x86_64", manylinux-version: "2014"}
99+
# steps:
100+
# - uses: actions/checkout@v4
101+
# with:
102+
# fetch-depth: 0
103+
104+
# - name: Set up Python
105+
# uses: actions/setup-python@v5
106+
# with:
107+
# python-version: "3.13"
108+
109+
# - name: install dependencies
110+
# run: python -m pip install cibuildwheel
111+
112+
# - name: build metatomic-torch wheel
113+
# run: python -m cibuildwheel python/metatomic_torch
114+
# env:
115+
# CIBW_BUILD: ${{ matrix.cibw-python}}
116+
# CIBW_SKIP: "*musllinux*"
117+
# CIBW_ARCHS: ${{ matrix.cibw-arch }}
118+
# CIBW_BUILD_VERBOSITY: 1
119+
# CIBW_MANYLINUX_X86_64_IMAGE: quay.io/pypa/manylinux${{ matrix.manylinux-version }}_x86_64
120+
# CIBW_MANYLINUX_AARCH64_IMAGE: quay.io/pypa/manylinux${{ matrix.manylinux-version }}_aarch64
121+
# CIBW_ENVIRONMENT: >
122+
# METATOMIC_TORCH_BUILD_WITH_TORCH_VERSION=${{ matrix.torch-version }}.*
123+
# PIP_EXTRA_INDEX_URL=https://download.pytorch.org/whl/cpu
124+
# MACOSX_DEPLOYMENT_TARGET=11
125+
# # do not complain for missing shared libraries provided by other packages
126+
# CIBW_REPAIR_WHEEL_COMMAND_MACOS: |
127+
# delocate-wheel --ignore-missing-dependencies --require-archs {delocate_archs} -w {dest_dir} -v {wheel}
128+
# CIBW_REPAIR_WHEEL_COMMAND_LINUX: |
129+
# auditwheel repair --exclude libmetatensor.so --exclude libmetatensor_torch.so --exclude libtorch.so --exclude libtorch_cpu.so --exclude libc10.so -w {dest_dir} {wheel}
130+
131+
# - uses: actions/upload-artifact@v4
132+
# with:
133+
# name: torch-single-version-wheel-${{ matrix.torch-version }}-${{ matrix.os }}-${{ matrix.arch }}
134+
# path: ./wheelhouse/*.whl
135+
136+
# merge-torch-wheels:
137+
# needs: build-torch-wheels
138+
# runs-on: ubuntu-22.04
139+
# name: merge metatomic-torch ${{ matrix.name }}
140+
# strategy:
141+
# matrix:
142+
# include:
143+
# - name: x86_64 Linux
144+
# os: ubuntu-22.04
145+
# arch: x86_64
146+
# - name: arm64 Linux
147+
# os: ubuntu-22.04-arm
148+
# arch: arm64
149+
# - name: x86_64 macOS
150+
# os: macos-13
151+
# arch: x86_64
152+
# - name: arm64 macOS
153+
# os: macos-14
154+
# arch: arm64
155+
# - name: x86_64 Windows
156+
# os: windows-2022
157+
# arch: x86_64
158+
# steps:
159+
# - uses: actions/checkout@v4
160+
161+
# - name: Download wheels
162+
# uses: actions/download-artifact@v4
163+
# with:
164+
# pattern: torch-single-version-wheel-*-${{ matrix.os }}-${{ matrix.arch }}
165+
# merge-multiple: false
166+
# path: dist
167+
168+
# - name: Set up Python
169+
# uses: actions/setup-python@v5
170+
# with:
171+
# python-version: "3.13"
172+
173+
# - name: install dependencies
174+
# run: python -m pip install twine wheel
175+
176+
# - name: merge wheels
177+
# run: |
178+
# # collect all torch versions used for the build
179+
# REQUIRES_TORCH=$(find dist -name "*.whl" -exec unzip -p {} "metatomic_torch-*.dist-info/METADATA" \; | grep "Requires-Dist: torch")
180+
# MERGED_TORCH_REQUIRE=$(python scripts/create-torch-versions-range.py "$REQUIRES_TORCH")
181+
182+
# echo MERGED_TORCH_REQUIRE=$MERGED_TORCH_REQUIRE
183+
184+
# # unpack all single torch versions wheels in the same directory
185+
# mkdir dist/unpacked
186+
# find dist -name "*.whl" -print -exec python -m wheel unpack --dest dist/unpacked/ {} ';'
187+
188+
# sed -i "s/Requires-Dist: torch.*/$MERGED_TORCH_REQUIRE/" dist/unpacked/metatomic_torch-*/metatomic_torch-*.dist-info/METADATA
189+
190+
# echo "\n\n METADATA = \n\n"
191+
# cat dist/unpacked/metatomic_torch-*/metatomic_torch-*.dist-info/METADATA
192+
193+
# # check the right metadata was added to the file. grep will exit with
194+
# # code `1` if the line is not found, which will stop CI
195+
# grep "$MERGED_TORCH_REQUIRE" dist/unpacked/metatomic_torch-*/metatomic_torch-*.dist-info/METADATA
196+
197+
# # repack the directory as a new wheel
198+
# mkdir wheelhouse
199+
# python -m wheel pack --dest wheelhouse/ dist/unpacked/*
200+
201+
# - name: check wheels with twine
202+
# run: twine check wheelhouse/*
203+
204+
# - uses: actions/upload-artifact@v4
205+
# with:
206+
# name: torch-wheel-${{ matrix.os }}-${{ matrix.arch }}
207+
# path: ./wheelhouse/*.whl
208+
209+
# build-others:
210+
# name: Build other wheels/sdists
211+
# runs-on: ubuntu-22.04
212+
# env:
213+
# METATOMIC_NO_LOCAL_DEPS: "1"
214+
# steps:
215+
# - uses: actions/checkout@v4
216+
# with:
217+
# fetch-depth: 0
218+
219+
# - name: Set up Python
220+
# uses: actions/setup-python@v5
221+
# with:
222+
# python-version: "3.13"
223+
224+
# - name: install dependencies
225+
# run: python -m pip install wheel build twine
226+
227+
# - name: build metatomic-torch sdist
228+
# run: python -m build python/metatomic_torch --sdist --outdir=dist/
229+
230+
# - name: build metatomic sdist and wheel
231+
# run: python -m build . --outdir=dist/
232+
233+
# - name: check sdist and wheels with twine
234+
# run: twine check dist/*.tar.gz dist/*.whl
235+
236+
# - name: create C++ tarballs
237+
# run: |
238+
# ./scripts/package-torch.sh dist/cxx/
239+
240+
# - uses: actions/upload-artifact@v4
241+
# with:
242+
# name: others
243+
# path: |
244+
# dist/*.tar.gz
245+
# dist/cxx/*.tar.gz
246+
# dist/*.whl
247+
248+
# merge-and-release:
249+
# name: Merge and release wheels/sdists
250+
# needs: [merge-torch-wheels, build-others]
251+
# runs-on: ubuntu-22.04
252+
# permissions:
253+
# contents: write
254+
# pull-requests: write
255+
# steps:
256+
# - name: Download metatomic-torch wheels
257+
# uses: actions/download-artifact@v4
258+
# with:
259+
# path: wheels
260+
# pattern: torch-wheel-*
261+
# merge-multiple: true
262+
263+
# - name: Download other wheels and sdists
264+
# uses: actions/download-artifact@v4
265+
# with:
266+
# path: wheels
267+
# name: others
268+
269+
# - name: Re-upload a single wheels artifact
270+
# uses: actions/upload-artifact@v4
271+
# with:
272+
# name: wheels
273+
# path: |
274+
# wheels/*
275+
# wheels/cxx/*
276+
277+
# - name: Comment with download link
278+
# uses: PicoCentauri/comment-artifact@v1
279+
# if: github.event.pull_request.head.repo.fork == false
280+
# with:
281+
# name: wheels
282+
# description: ⚙️ Download Python wheels for this pull-request (you can install these with pip)
283+
284+
# - name: upload to GitHub release (metatomic-torch)
285+
# if: startsWith(github.ref, 'refs/tags/metatomic-torch-v')
286+
# uses: softprops/action-gh-release@v2
287+
# with:
288+
# files: |
289+
# wheels/cxx/metatomic-torch-cxx-*.tar.gz
290+
# wheels/metatomic_torch-*
291+
# prerelease: ${{ contains(github.ref, '-rc') }}
292+
# env:
293+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
294+
295+
test-build-external:
296+
# This checks building the wheels with external libraries. This setup is
297+
# mainly used for the conda packages metatensor-*-python, which use the
298+
# libmetatensor-* conda packages to provide the native code.
299+
runs-on: ${{ matrix.os }}
300+
name: External libraries / ${{ matrix.os }}
301+
defaults:
302+
run:
303+
shell: bash
304+
strategy:
305+
matrix:
306+
os: ['ubuntu-22.04', 'macos-14', 'windows-2022']
307+
steps:
308+
- uses: actions/checkout@v4
309+
with:
310+
fetch-depth: 0
311+
312+
- name: install conda with conda-forge channel
313+
uses: conda-incubator/setup-miniconda@v3
314+
with:
315+
miniforge-version: latest
316+
python-version: "3.13"
317+
318+
- name: setup environment
319+
run: |
320+
pip install build
321+
conda install libmetatensor-torch "libtorch=*=cpu"
322+
323+
echo "$CONDA_PREFIX"
324+
echo "CMAKE_PREFIX_PATH=$CONDA_PREFIX" >> "$GITHUB_ENV"
325+
326+
- name: build libmetatomic-torch
327+
run: |
328+
echo CMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH
329+
cmake -B build-metatomic-torch -S metatomic-torch -DCMAKE_INSTALL_PREFIX=$CMAKE_PREFIX_PATH -DCMAKE_BUILD_TYPE=Debug
330+
cmake --build build-metatomic-torch --config Debug
331+
cmake --install build-metatomic-torch --config Debug
332+
333+
- name: build metatomic-torch wheels
334+
run: |
335+
python -m build python/metatomic_torch --wheel --outdir=dist/
336+
unzip -l dist/metatomic_torch*.whl | grep "_external.py"
337+
env:
338+
METATOMIC_TORCH_PYTHON_USE_EXTERNAL_LIB: "ON"

0 commit comments

Comments
 (0)