Taskfile.yml 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. version: '3'
  2. includes:
  3. common: ../Taskfile.yml
  4. vars:
  5. # Signing configuration - edit these values for your project
  6. # SIGN_CERTIFICATE: "path/to/certificate.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. - cmd: powershell Remove-item *.syso
  51. platforms: [windows]
  52. - cmd: rm -f *.syso
  53. platforms: [linux, darwin]
  54. vars:
  55. 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}}'
  56. env:
  57. GOOS: windows
  58. CGO_ENABLED: '{{.CGO_ENABLED | default "0"}}'
  59. GOARCH: '{{.ARCH | default ARCH}}'
  60. build:docker:
  61. summary: Cross-compiles for Windows using Docker with Zig (for CGO builds on non-Windows)
  62. internal: true
  63. deps:
  64. - task: common:build:frontend
  65. vars:
  66. OBFUSCATED:
  67. ref: .OBFUSCATED
  68. - task: common:generate:icons
  69. preconditions:
  70. - sh: docker info > /dev/null 2>&1
  71. msg: "Docker is required for CGO cross-compilation. Please install Docker."
  72. - sh: docker image inspect {{.CROSS_IMAGE}} > /dev/null 2>&1
  73. msg: |
  74. Docker image '{{.CROSS_IMAGE}}' not found.
  75. Build it first: wails3 task setup:docker
  76. cmds:
  77. - task: generate:syso
  78. vars:
  79. ARCH: '{{.ARCH}}'
  80. - 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}}
  81. - cmd: docker run --rm -v "{{.ROOT_DIR}}:/app" alpine chown -R $(id -u):$(id -g) /app/bin
  82. platforms: [linux, darwin]
  83. - rm -f *.syso
  84. vars:
  85. DOCKER_ARCH: '{{.ARCH | default "amd64"}}'
  86. # Generate Docker volume mounts: Go module cache + go.mod replace directives
  87. # Uses wails3 tool docker-mounts for cross-platform compatibility (Windows/Linux/macOS)
  88. DOCKER_MOUNTS:
  89. sh: 'wails3 tool docker-mounts'
  90. package:
  91. summary: Packages the application
  92. cmds:
  93. - task: '{{if eq (.FORMAT | default "nsis") "msix"}}create:msix:package{{else}}create:nsis:installer{{end}}'
  94. vars:
  95. INSTALL_SCOPE: '{{.INSTALL_SCOPE | default "machine"}}'
  96. vars:
  97. FORMAT: '{{.FORMAT | default "nsis"}}'
  98. INSTALL_SCOPE: '{{.INSTALL_SCOPE | default "machine"}}'
  99. generate:syso:
  100. summary: Generates Windows `.syso` file
  101. dir: build
  102. cmds:
  103. - wails3 generate syso -arch {{.ARCH}} -icon windows/icon.ico -manifest windows/wails.exe.manifest -info windows/info.json -out ../wails_windows_{{.ARCH}}.syso
  104. vars:
  105. ARCH: '{{.ARCH | default ARCH}}'
  106. create:nsis:installer:
  107. summary: Creates an NSIS installer
  108. dir: build/windows/nsis
  109. deps:
  110. - task: build
  111. preconditions:
  112. - sh: '[ "{{.INSTALL_SCOPE}}" = "user" ] || [ "{{.INSTALL_SCOPE}}" = "machine" ]'
  113. msg: "INSTALL_SCOPE must be 'user' or 'machine', got '{{.INSTALL_SCOPE}}'"
  114. cmds:
  115. # Create the Microsoft WebView2 bootstrapper if it doesn't exist
  116. - wails3 generate webview2bootstrapper -dir "{{.ROOT_DIR}}/build/windows/nsis"
  117. - |
  118. {{if eq OS "windows"}}
  119. 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
  120. {{else}}
  121. 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
  122. {{end}}
  123. vars:
  124. ARCH: '{{.ARCH | default ARCH}}'
  125. ARG_FLAG: '{{if eq .ARCH "amd64"}}AMD64{{else}}ARM64{{end}}'
  126. INSTALL_SCOPE: '{{.INSTALL_SCOPE | default "machine"}}'
  127. create:msix:package:
  128. summary: Creates an MSIX package
  129. deps:
  130. - task: build
  131. cmds:
  132. - |-
  133. wails3 tool msix \
  134. --config "{{.ROOT_DIR}}/build/config.yml" \
  135. --name "{{.APP_NAME}}.exe" \
  136. --executable "{{.ROOT_DIR}}/{{.BIN_DIR}}/{{.APP_NAME}}.exe" \
  137. --arch "{{.ARCH}}" \
  138. --out "{{.ROOT_DIR}}/{{.BIN_DIR}}/{{.APP_NAME}}-{{.ARCH}}.msix" \
  139. {{if .CERT_PATH}}--cert "{{.CERT_PATH}}"{{end}} \
  140. {{if .PUBLISHER}}--publisher "{{.PUBLISHER}}"{{end}} \
  141. {{if eq .USE_MSIX_TOOL "true"}}--use-msix-tool{{else}}--use-makeappx{{end}}
  142. vars:
  143. ARCH: '{{.ARCH | default ARCH}}'
  144. CERT_PATH: '{{.CERT_PATH | default ""}}'
  145. PUBLISHER: '{{.PUBLISHER | default ""}}'
  146. USE_MSIX_TOOL: '{{.USE_MSIX_TOOL | default "false"}}'
  147. install:msix:tools:
  148. summary: Installs tools required for MSIX packaging
  149. cmds:
  150. - wails3 tool msix-install-tools
  151. run:
  152. cmds:
  153. - '{{.BIN_DIR}}/{{.APP_NAME}}.exe'
  154. sign:
  155. summary: Signs the Windows executable
  156. desc: |
  157. Signs the .exe with an Authenticode certificate.
  158. Set SIGN_CERTIFICATE or SIGN_THUMBPRINT to override the certificate
  159. configured globally via `wails3 setup` (~/.config/wails/defaults.yaml).
  160. Password is retrieved from system keychain (run: wails3 setup signing)
  161. deps:
  162. - task: build
  163. cmds:
  164. # Certificate vars are optional: if unset, `wails3 tool sign` falls back to
  165. # the certificate configured globally via `wails3 setup`.
  166. - 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}}
  167. sign:installer:
  168. summary: Signs the NSIS installer
  169. desc: |
  170. Creates and signs the NSIS installer.
  171. Set SIGN_CERTIFICATE or SIGN_THUMBPRINT to override the certificate
  172. configured globally via `wails3 setup` (~/.config/wails/defaults.yaml).
  173. Password is retrieved from system keychain (run: wails3 setup signing)
  174. deps:
  175. - task: create:nsis:installer
  176. vars:
  177. INSTALL_SCOPE: '{{.INSTALL_SCOPE | default "machine"}}'
  178. vars:
  179. INSTALL_SCOPE: '{{.INSTALL_SCOPE | default "machine"}}'
  180. cmds:
  181. - 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}}