-
Notifications
You must be signed in to change notification settings - Fork 81
261 lines (225 loc) · 9.66 KB
/
python-wheel-workflow.yml
File metadata and controls
261 lines (225 loc) · 9.66 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
name: Build Python Wheels
on:
workflow_dispatch:
inputs:
precompiledRunId:
description: "Run ID of the precompiled-bin job whose artifacts should be used"
required: true
type: string
workflow_call:
inputs:
isNightly:
type: boolean
required: true
default: false
precompiledRunId:
type: string
required: true
jobs:
package-python-sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Update submodules
run: git submodule update --init --recursive tools/python_api
- name: Install uv
run: pip3 install uv
- name: Update nightly version
if: ${{ inputs.isNightly == true }}
run: |
uv venv
source .venv/bin/activate
python3 update-nightly-build-version.py
working-directory: scripts
- name: Package Python sdist
run: python package_tar.py
working-directory: scripts/pip-package
- name: Upload tarball
uses: actions/upload-artifact@v4
with:
name: python-sdist
path: scripts/pip-package/*.tar.gz
build-linux-wheels:
needs: package-python-sdist
# The 'runs-on' key is now inside the matrix
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
# Job 1: Native x86_64 build
- platform: x86_64
runner: ubuntu-latest # This is the standard x86_64 runner
os: linux
manylinux: _2_28
deployment-target: ''
# Job 2: Native aarch64 build
- platform: aarch64
runner: ubuntu-22.04-arm # This is a native ARM64 runner
os: linux
manylinux: _2_28
deployment-target: ''
# Job 3: macOS arm64 build
- platform: arm64
runner: macos-latest
os: macos
deployment-target: '13.3'
# Job 4: macOS x86_64 build
- platform: x86_64
runner: macos-15-intel
os: macos
deployment-target: '13.3'
# Job 5: Windows amd64 build
- platform: amd64
runner: windows-2022
os: windows
deployment-target: ''
env:
CIBW_PLATFORM: ${{ matrix.os }}
CIBW_BUILD: "cp310-* cp311-* cp312-* cp313-* cp314-*"
LBUG_PYTHON_PRECOMPILED_DIR: ${{ github.workspace }}/precompiled-liblbug
LBUG_PYTHON_CIBW_SOURCE_DIR: ${{ github.workspace }}/scripts/pip-package/cibw-source/sdist
# Let CIBW detect the arch, except explicitly set Windows wheel arch per matrix
CIBW_ARCHS: ${{ matrix.os == 'windows' && (matrix.platform == 'arm64' && 'ARM64' || 'AMD64') || 'auto' }}
# Set the manylinux image based on the detected arch (Linux only)
CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.os == 'linux' && format('manylinux{0}', matrix.manylinux) || '' }}
CIBW_MANYLINUX_AARCH64_IMAGE: ${{ matrix.os == 'linux' && format('manylinux{0}', matrix.manylinux) || '' }}
CIBW_BEFORE_ALL_LINUX: "command -v dnf && dnf install -y ccache || apk add --no-cache ccache"
CIBW_ENVIRONMENT_LINUX: ${{ matrix.os == 'linux' && 'LBUG_API_PRECOMPILED_LIB_PATH=/project/precompiled-liblbug/liblbug.a CMAKE_C_COMPILER_LAUNCHER=ccache CMAKE_CXX_COMPILER_LAUNCHER=ccache CCACHE_DIR=/project/.ccache' || '' }}
# Set deployment target for macOS, and Windows MSVC setup
CIBW_ENVIRONMENT_WINDOWS: ${{ matrix.os == 'windows' && format('DISTUTILS_USE_SDK=1 MSSdk=1 TMP={0} TEMP={0} LBUG_API_PRECOMPILED_LIB_PATH=$LBUG_API_PRECOMPILED_LIB_PATH', matrix.platform == 'arm64' && 'C:/t' || 'D:/t') || '' }}
CIBW_ENVIRONMENT_MACOS: ${{ matrix.os == 'macos' && format('MACOSX_DEPLOYMENT_TARGET={0} LBUG_API_PRECOMPILED_LIB_PATH={1}/precompiled-liblbug/liblbug.a CMAKE_C_COMPILER_LAUNCHER=ccache CMAKE_CXX_COMPILER_LAUNCHER=ccache CCACHE_DIR={1}/.ccache', matrix.deployment-target, github.workspace) || '' }}
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Update submodules
run: git submodule update --init --recursive tools/python_api
- name: Download sdist
uses: actions/download-artifact@v4
with:
name: python-sdist
path: scripts/pip-package/
- name: Find sdist file
shell: bash
run: echo "SDIST_FILE=$(ls scripts/pip-package/*.tar.gz)" >> $GITHUB_ENV
- name: Prepare wheel source tree
shell: bash
run: |
rm -rf scripts/pip-package/cibw-source
mkdir -p scripts/pip-package/cibw-source
tar -xzf "${SDIST_FILE}" -C scripts/pip-package/cibw-source
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install uv
run: python -m pip install uv
- name: Download precompiled liblbug
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LBUG_LIB_KIND: static
LBUG_LINUX_VARIANT: compat
LBUG_PRECOMPILED_RUN_ID: ${{ inputs.precompiledRunId }}
LBUG_TARGET_DIR: ${{ env.LBUG_PYTHON_PRECOMPILED_DIR }}
run: |
rm -rf "$LBUG_TARGET_DIR"
./scripts/download-liblbug.sh
- name: Inject precompiled lib into wheel source tree
shell: bash
run: |
rm -rf "${LBUG_PYTHON_CIBW_SOURCE_DIR}/precompiled-liblbug"
mkdir -p "${LBUG_PYTHON_CIBW_SOURCE_DIR}/precompiled-liblbug"
cp -R "${LBUG_PYTHON_PRECOMPILED_DIR}/." "${LBUG_PYTHON_CIBW_SOURCE_DIR}/precompiled-liblbug/"
if [ "$RUNNER_OS" = "Windows" ]; then
echo "LBUG_API_PRECOMPILED_LIB_PATH=${LBUG_PYTHON_CIBW_SOURCE_DIR}/precompiled-liblbug/lbug.lib" >> $GITHUB_ENV
fi
- name: Update nightly version
if: ${{ inputs.isNightly == true }}
shell: bash
run: |
uv venv
if [ "$RUNNER_OS" = "Windows" ]; then
source .venv/Scripts/activate
else
source .venv/bin/activate
fi
python update-nightly-build-version.py
working-directory: scripts
- name: Install cibuildwheel
if: matrix.os != 'windows'
run: |
uv venv
source .venv/bin/activate
uv pip install cibuildwheel
- name: Enable long paths (Windows)
if: matrix.os == 'windows'
run: |
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force
git config --system core.longpaths true
shell: pwsh
- name: Setup ccache for Windows wheel build
if: matrix.os == 'windows'
shell: cmd
run: |
choco install ccache -y
REM windows-11-arm runners do not reliably provide a D: drive, so ARM uses C:.
if "${{ matrix.platform }}"=="arm64" (
set "LB_CCACHE_DIR=C:\c"
set "LB_CCACHE_TEMPDIR=C:\t"
) else (
set "LB_CCACHE_DIR=D:\c"
set "LB_CCACHE_TEMPDIR=D:\t"
)
echo CMAKE_C_COMPILER_LAUNCHER=ccache>> %GITHUB_ENV%
echo CMAKE_CXX_COMPILER_LAUNCHER=ccache>> %GITHUB_ENV%
echo CCACHE_DIR=%LB_CCACHE_DIR%>> %GITHUB_ENV%
echo CCACHE_TEMPDIR=%LB_CCACHE_TEMPDIR%>> %GITHUB_ENV%
echo TMP=%LB_CCACHE_TEMPDIR%>> %GITHUB_ENV%
echo TEMP=%LB_CCACHE_TEMPDIR%>> %GITHUB_ENV%
if not exist "%LB_CCACHE_DIR%" mkdir "%LB_CCACHE_DIR%"
if not exist "%LB_CCACHE_TEMPDIR%" mkdir "%LB_CCACHE_TEMPDIR%"
ccache --set-config=max_size=2G
ccache --set-config=compression=true
ccache --set-config=cache_dir=%LB_CCACHE_DIR%
ccache --set-config=temporary_dir=%LB_CCACHE_TEMPDIR%
- name: Cache ccache directory (Windows)
if: matrix.os == 'windows'
uses: actions/cache@v4
with:
path: ${{ matrix.platform == 'arm64' && 'C:/c' || 'D:/c' }}
key: ${{ runner.os }}-${{ matrix.platform }}-ccache-wheel-${{ hashFiles('**/CMakeLists.txt', '**/*.cpp', '**/*.h') }}
restore-keys: |
${{ runner.os }}-${{ matrix.platform }}-ccache-wheel-
- name: Build wheels on ${{ matrix.platform }} (Windows)
if: matrix.os == 'windows'
shell: cmd
run: |
powershell.exe -Command "Add-MpPreference -ExclusionPath '${{ github.workspace }}'"
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
ccache -s
pipx run --spec cibuildwheel cibuildwheel %LBUG_PYTHON_CIBW_SOURCE_DIR% --output-dir scripts\pip-package\wheelhouse
if errorlevel 1 exit /b 1
ccache -s
- name: Install ccache (macOS)
if: matrix.os == 'macos'
run: brew install ccache
- name: Cache ccache directory (Linux/macOS)
if: matrix.os != 'windows'
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/.ccache
key: ${{ runner.os }}-${{ matrix.platform }}-ccache-wheel-${{ github.sha }}
restore-keys: |
${{ runner.os }}-${{ matrix.platform }}-ccache-wheel-
- name: Build wheels on ${{ matrix.platform }} (Linux/macOS)
if: matrix.os != 'windows'
shell: bash
run: |
source .venv/bin/activate
python -m cibuildwheel --output-dir scripts/pip-package/wheelhouse "${LBUG_PYTHON_CIBW_SOURCE_DIR}"
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os == 'linux' && format('manylinux{0}', matrix.manylinux) || matrix.os }}-wheels-${{ matrix.platform }}
path: ./scripts/pip-package/wheelhouse/*.whl