Skip to content

Commit 2d5fc72

Browse files
committed
fix(ci): 修复 Windows 桌面端打包失败
- 默认 ONNX 推理,移除 torch 依赖,避免 PyInstaller 引入 tensorboard。 - PyInstaller 排除 torch/tensorboard 等无关模块,降低打包失败概率。 - Windows CI 增加 MSBuild + app-builder 校验与调试日志,并同步更新 README/脚本入口。
1 parent b4ceea5 commit 2d5fc72

6 files changed

Lines changed: 91 additions & 92 deletions

File tree

.github/workflows/desktop-build.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,68 @@ jobs:
7272
with:
7373
python-version: '3.10'
7474

75+
# Windows: 安装 Visual Studio Build Tools(用于编译 native 模块)
76+
- name: Setup MSVC Build Tools (Windows only)
77+
if: matrix.platform == 'win'
78+
uses: microsoft/setup-msbuild@v2
79+
7580
- name: Install dependencies
7681
run: pnpm install --frozen-lockfile
7782

83+
# Windows: 确保 app-builder.exe 存在且可执行
84+
- name: Verify and fix app-builder (Windows only)
85+
if: matrix.platform == 'win'
86+
shell: pwsh
87+
run: |
88+
# 查找 app-builder.exe
89+
$appBuilder = Get-ChildItem -Path "node_modules" -Recurse -Filter "app-builder.exe" -ErrorAction SilentlyContinue | Select-Object -First 1
90+
91+
if ($appBuilder) {
92+
Write-Host "Found app-builder.exe at: $($appBuilder.FullName)"
93+
Write-Host "File size: $($appBuilder.Length) bytes"
94+
95+
# 验证文件是否为有效的 PE 文件
96+
$bytes = [System.IO.File]::ReadAllBytes($appBuilder.FullName)
97+
if ($bytes[0] -eq 0x4D -and $bytes[1] -eq 0x5A) {
98+
Write-Host "✓ Valid PE executable"
99+
} else {
100+
Write-Warning "File may be corrupted, reinstalling..."
101+
Remove-Item -Recurse -Force "node_modules/app-builder-bin" -ErrorAction SilentlyContinue
102+
Remove-Item -Recurse -Force "node_modules/.pnpm/app-builder-bin*" -ErrorAction SilentlyContinue
103+
pnpm install --frozen-lockfile
104+
}
105+
} else {
106+
Write-Warning "app-builder.exe not found, attempting reinstall..."
107+
pnpm install --frozen-lockfile
108+
}
109+
110+
# 再次验证
111+
$appBuilder = Get-ChildItem -Path "node_modules" -Recurse -Filter "app-builder.exe" -ErrorAction SilentlyContinue | Select-Object -First 1
112+
if (-not $appBuilder) {
113+
Write-Error "app-builder.exe still not found after reinstall!"
114+
exit 1
115+
}
116+
78117
- name: Prepare Python env for ASR backend
79118
working-directory: desktop
80119
run: pnpm run prepare:python
81120

