Skip to content

Commit 23a8bf8

Browse files
committed
build(macOS): 修复 Qt6 清晰度问题并优化构建流程
- 安装 create-dmg 依赖 - 设置 Qt6 相关环境变量 - 添加 Qt6 插件路径到 spec 文件 - 复制必要的 Qt6 插件到构建目录 - 使用 macdeployqt 处理 Qt6 依赖 - 优化构建脚本,增加调试信息和验证步骤
1 parent d2b89c0 commit 23a8bf8

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

.github/workflows/build.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,19 @@ jobs:
7878
7979
# 安装系统依赖
8080
brew install qt6
81+
brew install create-dmg
8182
82-
# 设置环境变量
83+
# 设置 Qt 环境变量
8384
echo "PYTHONPATH=${GITHUB_WORKSPACE}" >> $GITHUB_ENV
8485
echo "QT_PLUGIN_PATH=$BREW_PREFIX/opt/qt6/plugins" >> $GITHUB_ENV
86+
echo "QT_QPA_PLATFORM_PATH=$BREW_PREFIX/opt/qt6/plugins/platforms" >> $GITHUB_ENV
87+
echo "QT_LIBRARY_PATH=$BREW_PREFIX/opt/qt6/lib" >> $GITHUB_ENV
8588
echo "QT_DEBUG_PLUGINS=1" >> $GITHUB_ENV
8689
8790
# 显示 Qt 安装信息
8891
brew list qt6 --verbose
92+
ls -la $BREW_PREFIX/opt/qt6/plugins
93+
ls -la $BREW_PREFIX/opt/qt6/plugins/platforms
8994
9095
echo "Installed packages:"
9196
pip list
@@ -115,11 +120,18 @@ jobs:
115120
- name: Build (macOS ARM)
116121
if: runner.os == 'macOS'
117122
run: |
123+
# 添加 Qt 相关配置到 spec 文件
124+
echo "import os" > Text2Voice.spec
125+
echo "qt_plugin_path = '/opt/homebrew/opt/qt6/plugins'" >> Text2Voice.spec
126+
echo "qt_lib_path = '/opt/homebrew/opt/qt6/lib'" >> Text2Voice.spec
127+
118128
pyinstaller --noconsole \
119129
--add-data ".env:." \
120130
--add-data "assets:assets" \
121131
--add-data "resources:resources" \
122132
--add-data "ui/styles:ui/styles" \
133+
--add-binary "/opt/homebrew/opt/qt6/plugins/platforms/libqcocoa.dylib:PyQt6/Qt6/plugins/platforms/" \
134+
--add-binary "/opt/homebrew/opt/qt6/plugins/styles/libqmacstyle.dylib:PyQt6/Qt6/plugins/styles/" \
123135
--name "Text2Voice-ARM" \
124136
--hidden-import PyQt6.QtCore \
125137
--hidden-import PyQt6.QtGui \
@@ -130,13 +142,27 @@ jobs:
130142
--hidden-import pygame \
131143
main.py
132144
145+
# 验证构建结果
146+
otool -L "dist/Text2Voice-ARM.app/Contents/MacOS/Text2Voice-ARM"
147+
ls -R "dist/Text2Voice-ARM.app/Contents/Frameworks/"
148+
ls -R "dist/Text2Voice-ARM.app/Contents/PlugIns/"
149+
133150
# 创建 DMG (macOS ARM)
134151
- name: Create DMG (macOS ARM)
135152
if: runner.os == 'macOS'
136153
run: |
137-
brew install create-dmg
154+
# 确保应用程序可执行
138155
chmod +x "dist/Text2Voice-ARM.app/Contents/MacOS/Text2Voice-ARM"
139156
157+
# 复制额外的 Qt 插件
158+
mkdir -p "dist/Text2Voice-ARM.app/Contents/PlugIns/platforms"
159+
mkdir -p "dist/Text2Voice-ARM.app/Contents/PlugIns/styles"
160+
cp -f "/opt/homebrew/opt/qt6/plugins/platforms/libqcocoa.dylib" "dist/Text2Voice-ARM.app/Contents/PlugIns/platforms/"
161+
cp -f "/opt/homebrew/opt/qt6/plugins/styles/libqmacstyle.dylib" "dist/Text2Voice-ARM.app/Contents/PlugIns/styles/"
162+
163+
# 使用 macdeployqt 处理 Qt 依赖
164+
/opt/homebrew/opt/qt6/bin/macdeployqt "dist/Text2Voice-ARM.app" -verbose=3
165+
140166
create-dmg \
141167
--volname "Text2Voice" \
142168
--window-pos 200 120 \

0 commit comments

Comments
 (0)