Taskfile.yml 9.5 KB

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