121+
# 验证 Python 环境和 PyInstaller
122+
- name: Verify Python environment
123+
shell: bash
124+
run: |
125+
if [ "${{ matrix.platform }}" = "win" ]; then
126+
PYTHON_PATH="${{ github.workspace }}/desktop/python-env/Scripts/python.exe"
127+
else
128+
PYTHON_PATH="${{ github.workspace }}/desktop/python-env/bin/python3"
129+
fi
130+
echo "Python path: $PYTHON_PATH"
131+
"$PYTHON_PATH" --version
132+
"$PYTHON_PATH" -m pip list | head -30
133+
"$PYTHON_PATH" -c "import PyInstaller; print('PyInstaller OK')" || echo "PyInstaller import check failed"
134+
echo "Checking for PyInstaller module..."
135+
"$PYTHON_PATH" -m PyInstaller --version || true
136+
82137
- name: Print app version
83138
id: meta
84139
run: |
@@ -90,13 +145,32 @@ jobs:
90145
PYTHON: ${{ matrix.python }}
91146
ASR_IMPL: ${{ matrix.asr }}
92147
ASR_PYTHON_PATH: ${{ matrix.platform == 'win' && format('{0}/desktop/python-env/Scripts/python.exe', github.workspace) || format('{0}/desktop/python-env/bin/python3', github.workspace) }}
148+
# Windows: 增加调试日志级别
149+
DEBUG: ${{ matrix.platform == 'win' && 'electron-builder' || '' }}
93150
run: |
151+
echo "=== Build Environment ==="
152+
echo "Platform: ${{ matrix.platform }}"
153+
echo "Arch: ${{ matrix.arch }}"
154+
echo "ASR_PYTHON_PATH: $ASR_PYTHON_PATH"
155+
echo "========================="
156+
94157
if [ "${{ matrix.platform }}" = "mac" ]; then
95158
pnpm run build:mac -- --${{ matrix.arch }}
96159
else
97160
pnpm run build:win -- --${{ matrix.arch }}
98161
fi
99162
163+
# Windows: 列出构建产物帮助调试
164+
- name: List build artifacts
165+
if: always()
166+
shell: bash
167+
run: |
168+
echo "=== Release directory contents ==="
169+
ls -la release/ || echo "release/ not found"
170+
echo "=== Backend dist contents ==="
171+
ls -la backend/dist/ || echo "backend/dist/ not found"
172+
ls -la backend/dist/asr-backend/ 2>/dev/null | head -20 || echo "asr-backend dir not found"
173+
100174
- name: Upload artifacts
101175
uses: actions/upload-artifact@v4
102176
with:

desktop/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@ pnpm install
7878
### 配置语音识别
7979

8080
```bash
81-
# 安装 FunASR(推荐,中文识别效果最好,macOS 默认
82-
npm run setup-funasr
81+
# 准备内置 Python 运行环境(会创建 desktop/python-env 并安装依赖
82+
pnpm run prepare:python
8383
```
84+
85+
- 本项目桌面端的本地 ASR **默认使用 FunASR ONNX(`funasr-onnx + onnxruntime`**,因此 **不需要安装 `torch`**
8486
- Windows 也使用 FunASR ONNX,无需额外安装 faster-whisper。
8587

8688
### 启动

desktop/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"dev:vite": "vite",
1313
"download-models": "node scripts/download-models.js",
1414
"update-asr-model": "node scripts/update-asr-model.js",
15-
"setup-funasr": "bash scripts/setup-funasr.sh",
1615
"build:native": "node-gyp rebuild --directory=src/native/system-audio-capture",
1716
"rebuild:better-sqlite3": "electron-rebuild -f -w better-sqlite3",
1817
"rebuild:native": "electron-rebuild -f -w system_audio_capture",

desktop/requirements.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ onnxruntime==1.21.1
1313

1414
# FunASR ONNX 运行时依赖(funasr_onnx 内部会 import)
1515
jieba>=0.42.1
16-
torch
1716
modelscope
1817

18+
# 说明:
19+
# - 本项目桌面端默认使用 funasr-onnx + onnxruntime 做推理,不需要 PyTorch。
20+
# - 之前的 torch 主要会在 PyInstaller 分析阶段引入 torch.utils.tensorboard,导致 Windows CI 因缺少 tensorboard 失败。
21+
# - 如需完整 FunASR(非 ONNX)或训练/导出能力,请在单独环境中安装 torch(而不是默认打包依赖)。
22+

desktop/scripts/build-backend.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ function main() {
9090
'--collect-all numpy',
9191
'--hidden-import funasr_onnx',
9292
'--hidden-import jieba',
93+
// 排除不需要的 torch 子模块,避免 tensorboard 缺失导致构建失败
94+
'--exclude-module torch.utils.tensorboard',
95+
'--exclude-module tensorboard',
96+
'--exclude-module torch.utils.bottleneck',
97+
// 排除其他不需要的大型依赖,减小包体积
98+
'--exclude-module matplotlib',
99+
'--exclude-module PIL',
100+
'--exclude-module cv2',
93101
];
94102

95103
// 统一使用 onedir,避免 onefile 的压缩/解压开销

desktop/scripts/setup-funasr.sh

Lines changed: 0 additions & 88 deletions
This file was deleted.

0 commit comments

Comments
 (0)