Taskfile.yml 9.0 KB

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