-
Notifications
You must be signed in to change notification settings - Fork 7
445 lines (431 loc) · 14.6 KB
/
wheel.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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
name: Python Wheels
on:
workflow_dispatch:
release:
types: ['released', 'prereleased']
env:
PACKAGE_VERSION: "1.0.0a9"
PACKAGE_NAME: alpaqa
C_EXTENSIONS: _alpaqa
jobs:
generate-stubs:
runs-on: ubuntu-latest
container:
image: ubuntu:jammy
env:
HOST: 'x86_64-centos7-linux-gnu'
PYTHON_VERSION: '3.11'
CMAKE_C_COMPILER_LAUNCHER: ccache
CMAKE_CXX_COMPILER_LAUNCHER: ccache
CCACHE_DIR: /root/.ccache
steps:
# Git clone
- name: Install git
run: apt -y update && apt -y install --no-install-recommends git ca-certificates
- uses: actions/checkout@v3
with:
submodules: recursive
# Tools
- name: Install tools
uses: ./.github/workflows/toolchain
with:
host: ${{ env.HOST }}
python-version: ${{ env.PYTHON_VERSION }}
pypy: ''
# Ccache
- name: Prepare ccache directory
run: mkdir -p "${{ env.CCACHE_DIR }}"
- name: Cache ccache
uses: actions/cache@v3
with:
path: ${{ env.CCACHE_DIR }}
key: ${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ env.HOST }}-ccache-${{ github.run_id }}
restore-keys: ${{ runner.os }}-${{ env.PYTHON_VERSION }}-${{ env.HOST }}-ccache
# Pip install dependencies
- name: Install Python dependencies
run: python${{ env.PYTHON_VERSION }} -m pip install -U pip build pybind11-stubgen py-build-cmake~=0.2.0a5
# Build
- name: Native build
run: |
host="${{ env.HOST }}"
staging="/opt/$host"
pbc_cli="python${{ env.PYTHON_VERSION }} -m py_build_cmake.cli"
$pbc_cli -B native-build configure -- \
-D CMAKE_C_COMPILER="$staging/x-tools/$host/bin/$host-gcc" \
-D CMAKE_CXX_COMPILER="$staging/x-tools/$host/bin/$host-g++" \
-D CMAKE_Fortran_COMPILER="$staging/x-tools/$host/bin/$host-gfortran" \
-D USE_GLOBAL_PYBIND11=On \
-D CMAKE_FIND_ROOT_PATH="$staging/pybind11;$staging/eigen-master;$staging/casadi"
$pbc_cli -B native-build build -- -t ${{ env.C_EXTENSIONS }}
$pbc_cli -B native-build install --component python_stubs -- --prefix "$PWD/staging/python"
tar cf stubs.tar -C "$PWD/staging" python
# Upload
- name: Upload stubs
uses: actions/upload-artifact@v3
with:
name: stubs
retention-days: 1
path: stubs.tar
build-linux:
needs: [generate-stubs]
runs-on: ubuntu-latest
container:
image: ubuntu:jammy
strategy:
matrix:
pypy: ['', pypy]
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
host: [x86_64-centos7-linux-gnu, armv7-neon-linux-gnueabihf, armv6-rpi-linux-gnueabihf, aarch64-rpi3-linux-gnu]
include:
- python-version: '3.8'
pypy-version: '7.3.11'
- python-version: '3.9'
pypy-version: '7.3.12'
- python-version: '3.10'
pypy-version: '7.3.12'
exclude:
- pypy: pypy
python-version: '3.11'
- pypy: pypy
python-version: '3.12'
- pypy: pypy
host: armv7-neon-linux-gnueabihf
- pypy: pypy
host: armv6-rpi-linux-gnueabihf
env:
CMAKE_C_COMPILER_LAUNCHER: ccache
CMAKE_CXX_COMPILER_LAUNCHER: ccache
CCACHE_DIR: /root/.ccache
steps:
# Git clone
- name: Install git
run: apt -y update && apt -y install --no-install-recommends git ca-certificates
- uses: actions/checkout@v3
with:
submodules: recursive
# Tools
- name: Install tools
uses: ./.github/workflows/toolchain
with:
host: ${{ matrix.host }}
python-version: ${{ matrix.python-version }}
pypy: ${{ matrix.pypy }}
pypy-version: ${{ matrix.pypy-version }}
# Ccache
- name: Prepare ccache directory
run: mkdir -p "${{ env.CCACHE_DIR }}"
- name: Cache ccache
uses: actions/cache@v3
with:
path: ${{ env.CCACHE_DIR }}
key: ${{ runner.os }}-${{ matrix.pypy }}${{ matrix.python-version }}-${{ matrix.host }}-ccache-${{ github.run_id }}
restore-keys: ${{ runner.os }}-${{ matrix.pypy }}${{ matrix.python-version }}-${{ matrix.host }}-ccache
# Pip install dependencies
- name: Install Python dependencies
run: python${{ matrix.python-version }} -m pip install -U pip build pybind11-stubgen py-build-cmake~=0.2.0a5
# Download stubs
- name: Download stubs
uses: actions/download-artifact@v3
with:
name: stubs
- name: Extract stubs
run: tar xf stubs.tar
# Build
- name: Build wheels
run: |
host="${{ matrix.host }}"
staging="/opt/$host"
cat > ninja-debug-release.cross.toml <<- EOF
[cmake]
config = ["Debug", "Release"]
generator = "Ninja Multi-Config"
[cmake.options]
CMAKE_FIND_ROOT_PATH = "$staging/pybind11;$staging/eigen-master;$staging/casadi"
USE_GLOBAL_PYBIND11 = "On"
EOF
python${{ matrix.python-version }} -m build -w . \
-C--cross="$PWD/ninja-debug-release.cross.toml" \
-C--cross="$staging/$host.py-build-cmake.cross.toml"
python${{ matrix.python-version }} -m build -w python/alpaqa-debug \
-C--cross="$PWD/ninja-debug-release.cross.toml" \
-C--cross="$staging/$host.py-build-cmake.cross.toml" \
-o dist-debug
env:
CFLAGS: '-static-libgcc'
CXXFLAGS: '-static-libgcc -static-libstdc++'
# Upload
- name: Upload Wheels
uses: actions/upload-artifact@v3
with:
name: whl-linux
retention-days: 1
path: dist/*.whl
- name: Upload debug Wheels
uses: actions/upload-artifact@v3
with:
name: whl-debug-linux
retention-days: 1
path: dist-debug/*.whl
build-linux-src:
runs-on: ubuntu-latest
container:
image: ubuntu:jammy
env:
HOST: 'x86_64-centos7-linux-gnu'
PYTHON_VERSION: '3.11'
steps:
# Git clone
- name: Install git
run: apt -y update && apt -y install --no-install-recommends git ca-certificates
- uses: actions/checkout@v3
with:
submodules: recursive
# Tools
- name: Install tools
uses: ./.github/workflows/toolchain
with:
host: ${{ env.HOST }}
python-version: ${{ env.PYTHON_VERSION }}
pypy: ''
# Pip install dependencies
- name: Install Python dependencies
run: python${{ env.PYTHON_VERSION }} -m pip install -U pip build
# Build
- name: Build wheels
run: |
host="${{ env.HOST }}"
staging="/opt/$host"
cat > ninja-debug.cross.toml <<- EOF
[cmake]
config = ["Debug"]
generator = "Ninja Multi-Config"
[cmake.options]
CMAKE_FIND_ROOT_PATH = "$staging/pybind11;$staging/eigen-master;$staging/casadi"
USE_GLOBAL_PYBIND11 = "On"
EOF
python${{ env.PYTHON_VERSION }} -m build . \
-C--cross="$PWD/ninja-debug.cross.toml" \
-C--cross="$staging/$host.py-build-cmake.cross.toml"
env:
CFLAGS: '-static-libgcc'
CXXFLAGS: '-static-libgcc -static-libstdc++'
# Upload
- name: Upload source
uses: actions/upload-artifact@v3
with:
name: src-dist
retention-days: 1
path: dist/*.tar.gz
test-linux:
needs: [build-linux]
runs-on: ubuntu-latest
container: python:${{ matrix.python-version }}-bullseye
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/download-artifact@v3
with:
name: whl-linux
path: dist
- name: Test
run: |
python3 -m pip install -U pip cmake ninja
python3 -m pip install --find-links=dist "${PACKAGE_NAME}[test]==${PACKAGE_VERSION}"
pytest -rP
build-windows:
needs: [generate-stubs]
runs-on: windows-2022
strategy:
matrix:
arch: ['AMD64', 'ARM64', 'x86']
python-id: ['cp38-*', 'cp39-*', 'cp310-*', 'cp311-*']
include:
- arch: 'AMD64'
python-id: 'pp38-*'
- arch: 'AMD64'
python-id: 'pp39-*'
- arch: 'AMD64'
python-id: 'pp310-*'
exclude:
- arch: 'ARM64'
python-id: 'cp38-*'
env:
CXXFLAGS: "/bigobj"
CFLAGS: "/bigobj"
PYTHONUTF8: 1
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Cache dependencies
id: cache-dep
uses: actions/cache@v3
with:
path: deps
key: deps-${{ runner.os }}-${{ matrix.arch }}-${{ hashFiles('scripts/install-eigen.ps1', 'scripts/install-casadi-static.ps1') }}
- name: Install Python dependencies
if: steps.cache-dep.outputs.cache-hit != 'true'
shell: powershell
run: |
mkdir $env:VIRTUAL_ENV
./scripts/install-eigen.ps1
./scripts/install-casadi-static.ps1
env:
VIRTUAL_ENV: ${{ github.workspace }}/deps
CMAKE_TOOLCHAIN_FILE: ${{ github.workspace }}/scripts/toolchains/Win-${{ matrix.arch }}.cmake
# Download stubs
- name: Download stubs
if: ${{ matrix.arch == 'ARM64' }}
uses: actions/download-artifact@v3
with:
name: stubs
- name: Extract stubs
if: ${{ matrix.arch == 'ARM64' }}
run: tar xf stubs.tar
- name: Build wheels
uses: pypa/cibuildwheel@39a63b5912f086dd459cf6fcb13dcdd3fe3bc24d
with:
output-dir: dist
env:
CIBW_BUILD: ${{ matrix.python-id }}
CIBW_ARCHS: ${{ matrix.arch }}
CIBW_TEST_SKIP: "*-{win32,win_arm64} pp*" # no CasADi binaries
CMAKE_PREFIX_PATH: ${{ github.workspace }}/deps
- name: Upload
uses: actions/upload-artifact@v3
with:
name: whl-windows
retention-days: 1
path: dist/*.whl
build-macos:
runs-on: macos-12
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
env:
CMAKE_C_COMPILER_LAUNCHER: ccache
CMAKE_CXX_COMPILER_LAUNCHER: ccache
CCACHE_DIR: /tmp/.ccache
MACOSX_DEPLOYMENT_TARGET: '10.9'
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/setup-python@v4
id: python
name: Install Python
with:
python-version: ${{ matrix.python-version }}
- name: Install ccache
run: brew install ccache && ccache --version
- name: Prepare ccache directory
run: mkdir -p "${{ env.CCACHE_DIR }}"
- name: Cache ccache
uses: actions/cache@v3
with:
path: ${{ env.CCACHE_DIR }}
key: ${{ runner.os }}-${{ matrix.python-version }}-ccache-${{ github.run_id }}
restore-keys: ${{ runner.os }}-${{ matrix.python-version }}-ccache
- name: Cache Virtual Environment
id: cache-venv
uses: actions/cache@v3
with:
path: py-venv
key: ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{ hashFiles('scripts/install-eigen.sh', 'scripts/install-casadi-static.sh') }}
- name: Install Python dependencies
if: steps.cache-venv.outputs.cache-hit != 'true'
run: |
python -m venv py-venv
source ./py-venv/bin/activate
python -m pip install -U pip build cmake ninja
./scripts/install-eigen.sh
./scripts/install-casadi-static.sh
- name: Build
run: |
source ./py-venv/bin/activate
CMAKE_PREFIX_PATH="$VIRTUAL_ENV:$CMAKE_PREFIX_PATH" \
_PYTHON_HOST_PLATFORM='macosx-10.9-universal2' \
ARCHFLAGS='-arch arm64 -arch x86_64' \
python -m build -w .
- name: Upload
uses: actions/upload-artifact@v3
with:
name: whl-macos
retention-days: 1
path: dist/*.whl
test-macos:
needs: [build-macos]
runs-on: macos-12
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: ${{ matrix.python-version }}
- uses: actions/download-artifact@v3
with:
name: whl-macos
path: dist
- name: Test
run: |
python3 -m pip install -U pip cmake ninja
python3 -m pip install --find-links=dist "${PACKAGE_NAME}[test]==${PACKAGE_VERSION}"
pytest -rP
check-release:
if: ${{ github.event.action == 'released' || github.event.action == 'prereleased' }}
needs: [test-linux, build-linux-src, build-windows, test-macos]
runs-on: ubuntu-latest
container: python:3.11-bullseye
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: whl-linux
path: dist
- name: Install package
run: python -m pip install --no-deps --no-index --find-links=dist ${PACKAGE_NAME}==${PACKAGE_VERSION}
- name: Check package version
run: |
[ "${{ github.event.release.tag_name }}" == $(python -c 'from importlib.metadata import version as v; print(v("${{ env.PACKAGE_NAME }}"))') ]
shell: bash
release:
needs: [check-release]
if: ${{ github.event.action == 'released' || github.event.action == 'prereleased' }}
runs-on: ubuntu-latest
environment:
name: release
url: https://pypi.org/p/alpaqa
permissions:
id-token: write # mandatory for trusted publishing
steps:
- uses: actions/download-artifact@v3
with:
name: whl-linux
path: dist
- uses: actions/download-artifact@v3
with:
name: whl-debug-linux
path: dist
- uses: actions/download-artifact@v3
with:
name: whl-windows
path: dist
- uses: actions/download-artifact@v3
with:
name: whl-macos
path: dist
- uses: actions/download-artifact@v3
with:
name: src-dist
path: dist
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@b7f401de30cb6434a1e19f805ff006643653240e