1
0

Taskfile.yml 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. version: '3'
  2. includes:
  3. common: ../Taskfile.yml
  4. vars:
  5. # Docker image for cross-compilation (used when building on non-macOS)
  6. CROSS_IMAGE: wails-cross
  7. tasks:
  8. build:
  9. summary: Builds the application
  10. cmds:
  11. # The experimental CGO-free backend (-tags purego, or WAILS_PUREGO=1) needs
  12. # no C toolchain, so it builds natively on every host; cgo builds
  13. # cross-compile through Docker.
  14. - task: '{{if or (eq OS "darwin") (has "purego" (splitList "," (.EXTRA_TAGS | default "")))}}build:native{{else}}build:docker{{end}}'
  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={{.VERSION}}"{{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:docker:
  57. summary: Cross-compiles for macOS using Docker (for Linux/Windows hosts)
  58. internal: true
  59. deps:
  60. - task: common:build:frontend
  61. vars:
  62. OBFUSCATED:
  63. ref: .OBFUSCATED
  64. - task: common:generate:icons
  65. preconditions:
  66. - sh: docker info > /dev/null 2>&1
  67. msg: "Docker is required for cross-compilation. Please install Docker."
  68. - sh: docker image inspect {{.CROSS_IMAGE}} > /dev/null 2>&1
  69. msg: |
  70. Docker image '{{.CROSS_IMAGE}}' not found.
  71. Build it first: wails3 task setup:docker
  72. cmds:
  73. - docker run --rm -v "{{.ROOT_DIR}}:/app" {{.DOCKER_MOUNTS}} -e APP_NAME="{{.APP_NAME}}" {{if .EXTRA_TAGS}}-e EXTRA_TAGS="{{.EXTRA_TAGS}}"{{end}} {{if eq .OBFUSCATED "true"}}-e OBFUSCATED=true{{end}} {{if .GARBLE_ARGS}}-e GARBLE_ARGS="{{.GARBLE_ARGS}}"{{end}} {{.CROSS_IMAGE}} darwin {{.DOCKER_ARCH}}
  74. - cmd: docker run --rm -v "{{.ROOT_DIR}}:/app" alpine chown -R $(id -u):$(id -g) /app/bin
  75. platforms: [linux, darwin]
  76. - mkdir -p {{.BIN_DIR}}
  77. - mv "bin/{{.APP_NAME}}-darwin-{{.DOCKER_ARCH}}" "{{.OUTPUT}}"
  78. vars:
  79. DOCKER_ARCH: '{{if eq .ARCH "arm64"}}arm64{{else if eq .ARCH "amd64"}}amd64{{else}}arm64{{end}}'
  80. DEFAULT_OUTPUT: '{{.BIN_DIR}}/{{.APP_NAME}}'
  81. OUTPUT: '{{ .OUTPUT | default .DEFAULT_OUTPUT }}'
  82. # Generate Docker volume mounts: Go module cache + go.mod replace directives
  83. # Uses wails3 tool docker-mounts for cross-platform compatibility (Windows/Linux/macOS)
  84. DOCKER_MOUNTS:
  85. sh: 'wails3 tool docker-mounts'
  86. build:universal:
  87. summary: Builds darwin universal binary (arm64 + amd64)
  88. deps:
  89. - task: build
  90. vars:
  91. ARCH: amd64
  92. OUTPUT: "{{.BIN_DIR}}/{{.APP_NAME}}-amd64"
  93. - task: build
  94. vars:
  95. ARCH: arm64
  96. OUTPUT: "{{.BIN_DIR}}/{{.APP_NAME}}-arm64"
  97. cmds:
  98. - task: '{{if eq OS "darwin"}}build:universal:lipo:native{{else}}build:universal:lipo:go{{end}}'
  99. build:universal:lipo:native:
  100. summary: Creates universal binary using native lipo (macOS)
  101. internal: true
  102. cmds:
  103. - lipo -create -output "{{.BIN_DIR}}/{{.APP_NAME}}" "{{.BIN_DIR}}/{{.APP_NAME}}-amd64" "{{.BIN_DIR}}/{{.APP_NAME}}-arm64"
  104. - rm "{{.BIN_DIR}}/{{.APP_NAME}}-amd64" "{{.BIN_DIR}}/{{.APP_NAME}}-arm64"
  105. build:universal:lipo:go:
  106. summary: Creates universal binary using wails3 tool lipo (Linux/Windows)
  107. internal: true
  108. cmds:
  109. - wails3 tool lipo -output "{{.BIN_DIR}}/{{.APP_NAME}}" -input "{{.BIN_DIR}}/{{.APP_NAME}}-amd64" -input "{{.BIN_DIR}}/{{.APP_NAME}}-arm64"
  110. - rm -f "{{.BIN_DIR}}/{{.APP_NAME}}-amd64" "{{.BIN_DIR}}/{{.APP_NAME}}-arm64"
  111. package:
  112. summary: Packages the application into a `.app` bundle
  113. deps:
  114. - task: build
  115. cmds:
  116. - task: create:app:bundle
  117. package:universal:
  118. summary: Packages darwin universal binary (arm64 + amd64)
  119. deps:
  120. - task: build:universal
  121. cmds:
  122. - task: create:app:bundle
  123. package:dmg:
  124. summary: Packages the application into a styled `.dmg`
  125. deps:
  126. - task: package
  127. cmds:
  128. - task: create:dmg
  129. create:dmg:
  130. summary: Creates a configurable `.dmg` from the `.app` bundle
  131. platforms: [darwin]
  132. cmds:
  133. - >-
  134. wails3 tool package --format dmg --name "{{.APP_NAME}}" --out "{{.BIN_DIR}}"
  135. --background "{{.DMG_BACKGROUND}}"
  136. --volume-icon "{{.DMG_VOLUME_ICON}}"
  137. --file-icon "{{.DMG_FILE_ICON}}"
  138. --window-width "{{.DMG_WINDOW_WIDTH}}"
  139. --window-height "{{.DMG_WINDOW_HEIGHT}}"
  140. {{if .DMG_FILES}}--files "{{.DMG_FILES}}"{{end}}
  141. vars:
  142. DMG_BACKGROUND: '{{.DMG_BACKGROUND | default "build/darwin/dmg-background.png"}}'
  143. DMG_VOLUME_ICON: '{{.DMG_VOLUME_ICON | default "build/darwin/icons.icns"}}'
  144. DMG_FILE_ICON: '{{.DMG_FILE_ICON | default "build/darwin/dmg-file-icon.icns"}}'
  145. DMG_WINDOW_WIDTH: '{{.DMG_WINDOW_WIDTH | default "540"}}'
  146. DMG_WINDOW_HEIGHT: '{{.DMG_WINDOW_HEIGHT | default "380"}}'
  147. DMG_FILES: '{{.DMG_FILES | default ""}}'
  148. create:app:bundle:
  149. summary: Creates an `.app` bundle
  150. cmds:
  151. # A reused bundle can acquire Finder metadata in synced folders. Build a
  152. # fresh bundle so codesign never has to replace a contaminated signature.
  153. - test -n "{{.BIN_DIR}}" && test -n "{{.APP_NAME}}" && rm -rf -- "{{.BIN_DIR}}/{{.APP_NAME}}.app"
  154. - mkdir -p "{{.BIN_DIR}}/{{.APP_NAME}}.app/Contents/MacOS"
  155. - mkdir -p "{{.BIN_DIR}}/{{.APP_NAME}}.app/Contents/Resources"
  156. - cp build/darwin/icons.icns "{{.BIN_DIR}}/{{.APP_NAME}}.app/Contents/Resources"
  157. - |
  158. if [ -f build/darwin/Assets.car ]; then
  159. cp build/darwin/Assets.car "{{.BIN_DIR}}/{{.APP_NAME}}.app/Contents/Resources"
  160. fi
  161. - cp "{{.BIN_DIR}}/{{.APP_NAME}}" "{{.BIN_DIR}}/{{.APP_NAME}}.app/Contents/MacOS"
  162. - cp build/darwin/Info.plist "{{.BIN_DIR}}/{{.APP_NAME}}.app/Contents"
  163. - task: '{{if eq OS "darwin"}}codesign:adhoc{{else}}codesign:skip{{end}}'
  164. codesign:adhoc:
  165. summary: Ad-hoc signs the app bundle (macOS only)
  166. internal: true
  167. cmds:
  168. - xattr -cr "{{.BIN_DIR}}/{{.APP_NAME}}.app"
  169. - codesign --force --deep --sign - "{{.BIN_DIR}}/{{.APP_NAME}}.app"
  170. - codesign --verify --deep --strict "{{.BIN_DIR}}/{{.APP_NAME}}.app"
  171. codesign:skip:
  172. summary: Skips codesigning when cross-compiling
  173. internal: true
  174. cmds:
  175. - 'echo "Skipping codesign (not available on {{OS}}). Sign the .app on macOS before distribution."'
  176. run:
  177. cmds:
  178. - wails3 tool prepare-macos-output --dir "{{.BIN_DIR}}"
  179. - test -n "{{.BIN_DIR}}" && test -n "{{.APP_NAME}}" && rm -rf -- "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app"
  180. - mkdir -p "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app/Contents/MacOS"
  181. - mkdir -p "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app/Contents/Resources"
  182. - cp build/darwin/icons.icns "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app/Contents/Resources"
  183. - |
  184. if [ -f build/darwin/Assets.car ]; then
  185. cp build/darwin/Assets.car "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app/Contents/Resources"
  186. fi
  187. - cp "{{.BIN_DIR}}/{{.APP_NAME}}" "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app/Contents/MacOS"
  188. - cp "build/darwin/Info.dev.plist" "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app/Contents/Info.plist"
  189. - xattr -cr "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app"
  190. - codesign --force --deep --sign - "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app"
  191. - codesign --verify --deep --strict "{{.BIN_DIR}}/{{.APP_NAME}}.dev.app"
  192. - '"{{.BIN_DIR}}/{{.APP_NAME}}.dev.app/Contents/MacOS/{{.APP_NAME}}"'
  193. sign:
  194. summary: Signs the application bundle with Developer ID
  195. desc: |
  196. Signs the .app bundle for distribution.
  197. Uses signing identity from `wails3 setup` (stored in ~/.config/wails/defaults.yaml).
  198. Override with: task darwin:sign -- --identity "Developer ID Application: ..."
  199. deps:
  200. - task: package
  201. cmds:
  202. - wails3 tool sign --input "{{.BIN_DIR}}/{{.APP_NAME}}.app" {{.CLI_ARGS}}
  203. sign:notarize:
  204. summary: Signs and notarizes the application bundle
  205. desc: |
  206. Signs the .app bundle and submits it for notarization.
  207. Uses signing identity and keychain profile from `wails3 setup`.
  208. First-time setup:
  209. wails3 setup
  210. deps:
  211. - task: package
  212. cmds:
  213. - wails3 tool sign --input "{{.BIN_DIR}}/{{.APP_NAME}}.app" --notarize {{.CLI_ARGS}}