|
1 | | -name: Windows build and package |
| 1 | +name: Windows and macOS build and package |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
@@ -82,3 +82,157 @@ jobs: |
82 | 82 | path: build/package/ |
83 | 83 | if-no-files-found: error |
84 | 84 | retention-days: 14 |
| 85 | + |
| 86 | + macos: |
| 87 | + name: macOS ${{ matrix.arch }} (Qt ${{ matrix.qt }}) |
| 88 | + runs-on: ${{ matrix.runner }} |
| 89 | + timeout-minutes: 45 |
| 90 | + strategy: |
| 91 | + fail-fast: false |
| 92 | + matrix: |
| 93 | + qt: ['5', '6'] |
| 94 | + arch: [arm64, x86_64] |
| 95 | + include: |
| 96 | + - arch: arm64 |
| 97 | + runner: macos-15 |
| 98 | + - arch: x86_64 |
| 99 | + runner: macos-15-intel |
| 100 | + - qt: '5' |
| 101 | + formula: qt@5 |
| 102 | + - qt: '6' |
| 103 | + formula: qt |
| 104 | + steps: |
| 105 | + - uses: actions/checkout@v4 |
| 106 | + - name: Install macOS build dependencies |
| 107 | + run: brew install cmake ninja "${{ matrix.formula }}" |
| 108 | + |
| 109 | + - name: Build QNetStats |
| 110 | + run: | |
| 111 | + set -euo pipefail |
| 112 | + qt_prefix="$(brew --prefix "${{ matrix.formula }}")" |
| 113 | + cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release \ |
| 114 | + -DUSE_QT=${{ matrix.qt }} -DCMAKE_PREFIX_PATH="$qt_prefix" \ |
| 115 | + -DCMAKE_OSX_ARCHITECTURES=${{ matrix.arch }} |
| 116 | + cmake --build build --parallel 3 |
| 117 | +
|
| 118 | + - name: Deploy, sign and package macOS app |
| 119 | + shell: bash |
| 120 | + run: | |
| 121 | + set -euo pipefail |
| 122 | + qt_prefix="$(brew --prefix "${{ matrix.formula }}")" |
| 123 | + qt_bin="$qt_prefix/bin" |
| 124 | + export PATH="$qt_bin:$PATH" |
| 125 | + cd build |
| 126 | + bundle=QNetStats.app |
| 127 | + test -d "$bundle" |
| 128 | + test "$(uname -m)" = "${{ matrix.arch }}" |
| 129 | + lipo "$bundle/Contents/MacOS/QNetStats" -verify_arch "${{ matrix.arch }}" |
| 130 | + cp ../COPYING "$bundle/Contents/Resources/LICENSE.txt" |
| 131 | +
|
| 132 | + # Stage the plugin types used by this Widgets application. Keep all |
| 133 | + # image formats, but exclude the unused QML virtual keyboard. |
| 134 | + qt_plugins="$("$qt_bin/qmake" -query QT_INSTALL_PLUGINS)" |
| 135 | + deploy_args=(-no-plugins -verbose=2 -no-codesign) |
| 136 | + shopt -s nullglob |
| 137 | + for plugin_type in platforms styles tls networkinformation imageformats iconengines; do |
| 138 | + for plugin in "$qt_plugins/$plugin_type/"*.dylib; do |
| 139 | + plugin_name="${plugin##*/}" |
| 140 | + case "$plugin_name" in |
| 141 | + *_debug.dylib|libqtvirtualkeyboard*.dylib) continue ;; |
| 142 | + esac |
| 143 | + if [ "$plugin_type" = platforms ] && [ "$plugin_name" != libqcocoa.dylib ]; then |
| 144 | + continue |
| 145 | + fi |
| 146 | + mkdir -p "$bundle/Contents/PlugIns/$plugin_type" |
| 147 | + destination="$bundle/Contents/PlugIns/$plugin_type/$plugin_name" |
| 148 | + cp "$plugin" "$destination" |
| 149 | + deploy_args+=("-executable=$destination") |
| 150 | + done |
| 151 | + done |
| 152 | +
|
| 153 | + # Homebrew installs Qt frameworks in separate formula directories. |
| 154 | + # Search them without copying modules that no retained binary uses. |
| 155 | + brew_prefix="$(brew --prefix)" |
| 156 | + deploy_args+=("-libpath=$brew_prefix/lib" |
| 157 | + "-libpath=$qt_prefix/lib") |
| 158 | + for qt_lib in "$brew_prefix"/opt/qt*/lib; do |
| 159 | + [ -d "$qt_lib" ] && deploy_args+=("-libpath=$qt_lib") |
| 160 | + done |
| 161 | + "$qt_bin/macdeployqt" "$bundle" "${deploy_args[@]}" |
| 162 | + test -f "$bundle/Contents/PlugIns/platforms/libqcocoa.dylib" |
| 163 | +
|
| 164 | + # Some transitive Homebrew references survive deployment even when |
| 165 | + # their libraries were copied. Repair only references with an existing |
| 166 | + # bundle counterpart; never leave a dependency on the build machine. |
| 167 | + while IFS= read -r -d '' binary; do |
| 168 | + file_type="$(file -b "$binary")" |
| 169 | + [[ "$file_type" == *Mach-O* ]] || continue |
| 170 | + dependencies="$(otool -L "$binary")" |
| 171 | + install_id="$(otool -D "$binary" | tail -n +2)" |
| 172 | + while IFS= read -r dependency; do |
| 173 | + case "$dependency" in |
| 174 | + "$brew_prefix"/*|@rpath/*) |
| 175 | + case "$dependency" in |
| 176 | + @rpath/*) relative="${dependency#@rpath/}" ;; |
| 177 | + *.framework/*) relative="${dependency#*/lib/}" ;; |
| 178 | + *) relative="${dependency##*/}" ;; |
| 179 | + esac |
| 180 | + target="$bundle/Contents/Frameworks/$relative" |
| 181 | + if [ ! -f "$target" ]; then |
| 182 | + echo "Missing bundled dependency for $binary: $dependency" >&2 |
| 183 | + exit 1 |
| 184 | + fi |
| 185 | + replacement="@executable_path/../Frameworks/$relative" |
| 186 | + if [ "$dependency" = "$install_id" ]; then |
| 187 | + install_name_tool -id "$replacement" "$binary" |
| 188 | + else |
| 189 | + install_name_tool -change "$dependency" "$replacement" "$binary" |
| 190 | + fi |
| 191 | + ;; |
| 192 | + esac |
| 193 | + done <<< "$(printf '%s\n' "$dependencies" | sed -n '2,$s/^[[:space:]]*\(.*\) (compatibility version.*$/\1/p')" |
| 194 | + done < <(find "$bundle" -type f -print0) |
| 195 | +
|
| 196 | + # Signing does not check library availability. Reject missing |
| 197 | + # bundle-relative dependencies as well as build-host references. |
| 198 | + while IFS= read -r -d '' binary; do |
| 199 | + file_type="$(file -b "$binary")" |
| 200 | + [[ "$file_type" == *Mach-O* ]] || continue |
| 201 | + dependencies="$(otool -L "$binary")" |
| 202 | + while IFS= read -r dependency; do |
| 203 | + case "$dependency" in |
| 204 | + /System/Library/*|/usr/lib/*) continue ;; |
| 205 | + @executable_path/*) |
| 206 | + target="$bundle/Contents/MacOS/${dependency#@executable_path/}" ;; |
| 207 | + @loader_path/*) |
| 208 | + target="${binary%/*}/${dependency#@loader_path/}" ;; |
| 209 | + *) |
| 210 | + echo "Unbundled dependency in $binary: $dependency" >&2 |
| 211 | + exit 1 ;; |
| 212 | + esac |
| 213 | + if [ ! -f "$target" ]; then |
| 214 | + echo "Missing bundled dependency for $binary: $dependency" >&2 |
| 215 | + exit 1 |
| 216 | + fi |
| 217 | + done <<< "$(printf '%s\n' "$dependencies" | sed -n '2,$s/^[[:space:]]*\(.*\) (compatibility version.*$/\1/p')" |
| 218 | + done < <(find "$bundle" -type f -print0) |
| 219 | + # All binary edits must precede signing. Deep signing is intentional |
| 220 | + # for this ad-hoc beta bundle, not a Developer ID/notarization workflow. |
| 221 | + codesign --force --deep --sign - "$bundle" |
| 222 | + codesign --verify --deep --strict --verbose=2 "$bundle" |
| 223 | + dmg_stage="$(mktemp -d "$RUNNER_TEMP/qnetstats-dmg.XXXXXX")" |
| 224 | + ditto "$bundle" "$dmg_stage/$bundle" |
| 225 | + ln -s /Applications "$dmg_stage/Applications" |
| 226 | + hdiutil create -volname "QNetStats" -srcfolder "$dmg_stage" \ |
| 227 | + -format UDZO "QNetStats.dmg" |
| 228 | + hdiutil verify "QNetStats.dmg" |
| 229 | + mkdir -p package |
| 230 | + mv QNetStats.dmg "package/QNetStats-macOS-${{ matrix.arch }}-Qt${{ matrix.qt }}.dmg" |
| 231 | +
|
| 232 | + - name: Upload macOS package |
| 233 | + uses: actions/upload-artifact@v4 |
| 234 | + with: |
| 235 | + name: QNetStats-macOS-${{ matrix.arch }}-Qt${{ matrix.qt }}-${{ github.sha }} |
| 236 | + path: build/package/*.dmg |
| 237 | + if-no-files-found: error |
| 238 | + retention-days: 14 |
0 commit comments