Skip to content

Commit c6b4282

Browse files
authored
Merge pull request #554 from Ericzklm/mac-deploy
Mac Distributable Workflow
2 parents 45737f5 + 084742e commit c6b4282

File tree

4 files changed

+156
-2
lines changed

4 files changed

+156
-2
lines changed

.github/workflows/mac-release.yml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
name: SerialPrograms MacOS Release
2+
3+
on:
4+
push:
5+
tags:
6+
# Start MacOS release flow when a new version tag is created
7+
- 'v*'
8+
workflow_dispatch:
9+
# Manual release / testing
10+
inputs:
11+
version:
12+
description: 'Version for the manual release'
13+
required: true
14+
jobs:
15+
description: 'Number of parallel jobs to build with'
16+
default: 4
17+
type: number
18+
qt_version:
19+
description: 'Qt version to use'
20+
required: true
21+
default: '6.8.2'
22+
type: choice
23+
options:
24+
- '6.8.2'
25+
- '6.5.3'
26+
runner:
27+
description: "MacOS Runner"
28+
required: true
29+
default: "macos-13"
30+
type: choice
31+
options:
32+
- "macos-15"
33+
- "macos-13"
34+
35+
36+
jobs:
37+
build:
38+
runs-on: ${{ github.event.inputs.runner }}
39+
steps:
40+
- name: Checkout Arduino-Source
41+
uses: actions/checkout@v4
42+
with:
43+
path: Arduino-Source
44+
45+
- name: Checkout Packages
46+
uses: actions/checkout@v4
47+
with:
48+
repository: 'PokemonAutomation/Packages'
49+
path: Packages
50+
51+
# MacOS runners have Homebrew, Xcode, and Cmake already installed
52+
- name: Install Dependencies
53+
run: |
54+
brew install tesseract
55+
brew install tesseract-lang
56+
brew install opencv
57+
58+
- uses: jurplel/install-qt-action@v4
59+
with:
60+
version: ${{ github.event.inputs.qt_version }}
61+
modules: 'qtmultimedia qtserialport'
62+
63+
- name: Build SerialPrograms.app
64+
run: |
65+
cd Arduino-Source/SerialPrograms
66+
mkdir bin
67+
cd bin
68+
cmake .. -DUNIX_LINK_TESSERACT:BOOL=true -DCMAKE_BUILD_TYPE:STRING=Release
69+
cmake --build . -j ${{ github.event.inputs.jobs }}
70+
cp -r SerialPrograms.app ../../../SerialPrograms.app
71+
72+
# Important: GitHub MacOS runners do not have the lib area in its rpath by default. It must manually be added for frameworks to be discovered and added to the bundle
73+
# Some libraries are not copied in QT deployment on the runner but will still be proprely linked if they're added prior to deployment
74+
- name: rpath resolution
75+
run: |
76+
BREW_PREFIX=$(brew --prefix)
77+
install_name_tool -add_rpath $BREW_PREFIX/lib SerialPrograms.app/Contents/MacOS/SerialPrograms
78+
otool -l SerialPrograms.app/Contents/MacOS/SerialPrograms | grep -A2 LC_RPATH
79+
mkdir SerialPrograms.app/Contents/Frameworks
80+
cp $BREW_PREFIX/Cellar/protobuf/29.3/lib/libutf8_validity.dylib SerialPrograms.app/Contents/Frameworks
81+
cp $BREW_PREFIX/Cellar/webp/1.5.0/lib/libsharpyuv.0.dylib SerialPrograms.app/Contents/Frameworks
82+
cp $BREW_PREFIX/Cellar/jpeg-xl/0.11.1/lib/libjxl_cms.0.11.dylib SerialPrograms.app/Contents/Frameworks
83+
cp $BREW_PREFIX/Cellar/vtk/9.4.1_2/lib/libvtkCommonComputationalGeometry-9.4.1.dylib SerialPrograms.app/Contents/Frameworks
84+
cp $BREW_PREFIX/Cellar/vtk/9.4.1_2/lib/libvtkFiltersVerdict-9.4.1.dylib SerialPrograms.app/Contents/Frameworks
85+
cp $BREW_PREFIX/Cellar/vtk/9.4.1_2/lib/libvtkfmt-9.4.1.dylib SerialPrograms.app/Contents/Frameworks
86+
cp $BREW_PREFIX/Cellar/vtk/9.4.1_2/lib/libvtkFiltersGeometry-9.4.1.dylib SerialPrograms.app/Contents/Frameworks
87+
cp $BREW_PREFIX/Cellar/vtk/9.4.1_2/lib/libvtkFiltersCore-9.4.1.dylib SerialPrograms.app/Contents/Frameworks
88+
cp $BREW_PREFIX/Cellar/vtk/9.4.1_2/lib/libvtkCommonCore-9.4.1.dylib SerialPrograms.app/Contents/Frameworks
89+
cp $BREW_PREFIX/Cellar/vtk/9.4.1_2/lib/libvtkCommonSystem-9.4.1.dylib SerialPrograms.app/Contents/Frameworks
90+
91+
# Use macdeployqt to bundle the app with dependencies
92+
- name: Run macdeployqt
93+
run: macdeployqt SerialPrograms.app -verbose=3
94+
95+
# Dummy codesign
96+
- name: Codesign
97+
run: codesign --force --deep --sign - SerialPrograms.app
98+
99+
# Create a disk image for installation
100+
- name: Create disk image
101+
run: |
102+
brew install create-dmg
103+
mkdir dmg
104+
cd dmg
105+
mv ../SerialPrograms.app ./SerialPrograms.app
106+
create-dmg --volname "SerialPrograms Installer" \
107+
--window-pos 150 150 \
108+
--window-size 600 400 \
109+
--icon-size 128 \
110+
--icon "SerialPrograms.app" 140 160 \
111+
--hide-extension "SerialPrograms.app" \
112+
--app-drop-link 450 160 \
113+
"SerialPrograms-Installer.dmg" \
114+
"./"
115+
mv SerialPrograms-Installer.dmg $GITHUB_WORKSPACE/SerialPrograms-Installer.dmg
116+
117+
- name: Upload artifact
118+
uses: actions/upload-artifact@v4
119+
with:
120+
name: SerialPrograms-Installer.dmg
121+
path: SerialPrograms-Installer.dmg
122+
123+
- name: GitHub Release
124+
uses: softprops/action-gh-release@v2
125+
with:
126+
files: SerialPrograms-Installer.dmg
127+
# Tag should be automatically set in the case of a tag push
128+
tag_name: ${{ github.event.inputs.version }}
129+
token: ${{ secrets.GITHUB_TOKEN }}

