Repository navigation
274 lines (247 loc) · 9.99 KB
/
Copy pathbuild-python-binding.yml
File metadata and controls
274 lines (247 loc) · 9.99 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
# 在 macOS 上构建 ElaWidgetTools 的 PySide6 6.10.3 Python 绑定
# 矩阵构建 Python 3.10 / 3.12,产出可直接 `import ElaWidgetTools` 的 .so 模块,打包为 zip artifact 供下载
name: Build Python Binding (macOS)
on:
push:
branches: [main, master]
paths:
- 'CMakeLists.txt'
- 'ElaWidgetTools/**'
- 'bindings/**'
- '.github/workflows/build-python-binding.yml'
pull_request:
branches: [main, master]
paths:
- 'CMakeLists.txt'
- 'ElaWidgetTools/**'
- 'bindings/**'
- '.github/workflows/build-python-binding.yml'
workflow_dispatch:
env:
QT_VERSION: 6.10.3
PYSIDE6_VERSION: 6.10.3
BUILD_TYPE: Release
concurrency:
group: build-python-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build-macos:
name: macOS / Python ${{ matrix.python-version }} / PySide6 6.10.3
runs-on: macos-15
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.12"]
steps:
- name: Checkout 源码
uses: actions/checkout@v4
with:
submodules: recursive
- name: 用 conda 安装 Python ${{ matrix.python-version }}
uses: conda-incubator/setup-miniconda@v3
with:
python-version: ${{ matrix.python-version }}
miniforge-variant: Miniforge3
use-mamba: true
channels: conda-forge
channel-priority: strict
auto-activate-base: true
- name: 验证 Python 版本
shell: bash -el {0}
run: |
python --version
which python
python -c "import sys; print('exec:', sys.executable)"
- name: 安装 PySide6 / shiboken6 / shiboken6_generator ${{ env.PYSIDE6_VERSION }}
shell: bash -el {0}
run: |
python -m pip install --upgrade pip
python -m pip install \
"PySide6==${{ env.PYSIDE6_VERSION }}" \
"shiboken6==${{ env.PYSIDE6_VERSION }}" \
"shiboken6_generator==${{ env.PYSIDE6_VERSION }}"
- name: 安装 Qt ${{ env.QT_VERSION }} (clang_64)
uses: jurplel/install-qt-action@v4
with:
version: ${{ env.QT_VERSION }}
arch: clang_64
host: mac
target: desktop
cache: true
cache-key-prefix: qt-${{ env.QT_VERSION }}-clang_64
- name: 安装 Ninja
run: brew install ninja
- name: 查询环境路径
id: env
shell: bash -el {0}
run: |
set -euo pipefail
python --version
echo "qt_root_dir=$QT_ROOT_DIR" >> "$GITHUB_OUTPUT"
PY_INC=$(python -c "import sysconfig; print(sysconfig.get_path('include'))")
PY_SITE=$(python -c "import site; print(site.getsitepackages()[0])")
SHIBOKEN_DIR=$(python -c "import shiboken6,os;print(os.path.dirname(shiboken6.__file__))")
PYSIDE6_DIR=$(python -c "import PySide6,os;print(os.path.dirname(PySide6.__file__))")
echo "py_include=$PY_INC" >> "$GITHUB_OUTPUT"
echo "py_site=$PY_SITE" >> "$GITHUB_OUTPUT"
echo "shiboken_dir=$SHIBOKEN_DIR" >> "$GITHUB_OUTPUT"
echo "pyside6_dir=$PYSIDE6_DIR" >> "$GITHUB_OUTPUT"
echo "--- Qt root ---"; ls "$QT_ROOT_DIR"
echo "--- PySide6 dir ---"; ls "$PYSIDE6_DIR/lib/cmake/PySide6" | head
- name: 替换 bindings.xml 中的硬编码 PySide6 glue 路径
shell: bash -el {0}
run: |
set -euo pipefail
# bindings.xml 引用了开发者本机的 PySide6 glue 文件路径,
# 替换为 runner 上实际的 PySide6 安装路径
PYSIDE6_GLUE_DIR="${{ steps.env.outputs.pyside6_dir }}/glue"
echo "PySide6 glue dir: $PYSIDE6_GLUE_DIR"
ls "$PYSIDE6_GLUE_DIR" | head
sed -i.bak "s|/Users/cyber/miniconda3/envs/aidub/lib/python3.10/site-packages/PySide6/glue|$PYSIDE6_GLUE_DIR|g" bindings/bindings.xml
echo "--- 替换后的 inject-code 行 ---"
grep "inject-code.*glue" bindings/bindings.xml
rm -f bindings/bindings.xml.bak
- name: 诊断 Qt 目录结构 + 创建 include 符号链接
shell: bash -el {0}
run: |
set -euo pipefail
echo "=== QT_ROOT_DIR ==="; echo "$QT_ROOT_DIR"
echo "=== lib 目录 ==="; ls "$QT_ROOT_DIR/lib" | head -20
echo "=== include 目录是否存在 ==="; ls -d "$QT_ROOT_DIR/include" 2>&1 || echo "include 目录不存在"
echo "=== include/QtCore 是否存在 ==="; ls -d "$QT_ROOT_DIR/include/QtCore" 2>&1 || echo "include/QtCore 不存在"
echo "=== framework Headers ==="; ls "$QT_ROOT_DIR/lib/QtCore.framework/Headers" | head -5
# Qt framework 安装可能缺少 include/QtCore 链接,创建符号链接
if [ ! -d "$QT_ROOT_DIR/include/QtCore" ]; then
echo "创建 include 符号链接..."
mkdir -p "$QT_ROOT_DIR/include"
for fw in QtCore QtGui QtWidgets; do
if [ -d "$QT_ROOT_DIR/lib/${fw}.framework/Headers" ]; then
ln -sf "$QT_ROOT_DIR/lib/${fw}.framework/Headers" "$QT_ROOT_DIR/include/${fw}"
echo " 链接: include/${fw} -> lib/${fw}.framework/Headers"
fi
done
echo "=== 验证 ==="; ls -la "$QT_ROOT_DIR/include"
fi
- name: CMake configure
shell: bash -el {0}
run: |
cmake -S . -B build-python \
-G Ninja \
-DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} \
-DCMAKE_PREFIX_PATH="${{ steps.env.outputs.qt_root_dir }}" \
-DPython3_EXECUTABLE="$(which python)" \
-DShiboken6_DIR="${{ steps.env.outputs.shiboken_dir }}/lib/cmake/Shiboken6" \
-DPySide6_DIR="${{ steps.env.outputs.pyside6_dir }}/lib/cmake/PySide6" \
-DBUILD_PYTHON_BINDINGS=ON
- name: CMake build (shiboken 生成 + 编译)
shell: bash -el {0}
run: cmake --build build-python --target ElaWidgetToolsPython --parallel
- name: CMake install (装入 site-packages)
shell: bash -el {0}
run: cmake --install build-python
- name: 冒烟测试 (import)
shell: bash -el {0}
run: |
python - <<'PY'
import sys
sys.path.insert(0, "${{ steps.env.outputs.py_site }}")
import ElaWidgetTools as E
print("ElaWidgetTools loaded:", E.__file__)
# 抽查几个关键类
for name in ["ElaWindow","ElaMessageBar","ElaIconType","ElaNavigationRouter"]:
assert hasattr(E, name), f"missing: {name}"
print("smoke test passed")
PY
- name: 生成 .pyi 类型桩
shell: bash -el {0}
run: |
set -euo pipefail
PY_SITE="${{ steps.env.outputs.py_site }}"
SO=$(ls "$PY_SITE"/ElaWidgetTools*.so | head -n1)
echo "generate type stub for: $SO"
python - "$SO" "$PY_SITE" <<'PY'
import sys
so, outdir = sys.argv[1], sys.argv[2]
sys.argv = ["genpyi", so, "--outpath", outdir]
import PySide6
import PySide6.QtWidgets
import PySide6.QtCore
import PySide6.QtGui
import shiboken6
import shibokensupport.signature.lib.pyi_generator as gen
gen.PySide6 = PySide6
from shibokensupport.signature.lib.pyi_generator import main
main()
PY
echo "--- generated pyi ---"
ls -la "$PY_SITE"/ElaWidgetTools*.pyi
- name: 打包 .so + .pyi 到 dist/
shell: bash -el {0}
run: |
set -euo pipefail
mkdir -p dist
# 主 .so 模块 + 类型桩
cp "${{ steps.env.outputs.py_site }}/ElaWidgetTools"*.so dist/
cp "${{ steps.env.outputs.py_site }}/ElaWidgetTools"*.pyi dist/
# 列出产物
ls -lh dist/
- name: 上传构建产物
uses: actions/upload-artifact@v4
with:
name: ElaWidgetTools-macos-py${{ matrix.python-version }}-pyside${{ env.PYSIDE6_VERSION }}
path: dist/*
retention-days: 30
if-no-files-found: error
release:
name: 发布到 GitHub Release
needs: build-macos
runs-on: ubuntu-latest
if: |
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
github.event_name == 'workflow_dispatch'
permissions:
contents: write
steps:
- name: 下载 artifact
uses: actions/download-artifact@v4
with:
path: artifacts
- name: 打包为 zip
run: |
set -euo pipefail
mkdir -p dist
cd artifacts
for d in */; do
name="${d%/}"
(cd "$d" && zip -r "../../dist/${name}.zip" .)
done
cd ..
ls -lh dist/
- name: 用日期生成 tag 并清理同日旧 release
id: meta
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
tag="py-v$(date -u +%Y.%m.%d)"
if gh release view "$tag" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
echo "存在同日 release $tag,删除以重建"
gh release delete "$tag" --yes --cleanup-tag --repo "$GITHUB_REPOSITORY"
fi
echo "tag=$tag" >> "$GITHUB_OUTPUT"
- name: 创建 Release 并上传产物
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.meta.outputs.tag }}
name: ${{ steps.meta.outputs.tag }}
target_commitish: ${{ github.sha }}
body: |
自动构建 Python 绑定 — 提交 `${{ github.sha }}`
平台:macOS 15 (clang_64)
Python:3.10 / 3.12
PySide6:${{ env.PYSIDE6_VERSION }}
Qt:${{ env.QT_VERSION }}
将 zip 解压后把 `ElaWidgetTools.*.so` 放入对应 Python 的 site-packages 即可 `import ElaWidgetTools`。
同目录下的 `ElaWidgetTools.pyi` 为类型桩,一并放入可获得 IDE 类型提示。
fail_on_unmatched_files: true
files: dist/*.zip