Taskfile.yml 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. version: '3'
  2. includes:
  3. common: ../Taskfile.yml
  4. vars:
  5. # Signing configuration - edit these values for your project
  6. SIGN_CERTIFICATE: "signing.pfx"
  7. # SIGN_THUMBPRINT: "certificate-thumbprint" # Alternative to SIGN_CERTIFICATE
  8. # TIMESTAMP_SERVER: "http://timestamp.digicert.com"
  9. #
  10. # Password is stored securely in system keychain. Run: wails3 setup signing
  11. # Docker image for cross-compilation with CGO (used when CGO_ENABLED=1 on non-Windows)
  12. CROSS_IMAGE: wails-cross
  13. tasks:
  14. build:
  15. summary: Builds the application for Windows
  16. cmds:
  17. # Auto-detect CGO: if CGO_ENABLED=1, use Docker; otherwise use native Go cross-compile
  18. - task: '{{if and (ne OS "windows") (eq .CGO_ENABLED "1")}}build:docker{{else}}build:native{{end}}'
  19. vars:
  20. ARCH: '{{.ARCH}}'
  21. DEV: '{{.DEV}}'
  22. EXTRA_TAGS: '{{.EXTRA_TAGS}}'
  23. OBFUSCATED: '{{.OBFUSCATED}}'
  24. GARBLE_ARGS: '{{.GARBLE_ARGS}}'
  25. vars:
  26. # 鼠标提醒依赖 CGO(syscall.NewCallback 从系统钩子线程进入 Go runtime),
  27. # 故默认启用 CGO=1;如无需 CGO 可显式传 CGO_ENABLED=0。
  28. CGO_ENABLED: '{{.CGO_ENABLED | default "1"}}'
  29. build:native:
  30. summary: Builds the application using native Go cross-compilation
  31. internal: true
  32. deps:
  33. - task: common:go:mod:tidy
  34. - task: common:build:frontend
  35. vars:
  36. BUILD_FLAGS:
  37. ref: .BUILD_FLAGS
  38. OBFUSCATED:
  39. ref: .OBFUSCATED
  40. DEV:
  41. ref: .DEV
  42. - task: common:generate:icons
  43. preconditions:
  44. - sh: '{{if eq .OBFUSCATED "true"}}command -v garble >/dev/null 2>&1{{else}}true{{end}}'
  45. 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."
  46. cmds:
  47. - task: generate:syso
  48. vars:
  49. ARCH: '{{.ARCH}}'
  50. - '{{if eq .OBFUSCATED "true"}}garble {{.GARBLE_ARGS}} build{{else}}go build{{end}} {{.BUILD_FLAGS}} -o "{{.BIN_DIR}}/{{.APP_NAME}}.exe"'
  51. - task: upx:compress
  52. vars:
  53. TARGET_FILE: '{{.BIN_DIR}}/{{.APP_NAME}}.exe'
  54. - cmd: powershell Remove-item *.syso
  55. platforms: [windows]
  56. - cmd: rm -f *.syso
  57. platforms: [linux, darwin]
  58. vars:
  59. 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 -H windowsgui"{{end}}'
  60. env:
  61. GOOS: windows
  62. CGO_ENABLED: '{{.CGO_ENABLED | default "1"}}'
  63. GOARCH: '{{.ARCH | default ARCH}}'
  64. build:docker:
  65. summary: Cross-compiles for Windows using Docker with Zig (for CGO builds on non-Windows)
  66. internal: true
  67. deps:
  68. - task: common:build:frontend
  69. vars:
  70. OBFUSCATED:
  71. ref: .OBFUSCATED
  72. - task: common:generate:icons
  73. preconditions:
  74. - sh: docker info > /dev/null 2>&1
  75. msg: "Docker is required for CGO cross-compilation. Please install Docker."
  76. - sh: docker image inspect {{.CROSS_IMAGE}} > /dev/null 2>&1
  77. msg: |
  78. Docker image '{{.CROSS_IMAGE}}' not found.
  79. Build it first: wails3 task setup:docker
  80. cmds:
  81. - task: generate:syso
  82. vars:
  83. ARCH: '{{.ARCH}}'
  84. - 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}} windows {{.DOCKER_ARCH}}
  85. - cmd: docker run --rm -v "{{.ROOT_DIR}}:/app" alpine chown -R $(id -u):$(id -g) /app/bin
  86. platforms: [linux, darwin]
  87. - rm -f *.syso
  88. vars:
  89. DOCKER_ARCH: '{{.ARCH | default "amd64"}}'
  90. # Generate Docker volume mounts: Go module cache + go.mod replace directives
  91. # Uses wails3 tool docker-mounts for cross-platform compatibility (Windows/Linux/macOS)
  92. DOCKER_MOUNTS:
  93. sh: 'wails3 tool docker-mounts'
  94. package:
  95. summary: Packages the application
  96. cmds:
  97. - task: '{{if eq (.FORMAT | default "nsis") "msix"}}create:msix:package{{else}}create:nsis:installer{{end}}'
  98. vars:
  99. INSTALL_SCOPE: '{{.INSTALL_SCOPE | default "machine"}}'
  100. vars:
  101. FORMAT: '{{.FORMAT | default "nsis"}}'
  102. INSTALL_SCOPE: '{{.INSTALL_SCOPE | default "machine"}}'
  103. generate:syso:
  104. summary: Generates Windows `.syso` file
  105. dir: build
  106. cmds:
  107. - wails3 generate syso -arch {{.ARCH}} -icon windows/icon.ico -manifest windows/wails.exe.manifest -info windows/info.json -out ../wails_windows_{{.ARCH}}.syso
  108. vars:
  109. ARCH: '{{.ARCH | default ARCH}}'
  110. upx:compress:
  111. summary: Compress the built binary with UPX (if available)
  112. internal: true
  113. cmds:
  114. - |
  115. if [ "{{.DEV}}" = "true" ]; then
  116. echo "DEV mode, skipping UPX."
  117. exit 0
  118. fi
  119. if command -v upx >/dev/null 2>&1; then
  120. echo "Compressing {{.TARGET_FILE}} with UPX..."
  121. upx --best --lzma "{{.TARGET_FILE}}" || true
  122. else
  123. echo "UPX not found in PATH, skipping compression."
  124. fi
  125. vars:
  126. TARGET_FILE: '{{.TARGET_FILE}}'
  127. create:nsis:installer:
  128. summary: Creates an NSIS installer
  129. dir: build/windows/nsis
  130. deps:
  131. - task: build
  132. preconditions:
  133. - sh: '[ "{{.INSTALL_SCOPE}}" = "user" ] || [ "{{.INSTALL_SCOPE}}" = "machine" ]'
  134. msg: "INSTALL_SCOPE must be 'user' or 'machine', got '{{.INSTALL_SCOPE}}'"
  135. cmds:
  136. # Create the Microsoft WebView2 bootstrapper if it doesn't exist
  137. - wails3 generate webview2bootstrapper -dir "{{.ROOT_DIR}}/build/windows/nsis"
  138. - |
  139. {{if eq OS "windows"}}
  140. makensis {{if eq .INSTALL_SCOPE "user"}}-DWAILS_INSTALL_SCOPE=user -DREQUEST_EXECUTION_LEVEL=user {{end}}-DARG_WAILS_{{.ARG_FLAG}}_BINARY="{{.ROOT_DIR}}\{{.BIN_DIR}}\{{.APP_NAME}}.exe" project.nsi
  141. {{else}}
  142. makensis {{if eq .INSTALL_SCOPE "user"}}-DWAILS_INSTALL_SCOPE=user -DREQUEST_EXECUTION_LEVEL=user {{end}}-DARG_WAILS_{{.ARG_FLAG}}_BINARY="{{.ROOT_DIR}}/{{.BIN_DIR}}/{{.APP_NAME}}.exe" project.nsi
  143. {{end}}
  144. vars:
  145. ARCH: '{{.ARCH | default ARCH}}'
  146. ARG_FLAG: '{{if eq .ARCH "amd64"}}AMD64{{else}}ARM64{{end}}'
  147. INSTALL_SCOPE: '{{.INSTALL_SCOPE | default "machine"}}'
  148. create:msix:package:
  149. summary: Creates an MSIX package
  150. deps:
  151. - task: build
  152. cmds:
  153. - |-
  154. wails3 tool msix \
  155. --config "{{.ROOT_DIR}}/build/config.yml" \
  156. --name "{{.APP_NAME}}.exe" \
  157. --executable "{{.ROOT_DIR}}/{{.BIN_DIR}}/{{.APP_NAME}}.exe" \
  158. --arch "{{.ARCH}}" \
  159. --out "{{.ROOT_DIR}}/{{.BIN_DIR}}/{{.APP_NAME}}-{{.ARCH}}.msix" \
  160. {{if .CERT_PATH}}--cert "{{.CERT_PATH}}"{{end}} \
  161. {{if .PUBLISHER}}--publisher "{{.PUBLISHER}}"{{end}} \
  162. {{if eq .USE_MSIX_TOOL "true"}}--use-msix-tool{{else}}--use-makeappx{{end}}
  163. vars:
  164. ARCH: '{{.ARCH | default ARCH}}'
  165. CERT_PATH: '{{.CERT_PATH | default ""}}'
  166. PUBLISHER: '{{.PUBLISHER | default ""}}'
  167. USE_MSIX_TOOL: '{{.USE_MSIX_TOOL | default "false"}}'
  168. install:msix:tools:
  169. summary: Installs tools required for MSIX packaging
  170. cmds:
  171. - wails3 tool msix-install-tools
  172. run:
  173. cmds:
  174. - '{{.BIN_DIR}}/{{.APP_NAME}}.exe'
  175. sign:
  176. summary: Signs the Windows executable
  177. desc: |
  178. Signs the .exe with an Authenticode certificate.
  179. Set SIGN_CERTIFICATE or SIGN_THUMBPRINT to override the certificate
  180. configured globally via `wails3 setup` (~/.config/wails/defaults.yaml).
  181. Password is retrieved from system keychain (run: wails3 setup signing)
  182. deps:
  183. - task: build
  184. cmds:
  185. # Certificate vars are optional: if unset, `wails3 tool sign` falls back to
  186. # the certificate configured globally via `wails3 setup`.
  187. - wails3 tool sign --input "{{.BIN_DIR}}/{{.APP_NAME}}.exe" {{if .SIGN_CERTIFICATE}}--certificate "{{.SIGN_CERTIFICATE}}"{{end}} {{if .SIGN_THUMBPRINT}}--thumbprint "{{.SIGN_THUMBPRINT}}"{{end}} {{if .TIMESTAMP_SERVER}}--timestamp "{{.TIMESTAMP_SERVER}}"{{end}}
  188. sign:installer:
  189. summary: Signs the NSIS installer
  190. desc: |
  191. Creates and signs the NSIS installer.
  192. Set SIGN_CERTIFICATE or SIGN_THUMBPRINT to override the certificate
  193. configured globally via `wails3 setup` (~/.config/wails/defaults.yaml).
  194. Password is retrieved from system keychain (run: wails3 setup signing)
  195. deps:
  196. - task: create:nsis:installer
  197. vars:
  198. INSTALL_SCOPE: '{{.INSTALL_SCOPE | default "machine"}}'
  199. vars:
  200. INSTALL_SCOPE: '{{.INSTALL_SCOPE | default "machine"}}'
  201. cmds:
  202. - wails3 tool sign --input "build/windows/nsis/{{.APP_NAME}}-installer.exe" {{if .SIGN_CERTIFICATE}}--certificate "{{.SIGN_CERTIFICATE}}"{{end}} {{if .SIGN_THUMBPRINT}}--thumbprint "{{.SIGN_THUMBPRINT}}"{{end}} {{if .TIMESTAMP_SERVER}}--timestamp "{{.TIMESTAMP_SERVER}}"{{end}}