macos-app.yml 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. # LYNX SHARE for macOS (universal dmg), round 190qd (the 0.1.31 release). A universal build in ONE job compiled every
  2. # translation unit twice (arm64 + x86_64) on one runner, and the big ones (src/Main.cpp) took about 2 h per architecture
  3. # on Apple clang: 0.1.30's job ran 3 h 25 min, 0.1.31's went past 4 h, close to GitHub's 6 h job limit. So each
  4. # architecture now builds on its own runner, in parallel, and a small job merges them with lipo.
  5. #
  6. # version the package label (input, or CMakeLists.txt's version + the commit)
  7. # build (macos-15, matrix arm64 / x86_64) CMake + Ninja, one architecture each; the LYNX.app goes on as an artifact
  8. # universal (macos-15) lipo -create of every Mach-O file of the two apps into one universal LYNX.app, self-test and
  9. # demo project on it (native arm64), scripts/package-macos.sh (ad-hoc signs the merged bundle) ->
  10. # LYNX-<label>-macos-universal.dmg
  11. # attach (workflow_dispatch with a tag only) attaches the dmg to that tag's GitHub release and adds its line to the
  12. # release's SHA256SUMS.txt (the in-app updater checks every download against it)
  13. #
  14. # release.yml calls it (workflow_call); a manual run (workflow_dispatch) builds `ref` (a tag: the dmg goes to its release).
  15. name: macOS app
  16. on:
  17. workflow_dispatch:
  18. inputs:
  19. ref:
  20. description: 'tag or commit to build (a tag v*: the dmg is attached to its release)'
  21. type: string
  22. required: true
  23. workflow_call:
  24. inputs:
  25. label:
  26. description: 'package label (release.yml passes its own)'
  27. type: string
  28. default: ''
  29. permissions:
  30. contents: read
  31. env:
  32. JUCE_VERSION: 8.0.4
  33. JUCE_SHA256: 0effe9823a6fd8a4f98e5c08be7d308350e417b2d15dcf34011e778fefbbf005
  34. jobs:
  35. version:
  36. name: Version
  37. runs-on: ubuntu-24.04
  38. outputs:
  39. label: ${{ steps.version.outputs.label }}
  40. ref: ${{ steps.version.outputs.ref }}
  41. steps:
  42. - uses: actions/checkout@v5
  43. with:
  44. ref: ${{ inputs.ref || github.ref }}
  45. - name: Label
  46. id: version
  47. shell: bash
  48. env:
  49. INPUT_LABEL: ${{ inputs.label }}
  50. INPUT_REF: ${{ inputs.ref }}
  51. run: |
  52. version="$(sed -n 's/^project(LYNX VERSION \([0-9]*\.[0-9]*\.[0-9]*\(\.[0-9]*\)\{0,1\}\).*/\1/p' CMakeLists.txt)"
  53. [[ -n "$version" ]] || { echo "::error::no version in CMakeLists.txt"; exit 1; }
  54. sha="$(git rev-parse HEAD)"
  55. if [[ -n "$INPUT_LABEL" ]]; then label="$INPUT_LABEL"
  56. elif [[ "$INPUT_REF" == v* ]]; then label="${INPUT_REF#v}"
  57. else label="$version-${sha::7}"; fi
  58. echo "label=$label" >> "$GITHUB_OUTPUT"
  59. echo "ref=$sha" >> "$GITHUB_OUTPUT"
  60. echo "LYNX macOS $label ($sha)"
  61. build:
  62. name: macOS (${{ matrix.arch }})
  63. needs: version
  64. runs-on: macos-15
  65. # (rollup 0.1.32: a cold arm64 build took 4.5-5 h and was cancelled at the old 300; GitHub's own limit is 360)
  66. timeout-minutes: 350
  67. strategy:
  68. matrix:
  69. arch: [arm64, x86_64]
  70. env:
  71. CCACHE_DIR: ${{ github.workspace }}/.ccache
  72. CCACHE_MAXSIZE: 1500M
  73. CCACHE_COMPILERCHECK: content
  74. steps:
  75. - uses: actions/checkout@v5
  76. with:
  77. ref: ${{ needs.version.outputs.ref }}
  78. - name: Build dependencies
  79. run: |
  80. brew list ninja > /dev/null 2>&1 || brew install ninja
  81. brew list ccache > /dev/null 2>&1 || brew install ccache
  82. # (rollup 0.1.32, as Tests' App job: ccache between runs, per architecture; main saves it, other branches start from main's)
  83. - uses: actions/cache/restore@v4
  84. with:
  85. path: .ccache
  86. key: ccache-macapp-${{ matrix.arch }}-${{ needs.version.outputs.ref }}
  87. restore-keys: ccache-macapp-${{ matrix.arch }}-
  88. - name: JUCE (checksum verified)
  89. run: |
  90. curl -fsSL -o juce.tar.gz "https://github.com/juce-framework/JUCE/archive/refs/tags/$JUCE_VERSION.tar.gz"
  91. echo "$JUCE_SHA256 juce.tar.gz" | shasum -a 256 -c -
  92. mkdir -p "$RUNNER_TEMP/juce" && tar xzf juce.tar.gz -C "$RUNNER_TEMP/juce" --strip-components 1 && rm juce.tar.gz
  93. - name: Build (${{ matrix.arch }})
  94. run: |
  95. ccache --zero-stats > /dev/null
  96. cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DFETCHCONTENT_SOURCE_DIR_JUCE="$RUNNER_TEMP/juce" \
  97. -DCMAKE_OSX_ARCHITECTURES="${{ matrix.arch }}" \
  98. -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_OBJC_COMPILER_LAUNCHER=ccache -DCMAKE_OBJCXX_COMPILER_LAUNCHER=ccache
  99. # -j 2 on macOS (rollup 0.1.32 step 12): the macos-15 runner has 3 cores and 7 GB; three UI objects at once (clang peaks
  100. # 1.1-1.9 GB each) made it swap: single files took 17-41 min (seconds on Linux). Runner RAM, as round 190ov's Windows JOBS=2.
  101. cmake --build build --target LYNX -- -k 0 -j 2
  102. ccache --show-stats || true
  103. lipo -info build/LYNX_artefacts/Release/LYNX.app/Contents/MacOS/LYNX
  104. # (a tar keeps the bundle's symbolic links and modes through the artifact)
  105. tar -C build/LYNX_artefacts/Release -cf "LYNX-app-${{ matrix.arch }}.tar" LYNX.app
  106. - uses: actions/cache/save@v4
  107. if: always() && github.ref == 'refs/heads/main'
  108. with:
  109. path: .ccache
  110. key: ccache-macapp-${{ matrix.arch }}-${{ needs.version.outputs.ref }}
  111. - uses: actions/upload-artifact@v7
  112. with:
  113. name: macos-app-${{ matrix.arch }}
  114. path: LYNX-app-${{ matrix.arch }}.tar
  115. if-no-files-found: error
  116. retention-days: 3
  117. universal:
  118. name: macOS (universal dmg)
  119. needs: [version, build]
  120. runs-on: macos-15
  121. timeout-minutes: 60
  122. env:
  123. LABEL: ${{ needs.version.outputs.label }}
  124. steps:
  125. - uses: actions/checkout@v5
  126. with:
  127. ref: ${{ needs.version.outputs.ref }}
  128. - uses: actions/download-artifact@v8
  129. with:
  130. pattern: macos-app-*
  131. path: apps
  132. merge-multiple: true
  133. - name: Merge the two apps (lipo)
  134. run: |
  135. mkdir -p apps/arm64 apps/x86_64 merged
  136. tar -C apps/arm64 -xf apps/LYNX-app-arm64.tar
  137. tar -C apps/x86_64 -xf apps/LYNX-app-x86_64.tar
  138. cp -R apps/arm64/LYNX.app merged/LYNX.app
  139. n=0
  140. while IFS= read -r -d '' f; do
  141. rel="${f#apps/arm64/}"
  142. if file -b "$f" | grep -q 'Mach-O'; then
  143. [[ -f "apps/x86_64/$rel" ]] || { echo "::error::$rel has no x86_64 twin"; exit 1; }
  144. lipo -create "$f" "apps/x86_64/$rel" -output "merged/$rel"
  145. n=$((n + 1))
  146. fi
  147. done < <(find apps/arm64/LYNX.app -type f -print0)
  148. echo "merged $n Mach-O files"
  149. lipo -info merged/LYNX.app/Contents/MacOS/LYNX
  150. lipo -info merged/LYNX.app/Contents/MacOS/LYNX | grep -q 'x86_64 arm64\|arm64 x86_64'
  151. - name: Self-test and demo project
  152. run: |
  153. bin=merged/LYNX.app/Contents/MacOS/LYNX
  154. "$bin" --selftest "$PWD/selftest.txt" "$PWD/selftest-demo.lynx" || true
  155. cat selftest.txt
  156. grep -q '^result=OK' selftest.txt
  157. "$bin" --showcase "$PWD/Demo.lynx" || true
  158. test -s Demo.lynx
  159. - name: Package
  160. run: ./scripts/package-macos.sh merged/LYNX.app "$LABEL" dist Demo.lynx
  161. - name: Upload package
  162. uses: actions/upload-artifact@v7
  163. with:
  164. name: LYNX-${{ env.LABEL }}-macos-universal
  165. path: dist/*
  166. if-no-files-found: error
  167. attach:
  168. name: Attach to the release
  169. needs: [version, universal]
  170. if: ${{ github.event_name == 'workflow_dispatch' && startsWith(inputs.ref, 'v') }}
  171. runs-on: ubuntu-24.04
  172. permissions:
  173. contents: write
  174. env:
  175. LABEL: ${{ needs.version.outputs.label }}
  176. GH_TOKEN: ${{ github.token }}
  177. GH_REPO: ${{ github.repository }}
  178. TAG: ${{ inputs.ref }}
  179. steps:
  180. - uses: actions/download-artifact@v8
  181. with:
  182. name: LYNX-${{ env.LABEL }}-macos-universal
  183. path: dist
  184. - name: Upload the dmg and update SHA256SUMS.txt
  185. run: |
  186. cd dist
  187. ls -la
  188. gh release download "$TAG" -p SHA256SUMS.txt -D old
  189. grep -v -- '-macos-universal\.dmg$' old/SHA256SUMS.txt > SHA256SUMS.txt || true
  190. sha256sum -- *.dmg >> SHA256SUMS.txt
  191. cat SHA256SUMS.txt
  192. gh release upload "$TAG" ./*.dmg SHA256SUMS.txt --clobber