1
0

Taskfile.yml 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. version: '3'
  2. includes:
  3. common: ../Taskfile.yml
  4. tasks:
  5. build:
  6. summary: Builds the application
  7. # MPCkit builds on each system natively; there is no Docker cross-build.
  8. # The experimental CGO-free backend (-tags purego) needs no C toolchain,
  9. # so only it can be built for macOS elsewhere.
  10. preconditions:
  11. - sh: '{{if or (eq OS "darwin") (has "purego" (splitList "," (.EXTRA_TAGS | default "")))}}true{{else}}false{{end}}'
  12. msg: "The macOS app must be built on a Mac."
  13. cmds:
  14. - task: build:native
  15. vars:
  16. ARCH: '{{.ARCH}}'
  17. DEV: '{{.DEV}}'
  18. OUTPUT: '{{.OUTPUT}}'
  19. EXTRA_TAGS: '{{.EXTRA_TAGS}}'
  20. OBFUSCATED: '{{.OBFUSCATED}}'
  21. GARBLE_ARGS: '{{.GARBLE_ARGS}}'
  22. vars:
  23. DEFAULT_OUTPUT: '{{.BIN_DIR}}/{{.APP_NAME}}'
  24. OUTPUT: '{{ .OUTPUT | default .DEFAULT_OUTPUT }}'
  25. build:native:
  26. summary: Builds the application natively (on macOS, or anywhere with -tags purego)
  27. internal: true
  28. deps:
  29. - task: common:go:mod:tidy
  30. - task: common:build:frontend
  31. vars:
  32. BUILD_FLAGS:
  33. ref: .BUILD_FLAGS
  34. OBFUSCATED:
  35. ref: .OBFUSCATED
  36. DEV:
  37. ref: .DEV
  38. - task: common:generate:icons
  39. preconditions:
  40. - sh: '{{if eq .OBFUSCATED "true"}}command -v garble >/dev/null 2>&1{{else}}true{{end}}'
  41. msg: "garble is required for obfuscated builds. Install it with: go install mvdan.cc/garble@v0.16.0 (requires Go 1.24+). See https://github.com/burrowers/garble/releases for version/toolchain compatibility."
  42. cmds:
  43. - wails3 tool prepare-macos-output --dir "{{.BIN_DIR}}"
  44. - '{{if eq .OBFUSCATED "true"}}garble {{.GARBLE_ARGS}} build{{else}}go build{{end}} {{.BUILD_FLAGS}} -o "{{.OUTPUT}}"'
  45. vars:
  46. BUILD_FLAGS: '{{if eq .DEV "true"}}{{if or .EXTRA_TAGS (eq .OBFUSCATED "true")}}-tags {{if eq .OBFUSCATED "true"}}wails_obfuscated{{if .EXTRA_TAGS}},{{end}}{{end}}{{.EXTRA_TAGS}} {{end}}-buildvcs=false -gcflags=all="-l"{{else}}-tags production{{if eq .OBFUSCATED "true"}},wails_obfuscated{{end}}{{if .EXTRA_TAGS}},{{.EXTRA_TAGS}}{{end}} -trimpath -buildvcs=false -ldflags="-w -s -X git.monoexp.com/bajdev/mpckit/internal/app.Version={{.APP_VERSION}} -X git.monoexp.com/bajdev/mpckit/internal/app.Commit={{.COMMIT}}"{{end}}'
  47. DEFAULT_OUTPUT: '{{.BIN_DIR}}/{{.APP_NAME}}'
  48. OUTPUT: '{{ .OUTPUT | default .DEFAULT_OUTPUT }}'
  49. env:
  50. GOOS: darwin
  51. CGO_ENABLED: '{{if (has "purego" (splitList "," (.EXTRA_TAGS | default "")))}}0{{else}}1{{end}}'
  52. GOARCH: '{{.ARCH | default ARCH}}'
  53. CGO_CFLAGS: "-mmacosx-version-min=12.0"
  54. CGO_LDFLAGS: "-mmacosx-version-min=12.0"
  55. MACOSX_DEPLOYMENT_TARGET: "12.0"
  56. build:universal:
  57. summary: Builds darwin universal binary (arm64 + amd64)
  58. deps:
  59. - task: build
  60. vars:
  61. ARCH: amd64
  62. OUTPUT: "{{.BIN_DIR}}/{{.APP_NAME}}-amd64"
  63. - task: build
  64. vars:
  65. ARCH: arm64
  66. OUTPUT: "{{.BIN_DIR}}/{{.APP_NAME}}-arm64"
  67. cmds:
  68. - task: '{{if eq OS "darwin"}}build:universal:lipo:native{{else}}build:universal:lipo:go{{end}}'
  69. build:universal:lipo:native:
  70. summary: Creates universal binary using native lipo (macOS)
  71. internal: true
  72. cmds:
  73. - lipo -create -output "{{.BIN_DIR}}/{{.APP_NAME}}" "{{.BIN_DIR}}/{{.APP_NAME}}-amd64" "{{.BIN_DIR}}/{{.APP_NAME}}-arm64"
  74. - rm "{{.BIN_DIR}}/{{.APP_NAME}}-amd64" "{{.BIN_DIR}}/{{.APP_NAME}}-arm64"
  75. build:universal:lipo:go:
  76. summary: Creates universal binary using wails3 tool lipo (Linux/Windows)
  77. internal: true
  78. cmds:
  79. - wails3 tool lipo -output "{{.BIN_DIR}}/{{.APP_NAME}}" -input "{{.BIN_DIR}}/{{.APP_NAME}}-amd64" -input "{{.BIN_DIR}}/{{.APP_NAME}}-arm64"
  80. - rm -f "{{.BIN_DIR}}/{{.APP_NAME}}-amd64" "{{.BIN_DIR}}/{{.APP_NAME}}-arm64"
  81. package:
  82. summary: Packages the application into a `.app` bundle
  83. deps:
  84. - task: build
  85. cmds:
  86. - task: create:app:bundle
  87. package:universal:
  88. summary: Packages darwin universal binary (arm64 + amd64)
  89. deps:
  90. - task: build:universal
  91. cmds:
  92. - task: create:app:bundle
  93. package:dmg:
  94. summary: Packages the application into a styled `.dmg`
  95. deps:
  96. - task: package
  97. cmds:
  98. - task: create:dmg
  99. create:dmg:
  100. summary: Creates a configurable `.dmg` from the `.app` bundle
  101. platforms: [darwin]
  102. cmds:
  103. - >-
  104. wails3 tool package --format dmg --name "{{.APP_NAME}}" --out "{{.BIN_DIR}}"
  105. --background "{{.DMG_BACKGROUND}}"
  106. --volume-icon "{{.DMG_VOLUME_ICON}}"
  107. --file-icon "{{.DMG_FILE_ICON}}"
  108. --window-width "{{.DMG_WINDOW_WIDTH}}"
  109. --window-height "{{.DMG_WINDOW_HEIGHT}}"
  110. {{if .DMG_FILES}}--files "{{.DMG_FILES}}"{{end}}
  111. vars:
  112. DMG_BACKGROUND: '{{.DMG_BACKGROUND | default "build/darwin/dmg-background.png"}}'
  113. DMG_VOLUME_ICON: '{{.DMG_VOLUME_ICON | default "build/darwin/icons.icns"}}'
  114. DMG_FILE_ICON: '{{.DMG_FILE_ICON | default "build/darwin/dmg-file-icon.icns"}}'
  115. DMG_WINDOW_WIDTH: '{{.DMG_WINDOW_WIDTH | default "540"}}'
  116. DMG_WINDOW_HEIGHT: '{{.DMG_WINDOW_HEIGHT | default "380"}}'
  117. DMG_FILES: '{{.DMG_FILES | default ""}}'
  118. create:app:bundle:
  119. summary: Creates an `.app` bundle
  120. cmds:
  121. # A reused bundle can acquire Finder metadata in synced folders. Build a
  122. # fresh bundle so codesign never has to replace a contaminated signature.
  123. - test -n "{{.BIN_DIR}}" && test -n "{{.APP_NAME}}" && rm -rf -- "{{.BIN_DIR}}/{{.APP_NAME}}.app"
  124. - mkdir -p "{{.BIN_DIR}}/{{.APP_NAME}}.app/Contents/MacOS"
  125. - mkdir -p "{{.BIN_DIR}}/{{.APP_NAME}}.app/Contents/Resources"
  126. - cp build/darwin/icons.icns "{{.BIN_DIR}}/{{.APP_NAME}}.app/Contents/Resources"
  127. - |
  128. if [ -f build/darwin/Assets.car ]; then
  129. cp build/darwin/Assets.car "{{.BIN_DIR}}/{{.APP_NAME}}.app/Contents/Resources"
  130. fi
  131. - cp "{{.BIN_DIR}}/{{.APP_NAME}}" "{{.BIN_DIR}}/{{.APP_NAME}}.app/Contents/MacOS"
  132. - cp build/darwin/Info.plist "{{.BIN_DIR}}/{{.APP_NAME}}.app/Contents"
  133. - task: '{{if eq OS "darwin"}}codesign:adhoc{{else}}codesign:skip{{end}}'
  134. codesign:adhoc:
  135. summary: Ad-hoc signs the app bundle (macOS only)
  136. internal: true
  137. cmds:
  138. - xattr -cr "{{.BIN_DIR}}/{{.APP_NAME}}.app"
  139. - codesign --force --deep --sign - "{{.BIN_DIR}}/{{.APP_NAME}}.app"
  140. - codesign --verify --deep --strict "{{.BIN_DIR}}/{{.APP_NAME}}.app"
  141. codesign:skip:
  142. summary: Skips codesigning when cross-compiling
  143. internal: true
  144. cmds:
  145. - 'echo "Skipping codesign (not available on {{OS}}). Sign the .app on macOS before distribution."'
  146. run:
  147. cmds:
  148. - wails3 tool prepare-macos-output --dir "{{.BIN_DIR}}"
  149. - test -n "{{.BIN_DIR}}" && test -n "{{.APP_NAME}}" && rm -rf -- "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app"
  150. - mkdir -p "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app/Contents/MacOS"
  151. - mkdir -p "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app/Contents/Resources"
  152. - cp build/darwin/icons.icns "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app/Contents/Resources"
  153. - |
  154. if [ -f build/darwin/Assets.car ]; then
  155. cp build/darwin/Assets.car "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app/Contents/Resources"
  156. fi
  157. - cp "{{.BIN_DIR}}/{{.APP_NAME}}" "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app/Contents/MacOS"
  158. - cp "build/darwin/Info.dev.plist" "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app/Contents/Info.plist"
  159. - xattr -cr "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app"
  160. - codesign --force --deep --sign - "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app"
  161. - codesign --verify --deep --strict "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app"
  162. - '"{{.BIN_DIR}}/{{.APP_NAME}}.dev.app/Contents/MacOS/{{.APP_NAME}}"'
  163. sign:
  164. summary: Signs the application bundle with Developer ID
  165. desc: |
  166. Signs the .app bundle for distribution.
  167. Uses signing identity from `wails3 setup` (stored in ~/.config/wails/defaults.yaml).
  168. Override with: task darwin:sign -- --identity "Developer ID Application: ..."
  169. deps:
  170. - task: package
  171. cmds:
  172. - wails3 tool sign --input "{{.BIN_DIR}}/{{.APP_NAME}}.app" {{.CLI_ARGS}}
  173. sign:notarize:
  174. summary: Signs and notarizes the application bundle
  175. desc: |
  176. Signs the .app bundle and submits it for notarization.
  177. Uses signing identity and keychain profile from `wails3 setup`.
  178. First-time setup:
  179. wails3 setup
  180. deps:
  181. - task: package
  182. cmds:
  183. - wails3 tool sign --input "{{.BIN_DIR}}/{{.APP_NAME}}.app" --notarize {{.CLI_ARGS}}