-
Notifications
You must be signed in to change notification settings - Fork 0
347 lines (305 loc) · 12.2 KB
/
build-wheels.yml
File metadata and controls
347 lines (305 loc) · 12.2 KB
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
name: Build and Test Wheels
on:
push:
branches: [main, master]
pull_request:
workflow_dispatch:
inputs:
ref:
description: 'Git ref to build from (tag like v0.1.6)'
required: false
type: string
workflow_call:
inputs:
ref:
description: 'Git ref to build from'
required: false
type: string
env:
# CFD C library version to build against
# v0.2.0 adds 3D support, Poisson solver, GPU management, logging
CFD_VERSION: "v0.2.0"
jobs:
build_wheel:
name: Build ${{ matrix.variant }} wheel on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
variant: [cpu, cuda]
exclude:
# macOS doesn't support CUDA
- os: macos-latest
variant: cuda
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ inputs.ref || github.ref }}
- name: Checkout CFD C library
uses: actions/checkout@v4
with:
repository: ${{ github.repository_owner }}/cfd
ref: ${{ env.CFD_VERSION }}
path: cfd
fetch-depth: 0
- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: "3.9"
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
cache-dependency-glob: "pyproject.toml"
- name: Install build dependencies
run: uv pip install --system build scikit-build-core setuptools-scm
# ============ CPU-only builds ============
# Note: Linux CPU build is done inside manylinux container (see Build wheel step)
- name: Build CFD library (Linux - CPU only)
if: runner.os == 'Linux' && matrix.variant == 'cpu'
run: |
echo "Linux CPU build will be done inside manylinux container"
echo "Skipping host build to ensure glibc compatibility"
- name: Build CFD library (macOS - CPU only)
if: runner.os == 'macOS'
run: |
cmake -S cfd -B cfd/build \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DCFD_ENABLE_CUDA=OFF
cmake --build cfd/build --config Release
echo "=== CFD library built (CPU-only) ==="
ls -la cfd/build/lib/
- name: Build CFD library (Windows - CPU only)
if: runner.os == 'Windows' && matrix.variant == 'cpu'
run: |
# Build CPU-only for maximum compatibility
cmake -S cfd -B cfd/build `
-DCMAKE_BUILD_TYPE=Release `
-DBUILD_SHARED_LIBS=OFF `
-DCMAKE_POSITION_INDEPENDENT_CODE=ON `
-DCFD_ENABLE_CUDA=OFF
cmake --build cfd/build --config Release
echo "=== CFD library built (CPU-only) ==="
dir cfd\build\lib\Release
# ============ CUDA builds ============
# Note: Linux CUDA build is done inside NVIDIA manylinux container (see Build wheel step)
- name: Build CFD library (Linux with CUDA)
if: runner.os == 'Linux' && matrix.variant == 'cuda'
run: |
echo "Linux CUDA build will be done inside NVIDIA manylinux container"
echo "Skipping host build to ensure manylinux compatibility"
- name: Install CUDA Toolkit (Windows)
if: runner.os == 'Windows' && matrix.variant == 'cuda'
uses: Jimver/cuda-toolkit@v0.2.18
with:
cuda: '12.4.0'
method: 'network'
# visual_studio_integration required for CMake to find CUDA toolset
sub-packages: '["nvcc", "cudart", "nvrtc_dev", "cublas_dev", "cusparse_dev", "visual_studio_integration"]'
- name: Build CFD library (Windows with CUDA)
if: runner.os == 'Windows' && matrix.variant == 'cuda'
run: |
# Build with CUDA for Turing+ architectures
cmake -S cfd -B cfd/build `
-DCMAKE_BUILD_TYPE=Release `
-DBUILD_SHARED_LIBS=OFF `
-DCMAKE_POSITION_INDEPENDENT_CODE=ON `
-DCFD_ENABLE_CUDA=ON `
-DCFD_CUDA_ARCHITECTURES="75;80;86;89;90"
cmake --build cfd/build --config Release
echo "=== CFD library built with CUDA ==="
dir cfd\build\lib\Release
# ============ Build wheels ============
# Linux wheels must be built inside manylinux container for glibc compatibility
- name: Build wheel (Linux - CPU)
if: runner.os == 'Linux' && matrix.variant == 'cpu'
run: |
docker run --rm \
-v "${{ github.workspace }}:/workspace" \
-w /workspace \
-e CFD_STATIC_LINK=ON \
-e CFD_USE_STABLE_ABI=ON \
quay.io/pypa/manylinux_2_28_x86_64 \
bash -c "
set -e
# Build CFD C library inside container
cmake -S cfd -B cfd/build \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DCFD_ENABLE_CUDA=OFF
cmake --build cfd/build --config Release
# Build Python wheel
export CFD_ROOT=/workspace/cfd
/opt/python/cp39-cp39/bin/pip install scikit-build-core setuptools-scm
/opt/python/cp39-cp39/bin/pip wheel . --no-deps --wheel-dir dist_raw/
# Repair wheel for manylinux compatibility
/opt/python/cp39-cp39/bin/pip install auditwheel
auditwheel repair dist_raw/*.whl --plat manylinux_2_28_x86_64 -w dist/
"
echo "=== Wheel built (manylinux) ==="
ls -la dist/
- name: Build wheel (Linux - CUDA)
if: runner.os == 'Linux' && matrix.variant == 'cuda'
run: |
# Build inside NVIDIA's manylinux-compatible CUDA container
# Rocky Linux 8 is manylinux_2_28 compatible
# Use --user to match host UID/GID for proper file ownership
docker run --rm \
-v "${{ github.workspace }}:/workspace" \
-w /workspace \
-e CFD_STATIC_LINK=ON \
-e CFD_USE_STABLE_ABI=ON \
-e HOME=/tmp \
nvidia/cuda:12.4.0-devel-rockylinux8 \
bash -c "
set -e
# Install build tools (git for CMake FetchContent)
dnf install -y cmake git python3.11 python3.11-pip python3.11-devel
# Install patchelf via pip (EPEL version is too old for auditwheel)
python3.11 -m pip install patchelf
# Clean any previous build artifacts
rm -rf cfd/build build dist dist_raw
# Build CFD C library with CUDA
# 75=Turing, 80=Ampere, 86=Ampere, 89=Ada, 90=Hopper
cmake -S cfd -B cfd/build \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DCFD_ENABLE_CUDA=ON \
-DCFD_CUDA_ARCHITECTURES='75;80;86;89;90'
cmake --build cfd/build --config Release
# Build Python wheel
export CFD_ROOT=/workspace/cfd
python3.11 -m pip install scikit-build-core setuptools-scm
python3.11 -m pip wheel . --no-deps --wheel-dir dist_raw/
# Repair wheel for manylinux compatibility
python3.11 -m pip install auditwheel
auditwheel repair dist_raw/*.whl --plat manylinux_2_28_x86_64 -w dist/
# Fix permissions for host user
chmod -R 777 dist/
"
echo "=== Wheel built (CUDA manylinux) ==="
ls -la dist/
- name: Build wheel (macOS)
if: runner.os == 'macOS'
env:
CFD_ROOT: ${{ github.workspace }}/cfd
CFD_STATIC_LINK: "ON"
CFD_USE_STABLE_ABI: "ON"
run: |
pip wheel . --no-deps --wheel-dir dist/
echo "=== Wheel built ==="
ls -la dist/
- name: Build wheel (Windows)
if: runner.os == 'Windows'
env:
CFD_ROOT: ${{ github.workspace }}/cfd
CFD_STATIC_LINK: "ON"
CFD_USE_STABLE_ABI: "ON"
run: |
pip wheel . --no-deps --wheel-dir dist/
echo "=== Wheel built ==="
dir dist
- name: Inspect wheel contents
run: |
python -c "
import glob, zipfile
for wheel in glob.glob('dist/*.whl'):
print(f'=== Contents of {wheel} ===')
with zipfile.ZipFile(wheel) as zf:
for name in zf.namelist():
print(name)
"
# Upload wheels with variant in artifact name
# Note: Wheel filenames are standard (no variant suffix) to comply with PEP 427
# The variant (cpu/cuda) is encoded in the artifact name for differentiation
- uses: actions/upload-artifact@v4
with:
name: wheel-${{ matrix.os }}-${{ matrix.variant }}
path: dist/*.whl
test_wheel:
name: Test ${{ matrix.variant }} wheel on ${{ matrix.os }} with Python ${{ matrix.python }}
needs: [build_wheel]
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python: ["3.9", "3.13"]
variant: [cpu, cuda]
exclude:
# macOS doesn't have CUDA wheels
- os: macos-latest
variant: cuda
steps:
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v5
with:
python-version: "${{ matrix.python }}"
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: false
# Install CUDA runtime for CUDA wheel tests (must match build version)
- name: Install CUDA Toolkit (Linux - for testing)
if: runner.os == 'Linux' && matrix.variant == 'cuda'
run: |
# Install CUDA runtime libraries via apt (more reliable than runfile installer)
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt-get update
sudo apt-get install -y cuda-cudart-12-4
echo "LD_LIBRARY_PATH=/usr/local/cuda-12.4/lib64:$LD_LIBRARY_PATH" >> $GITHUB_ENV
- name: Install CUDA Toolkit (Windows - for testing)
if: runner.os == 'Windows' && matrix.variant == 'cuda'
uses: Jimver/cuda-toolkit@v0.2.18
with:
cuda: '12.4.0'
- uses: actions/download-artifact@v4
with:
name: wheel-${{ matrix.os }}-${{ matrix.variant }}
path: dist
- name: Install wheel (Unix)
if: runner.os != 'Windows'
run: |
python -m pip install dist/*.whl
python -m pip install pytest numpy
- name: Install wheel (Windows)
if: runner.os == 'Windows'
run: |
python -m pip install (Get-ChildItem dist/*.whl).FullName
python -m pip install pytest numpy
- name: Test import (Unix)
if: runner.os != 'Windows'
run: |
cd /tmp
python -c "
import cfd_python
print('Package loaded:', cfd_python.__file__)
print('Version:', cfd_python.__version__)
print('Has list_solvers:', hasattr(cfd_python, 'list_solvers'))
if hasattr(cfd_python, 'list_solvers'):
print('Solvers:', cfd_python.list_solvers())
"
- name: Test import (Windows)
if: runner.os == 'Windows'
run: |
cd $env:TEMP
python -c "import cfd_python; print('Package loaded:', cfd_python.__file__); print('Version:', cfd_python.__version__); print('Has list_solvers:', hasattr(cfd_python, 'list_solvers')); print('Solvers:', cfd_python.list_solvers()) if hasattr(cfd_python, 'list_solvers') else None"
- uses: actions/checkout@v4
with:
sparse-checkout: tests
sparse-checkout-cone-mode: false
- name: Run tests (Unix)
if: runner.os != 'Windows'
run: |
cd /tmp
pytest $GITHUB_WORKSPACE/tests/ -v
- name: Run tests (Windows)
if: runner.os == 'Windows'
run: |
cd $env:TEMP
pytest "$env:GITHUB_WORKSPACE\tests" -v