-
Notifications
You must be signed in to change notification settings - Fork 4
344 lines (283 loc) · 11.9 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
name: Build wheels
on:
push:
branches:
- main
pull_request:
workflow_dispatch:
release:
types: [published]
permissions: # Ensure the workflow has permission to push changes
contents: write # Allow write access for pushing to the repository
jobs:
bump_version:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v4
with:
persist-credentials: true
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install bump2version
run: python -m pip install bump2version
- name: Bump version (patch)
run: |
bump2version patch --current-version $(grep -Eo 'version="[^"]*' setup.py | cut -d'"' -f2) setup.py
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Commit and push version bump
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"
git commit -am "Bump version"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build_wheels:
runs-on: ${{ matrix.os }}
needs: bump_version
strategy:
matrix:
os: [ubuntu-latest,macos-latest,windows-latest]
python-version: ["3.9","3.10"]
include:
- os: ubuntu-latest
arch: aarch64
python-version: '3.9'
- os: macos-latest
arch: arm64
python-version: '3.9'
- os: macos-latest
arch: arm64
python-version: '3.10'
# Specific inclusion for Windows x86 architecture
- os: windows-latest
arch: amd64
python-version: '3.9'
- os: windows-latest
arch: amd64
python-version: '3.10'
steps:
- name: Checkout the code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
# Clean up on Unix-like systems
- name: Clean up previous builds (Unix)
if: runner.os != 'Windows'
run: |
rm -rf build dist *.egg-info class-sz/python/classy_sz.*so class-sz/python/classy_sz.*egg-info
- name: Set CIBW_BUILD for the correct CPython version
run: |
if [ "${{ matrix.python-version }}" == "3.9" ]; then
echo "CIBW_BUILD=cp39-*" >> $GITHUB_ENV
elif [ "${{ matrix.python-version }}" == "3.10" ]; then
echo "CIBW_BUILD=cp310-*" >> $GITHUB_ENV
fi
shell: bash
# - name: Install system dependencies (Linux)
# if: matrix.os == 'ubuntu-latest'
# run: |
# sudo apt-get install -y libgsl-dev libfftw3-dev
# echo "Include paths for GSL and FFTW:"
# dpkg -L libgsl-dev | grep '/include'
# dpkg -L libfftw3-dev | grep '/include'
# echo "Library paths for GSL and FFTW:"
# dpkg -L libgsl-dev | grep '/lib'
# dpkg -L libfftw3-dev | grep '/lib'
- name: Install cibuildwheel
run: python -m pip install cibuildwheel==2.14.1
shell: bash
# Build wheels for Linux (with custom build options)
- name: Build wheels for Linux
if: matrix.os == 'ubuntu-latest'
env:
CIBW_ENVIRONMENT: "LDFLAGS='-L/usr/lib/x86_64-linux-gnu' CFLAGS='-I/usr/include' LIBRARY_PATH='/usr/lib/x86_64-linux-gnu:$LIBRARY_PATH' C_INCLUDE_PATH='/usr/include:$C_INCLUDE_PATH' LD_LIBRARY_PATH='/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH'"
#CIBW_BUILD: "cp39-manylinux_x86_64" # Constrain build to cp39-manylinux_x86_64
CIBW_BUILD: ${{ env.CIBW_BUILD }}
CIBW_SKIP: "cp27-* cp34-* cp35-* cp36-* cp37-* cp38-* pp* *-manylinux_i686 *musllinux*"
CIBW_BEFORE_BUILD: |
# Build GSL from source
curl -O https://ftp.gnu.org/gnu/gsl/gsl-2.7.1.tar.gz
tar -xzf gsl-2.7.1.tar.gz
cd gsl-2.7.1
./configure --prefix=/usr/local
make
make install
# Go back to the root directory to build FFTW
cd ..
# Build FFTW from source
curl -O http://www.fftw.org/fftw-3.3.10.tar.gz
tar -xzf fftw-3.3.10.tar.gz
cd fftw-3.3.10
./configure --prefix=/usr/local --enable-shared
make
make install
# Print to check the files are correctly installed
# echo "Contents of /usr/local/include/gsl:"
# ls -la /usr/local/include/gsl/
# echo "Contents of /usr/local/include:"
# ls -la /usr/local/include/
# echo "Contents of /usr/local/lib:"
# ls -la /usr/local/lib/
run: |
# # Check GSL library and include files
# if [ -f /usr/lib/x86_64-linux-gnu/libgsl.so ]; then
# echo "GSL library found in /usr/lib/x86_64-linux-gnu/"
# else
# echo "GSL library not found in /usr/lib/x86_64-linux-gnu/"; exit 1;
# fi
# if [ -f /usr/include/gsl/gsl_sf_bessel.h ]; then
# echo "GSL include files found in /usr/include/gsl/"
# else
# echo "GSL include files not found in /usr/include/gsl/"; exit 1;
# fi
# # Check FFTW library and include files
# if [ -f /usr/lib/x86_64-linux-gnu/libfftw3.so ]; then
# echo "FFTW library found in /usr/lib/x86_64-linux-gnu/"
# else
# echo "FFTW library not found in /usr/lib/x86_64-linux-gnu/"; exit 1;
# fi
# if [ -f /usr/include/fftw3.h ]; then
# echo "FFTW include files found in /usr/include/"
# else
# echo "FFTW include files not found in /usr/include/"; exit 1;
# fi
python -m cibuildwheel --output-dir wheelhouse
- name: Install dependencies on macOS
if: matrix.os == 'macos-latest'
run: |
brew install gsl fftw libomp
chmod +x select_makefile.sh
./select_makefile.sh
make clean
# Check that omp.h is available in the include directory
if [ -f /opt/homebrew/opt/libomp/include/omp.h ]; then
echo "omp.h found"
else
echo "omp.h not found" && exit 1
fi
# Check that gsl_integration.h and fftw3.h are available
if [ -f /opt/homebrew/opt/gsl/include/gsl/gsl_integration.h ]; then
echo "gsl_integration.h found"
else
echo "gsl_integration.h not found" && exit 1
fi
if [ -f /opt/homebrew/opt/fftw/include/fftw3.h ]; then
echo "fftw3.h found"
else
echo "fftw3.h not found" && exit 1
fi
export LIBRARY_PATH=/opt/homebrew/opt/libomp/lib:$LIBRARY_PATH
export C_INCLUDE_PATH=/opt/homebrew/opt/libomp/include:$C_INCLUDE_PATH
export DYLD_LIBRARY_PATH=/opt/homebrew/opt/libomp/lib:$DYLD_LIBRARY_PATH # (Mac M1 users only)
working-directory: class-sz
# Build wheels for macOS (with Apple Silicon support)
- name: Build wheels for macOS
if: matrix.os == 'macos-latest'
env:
# CIBW_BUILD: "cp39-macosx_arm64" # Restrict to cp39-macosx_arm64
CIBW_BUILD: ${{ env.CIBW_BUILD }}
CIBW_ARCHS: "arm64"
CIBW_SKIP: "cp27-* cp34-* cp35-* cp36-* cp37-* cp38-* pp*"
LDFLAGS: "-L/opt/homebrew/opt/libomp/lib -L/opt/homebrew/opt/gsl/lib -L/opt/homebrew/opt/fftw/lib"
CPPFLAGS: "-I/opt/homebrew/opt/libomp/include -I/opt/homebrew/opt/gsl/include -I/opt/homebrew/opt/fftw/include"
LIBRARY_PATH: "/opt/homebrew/opt/libomp/lib:/opt/homebrew/opt/gsl/lib:/opt/homebrew/opt/fftw/lib:$LIBRARY_PATH"
C_INCLUDE_PATH: "/opt/homebrew/opt/libomp/include:/opt/homebrew/opt/gsl/include:/opt/homebrew/opt/fftw/include:$C_INCLUDE_PATH"
DYLD_LIBRARY_PATH: "/opt/homebrew/opt/libomp/lib:/opt/homebrew/opt/gsl/lib:/opt/homebrew/opt/fftw/lib:$DYLD_LIBRARY_PATH"
run: python -m cibuildwheel --output-dir wheelhouse
# Build wheels for Windows using bash
- name: Build wheels for Windows
if: matrix.os == 'windows-latest'
env:
CIBW_BUILD: ${{ env.CIBW_BUILD }}
CIBW_SKIP: "cp27-* cp34-* cp35-* cp36-* cp37-* cp38-* pp* *-win32"
CIBW_ARCHS: "x86" # Force cibuildwheel to use x86 only
LIBRARY_PATH: "$(pwd)/fftw/lib;$(pwd)/gsl/lib"
C_INCLUDE_PATH: "$(pwd)/fftw/include;$(pwd)/gsl/include"
CIBW_BEFORE_BUILD: |
curl -O https://ftp.gnu.org/gnu/gsl/gsl-2.7.1.tar.gz
tar -xzf gsl-2.7.1.tar.gz
cd gsl-2.7.1
./configure --prefix=/usr/local
make
make install
cd ..
curl -O http://www.fftw.org/fftw-3.3.10.tar.gz
tar -xzf fftw-3.3.10.tar.gz
cd fftw-3.3.10
./configure --prefix=/usr/local --enable-shared
make
make install
run: python -m cibuildwheel --output-dir wheelhouse
shell: bash
- name: Install dependencies for source distribution
run: |
python -m pip install build Cython numpy classy_szfast
shell: bash
- name: Build source distribution (sdist)
run: python -m build --sdist --outdir dist
shell: bash
- name: Upload built distributions (wheels and sdist)
uses: actions/upload-artifact@v4
with:
name: wheels-and-sdist-${{ matrix.os }}-${{ matrix.python-version }}
path: |
wheelhouse/*.whl
dist/*.tar.gz
- name: Install the built wheel
run: |
python -m pip install wheelhouse/*.whl
shell: bash
- name: Check import of classy_sz
run: |
python -c "import classy_sz; print('classy_sz imported successfully')"
shell: bash
publish_wheels:
runs-on: ubuntu-latest
needs: build_wheels
strategy:
matrix:
os: [ubuntu-latest,macos-latest]
python-version: ["3.9","3.10"]
steps:
- name: Checkout the code
uses: actions/checkout@v4
- name: Download built wheels and sdist
uses: actions/download-artifact@v4
with:
name: wheels-and-sdist-${{ matrix.os }}-${{ matrix.python-version }}
path: wheels-and-sdist-${{ matrix.os }}-${{ matrix.python-version }}
- name: Install dependencies for uploading
run: python -m pip install -U pip twine
- name: Upload distributions to PyPI
run: |
ls
ls -R wheels-and-sdist-${{ matrix.os }}-${{ matrix.python-version }}
mkdir -p wheelhouse dist
if [ -d "wheels-and-sdist-${{ matrix.os }}-${{ matrix.python-version }}/wheelhouse" ]; then
mv wheels-and-sdist-${{ matrix.os }}-${{ matrix.python-version }}/wheelhouse/* wheelhouse/
fi
if [ -d "wheels-and-sdist-${{ matrix.os }}-${{ matrix.python-version }}/dist" ]; then
mv wheels-and-sdist-${{ matrix.os }}-${{ matrix.python-version }}/dist/* dist/
fi
if [ "$(ls -A wheelhouse)" ]; then
echo "Uploading wheels..."
twine upload wheelhouse/*
else
echo "No wheels to upload."
fi
if [ -d "dist" ] && [ "$(ls -A dist)" ]; then
echo "Uploading source distribution to PyPI..."
twine upload dist/*.tar.gz || echo "Source distribution upload failed, probably cause it's already there continuing..."
else
echo "No source distribution to upload."
fi
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}