SerialPrograms/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,6 +2225,14 @@ if (APPLE)
22252225
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/cmake/MacOSXBundleInfo.plist.in
22262226
RESOURCE ${SerialPrograms_ICON}
22272227
)
2228+
2229+
add_custom_command(
2230+
TARGET SerialPrograms
2231+
POST_BUILD
2232+
COMMAND ${CMAKE_COMMAND} -E copy_directory
2233+
"${CMAKE_CURRENT_SOURCE_DIR}/../../Packages/SerialPrograms/Resources"
2234+
"$<TARGET_FILE_DIR:SerialPrograms>/../Resources"
2235+
)
22282236
else() # WIN and Linux:
22292237
add_executable(SerialPrograms WIN32 ${MAIN_SOURCES})
22302238
endif()

SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <iostream>
88
#include <set>
9+
#include <QStandardPaths>
910
#include <QCryptographicHash>
1011
#include "Common/Cpp/Containers/Pimpl.tpp"
1112
#include "Common/Cpp/LifetimeSanitizer.h"
@@ -106,15 +107,25 @@ GlobalSettings::GlobalSettings()
106107
false,
107108
"<b>Stats File:</b><br>Use the stats file here. Multiple instances of the program can use the same file.",
108109
LockMode::LOCK_WHILE_RUNNING,
110+
#if defined(__APPLE__)
111+
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation).toStdString() + "/UserSettings/PA-Stats.txt",
112+
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation).toStdString() + "/UserSettings/PA-Stats.txt"
113+
#else
109114
"UserSettings/PA-Stats.txt",
110115
"UserSettings/PA-Stats.txt"
116+
#endif
111117
)
112118
, TEMP_FOLDER(
113119
false,
114120
"<b>Temp Folder:</b><br>Place temporary files in this directory.",
115121
LockMode::LOCK_WHILE_RUNNING,
122+
#if defined(__APPLE__)
123+
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation).toStdString() + "/TempFiles/",
124+
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation).toStdString() + "/TempFiles/"
125+
#else
116126
"TempFiles/",
117127
"TempFiles/"
128+
#endif
118129
)
119130
, THEME(CONSTRUCT_TOKEN)
120131
, WINDOW_SIZE(

SerialPrograms/Source/CommonFramework/Globals.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include <QCoreApplication>
8+
#include <QStandardPaths>
89
#include <QFile>
910
#include <QFileInfo>
1011
#include <QDir>
@@ -112,9 +113,14 @@ std::string get_training_path(){
112113
}
113114

114115
std::string get_runtime_base_path(){
116+
// On MacOS, find the writable application support directory
115117
if (QSysInfo::productType() == "macos" || QSysInfo::productType() == "osx"){
116-
QString application_dir_path = get_application_base_dir_path();
117-
return application_dir_path.toStdString() + "/";
118+
QString appSupportPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
119+
QDir dir(appSupportPath);
120+
if (!dir.exists()) {
121+
dir.mkpath(".");
122+
}
123+
return appSupportPath.toStdString() + "/";
118124
}
119125
return "./";
120126
}

0 commit comments

Comments
 (0)