summaryrefslogtreecommitdiff
path: root/.github/workflows/build-windows.yml
blob: 8cb10042bc71847c8085de9d528a882f115234f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
name: Build Windows x86_64

on:
  workflow_call:
    inputs:
      version:
        description: "WSJT-X version string"
        required: true
        type: string
      hamlib_branch:
        description: "Hamlib branch to build"
        required: false
        type: string
        default: "4.7.2"
      cold_build:
        description: "Bypass workflow dependency and compiler caches without saving them"
        required: false
        type: boolean
        default: false
      recache:
        description: "Force ccache to recompile and refresh cached objects"
        required: false
        type: boolean
        default: false
      save_ccache:
        description: "Persist compiler objects from a trusted develop build"
        required: false
        type: boolean
        default: false
    outputs:
      installer-artifact-id:
        description: "Installer artifact id, for the SignPath submit step"
        value: ${{ jobs.build.outputs.installer-artifact-id }}
  # Also runnable on its own ("Run workflow" / gh workflow run) to build just
  # the Windows installer, at ~1/6 the cost of the full ci.yml matrix. GitHub
  # only exposes workflow_dispatch when the trigger is present on the default
  # branch, so this must be merged to develop before it can be dispatched.
  # Inputs mirror workflow_call with standalone defaults: hamlib_branch matches
  # what ci.yml / release.yml actually pass (4.7.2, not the workflow_call legacy
  # default), and version defaults to a clearly-marked devel string -- overridable
  # via `-f version=...` -- so a manual build is never mistaken for a release.
  # release_channel and prerelease_number exist only here, to override
  # release-state.txt.
  workflow_dispatch:
    inputs:
      version:
        description: "WSJT-X version string (installer filename + artifact names)"
        required: false
        type: string
        default: "3.2.0-devel"
      hamlib_branch:
        description: "Hamlib branch to build"
        required: false
        type: string
        default: "4.7.2"
      cold_build:
        description: "Bypass workflow dependency and compiler caches without saving them"
        required: false
        type: boolean
        default: false
      recache:
        description: "Force ccache to recompile and refresh cached objects"
        required: false
        type: boolean
        default: false
      save_ccache:
        description: "Persist compiler objects when dispatching on develop"
        required: false
        type: boolean
        default: true
      release_channel:
        description: "Build release channel"
        required: false
        type: choice
        options:
          - DEVEL
          - BETA
          - RC
          - GA
        default: "DEVEL"
      prerelease_number:
        description: "Prerelease number when release_channel is BETA or RC"
        required: false
        type: string
        default: ""

jobs:
  build:
    runs-on: windows-latest
    timeout-minutes: 100
    outputs:
      installer-artifact-id: ${{ steps.upload_installer.outputs.artifact-id }}
    env:
      BOOST_VERSION: 1.91.0
      BOOST_SOURCE_SHA256: de5e6b0e4913395c6bdfa90537febd9028ea4c0735d2cdb0cd9b45d5f51264f5
      WSJT_WINDOWS_API_FLOOR: "0x0601"
      VERSION: ${{ inputs.version }}
      HAMLIB_BRANCH: ${{ inputs.hamlib_branch }}
      WSJT_RELEASE_CHANNEL: ${{ inputs.release_channel }}
      WSJT_PRERELEASE_NUMBER: ${{ inputs.prerelease_number }}
    defaults:
      run:
        shell: msys2 {0}
    steps:
      # windows-latest's git defaults to core.autocrlf=true, which converts
      # text-file line endings during checkout. The converted working tree
      # then differs from the index, so cmake/getsvn.cmake's git_local_changes
      # reports DIRTY and the resulting binary's About tab shows
      # "wsjtx-<ver>-<sha>-dirty". Disable autocrlf before checkout so the
      # working tree matches the index exactly. (No-op on macOS/Linux runners,
      # which already default to autocrlf=false; this fix is Windows-only.)
      - name: Disable core.autocrlf before checkout
        shell: pwsh
        run: git config --global core.autocrlf false

      - uses: actions/checkout@v7

      - name: Validate workflow inputs
        shell: bash
        env:
          WSJTX_VERSION: ${{ inputs.version }}
        run: .github/scripts/validate-ci-inputs.sh

      # Boost is source-built by build-windows-deps so the Windows 7 API floor
      # and Boost.Atomic patch stay pinned; do not install MSYS2 Boost here.
      - uses: msys2/setup-msys2@v2
        with:
          msystem: MINGW64
          update: true
          cache: ${{ !inputs.cold_build }}
          install: >-
            git make tar
            mingw-w64-x86_64-gcc
            mingw-w64-x86_64-gcc-fortran
            mingw-w64-x86_64-ccache
            mingw-w64-x86_64-cmake
            mingw-w64-x86_64-qt5-base
            mingw-w64-x86_64-qt5-multimedia
            mingw-w64-x86_64-qt5-serialport
            mingw-w64-x86_64-qt5-svg
            mingw-w64-x86_64-qt5-tools
            mingw-w64-x86_64-qt5-websockets
            mingw-w64-x86_64-qt5-activeqt
            mingw-w64-x86_64-fftw
            mingw-w64-x86_64-libusb
            mingw-w64-x86_64-portaudio
            mingw-w64-x86_64-pkg-config
            mingw-w64-x86_64-nsis
            mingw-w64-x86_64-ruby
            autoconf automake libtool

      # asciidoctor is a Ruby gem (no native MSYS2 package) — needed by
      # doc/CMakeLists.txt to build the WSJT-X user guide HTML referenced
      # by Help → Local User Guide.
      - name: Install asciidoctor (Ruby gem)
        run: gem install asciidoctor --no-document

      - name: Select ccache key
        id: ccache-key
        shell: bash
        env:
          RECACHE: ${{ inputs.recache }}
        run: .github/scripts/select-ccache-key-suffix.sh

      - name: Restore ccache
        id: ccache
        if: ${{ !inputs.cold_build }}
        uses: actions/cache/restore@v6
        with:
          path: .ccache
          key: ccache-windows-x86_64-gcc-${{ github.sha }}${{ steps.ccache-key.outputs.suffix }}
          restore-keys: |
            ccache-windows-x86_64-gcc-

      - name: Configure ccache
        run: |
          WORKSPACE=$(cygpath "${GITHUB_WORKSPACE}")
          if [ "${{ inputs.cold_build }}" = "true" ]; then
            echo "CCACHE_DIR=$(mktemp -d)" >> "$GITHUB_ENV"
          else
            echo "CCACHE_DIR=${WORKSPACE}/.ccache" >> "$GITHUB_ENV"
          fi
          echo "ccache recache: ${{ inputs.recache }}"
          if [ "${{ inputs.recache }}" = "true" ]; then
            echo "CCACHE_RECACHE=1" >> "$GITHUB_ENV"
            echo "Forcing ccache recache for this run"
          fi
          mkdir -p "${WORKSPACE}/.ccache"
          ccache --version
          ccache --zero-stats

      - name: Build Windows dependencies
        id: windows-deps
        uses: ./.github/actions/build-windows-deps
        with:
          boost_version: ${{ env.BOOST_VERSION }}
          boost_source_sha256: ${{ env.BOOST_SOURCE_SHA256 }}
          windows_api_floor: ${{ env.WSJT_WINDOWS_API_FLOOR }}
          hamlib_branch: ${{ inputs.hamlib_branch }}
          cold_build: ${{ inputs.cold_build }}
          save_caches: ${{ github.event_name != 'pull_request' }}

      - name: Install OmniRig
        shell: pwsh
        run: |
          # Download OmniRig (provides type library embedded in OmniRig.exe for dumpcpp)
          Invoke-WebRequest -Uri "https://www.dxatlas.com/OmniRig/Files/OmniRig.zip" -OutFile OmniRig.zip
          Expand-Archive -Path OmniRig.zip -DestinationPath omnirig-extract
          # Run the installer silently (InnoSetup)
          $setup = Get-ChildItem -Path omnirig-extract -Filter "*.exe" -Recurse | Select-Object -First 1
          if (-not $setup) { throw "No installer found in OmniRig.zip" }
          Start-Process -FilePath $setup.FullName -ArgumentList '/VERYSILENT','/NORESTART' -Wait
          # Locate the installed OmniRig.exe (embeds the COM type library)
          $omnirig = Get-ChildItem -Path "C:\Program Files*\Afreet\OmniRig" -Filter "OmniRig.exe" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1
          if (-not $omnirig) { throw "OmniRig install failed — OmniRig.exe not found" }
          echo "OMNIRIG_PATH=$($omnirig.FullName)" >> $env:GITHUB_ENV

      - name: Configure build and tests
        run: |
          WORKSPACE=$(cygpath "${GITHUB_WORKSPACE}")
          OMNIRIG=$(cygpath "${OMNIRIG_PATH}")
          BOOST_PREFIX="${{ steps.windows-deps.outputs.boost_prefix }}"
          HAMLIB_PREFIX="${{ steps.windows-deps.outputs.hamlib_prefix }}"
          cmake -G "MSYS Makefiles" -S . -B wsjtx-build \
            -DCMAKE_PREFIX_PATH="${BOOST_PREFIX};${HAMLIB_PREFIX}" \
            -DBOOST_ROOT="${BOOST_PREFIX}" \
            -DBOOST_INCLUDEDIR="${BOOST_PREFIX}/include" \
            -DBOOST_LIBRARYDIR="${BOOST_PREFIX}/lib" \
            -DHamlib_INCLUDE_DIR="${HAMLIB_PREFIX}/include" \
            -DHamlib_LIBRARY="${HAMLIB_PREFIX}/lib/libhamlib.dll.a" \
            -DRIGCTL_EXE="${HAMLIB_PREFIX}/bin/rigctl.exe" \
            -DRIGCTLD_EXE="${HAMLIB_PREFIX}/bin/rigctld.exe" \
            -DRIGCTLCOM_EXE="${HAMLIB_PREFIX}/bin/rigctlcom.exe" \
            -DCMAKE_C_FLAGS="-D_WIN32_WINNT=${WSJT_WINDOWS_API_FLOOR} -DWINVER=${WSJT_WINDOWS_API_FLOOR}" \
            -DCMAKE_CXX_FLAGS="-D_WIN32_WINNT=${WSJT_WINDOWS_API_FLOOR} -DWINVER=${WSJT_WINDOWS_API_FLOOR} -DBOOST_USE_WINAPI_VERSION=${WSJT_WINDOWS_API_FLOOR}" \
            -DBoost_NO_SYSTEM_PATHS=ON \
            -DCMAKE_C_COMPILER_LAUNCHER=ccache \
            -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
            -DOMNIRIG_TYPE_LIB="${OMNIRIG}" \
            -DCMAKE_Fortran_FLAGS="-fallow-argument-mismatch -std=legacy" \
            -DWSJT_SKIP_MANPAGES=ON \
            -DWSJT_ENABLE_TESTS=ON \
            -DWSJT_ENABLE_GUI_SMOKE_TESTS=ON \
            -DWSJT_FORTRAN_LIBRARY_VARIANTS=OPENMP_ONLY \
            -DWSJT_RELEASE_CHANNEL="${WSJT_RELEASE_CHANNEL}" \
            -DWSJT_PRERELEASE_NUMBER="${WSJT_PRERELEASE_NUMBER}" \
            -DPFUNIT_DIR="${{ steps.windows-deps.outputs.pfunit_dir }}" \
            -DGFTL_DIR="${{ steps.windows-deps.outputs.gftl_dir }}" \
            -DGFTL_SHARED_DIR="${{ steps.windows-deps.outputs.gftl_shared_dir }}" \
            -DFARGPARSE_DIR="${{ steps.windows-deps.outputs.fargparse_dir }}" \
            -Wno-dev

      - name: Build and test targets
        id: compile
        run: cmake --build wsjtx-build -j$(nproc)

      - name: Show ccache stats
        if: always()
        run: ccache --show-stats

      - name: Report suppressed ccache save
        if: ${{ !inputs.cold_build && (inputs.save_ccache || inputs.recache) && github.ref != 'refs/heads/develop' }}
        run: echo "::notice::Not saving ccache because shared compiler caches are published only from develop"

      - name: Save ccache
        if: ${{ !inputs.cold_build && success() && (inputs.save_ccache || inputs.recache) && github.ref == 'refs/heads/develop' && steps.ccache.outputs.cache-hit != 'true' }}
        uses: actions/cache/save@v6
        with:
          path: .ccache
          key: ${{ steps.ccache.outputs.cache-primary-key }}

      - name: Run tests
        id: ctest
        run: |
          # Tests that link wsjt_qt (e.g. test_jtty_txstream) pull in the
          # rig-control code, so their exe imports libhamlib-4.dll. Hamlib is
          # built --enable-shared into hamlib-prefix, so hamlib-prefix/bin must
          # be on PATH for the test to load — the mingw runtime DLLs are already
          # reachable via /mingw64/bin, but hamlib-prefix is not. Without this
          # the test exits 0xc0000135 (STATUS_DLL_NOT_FOUND) at launch. The
          # packaged installer is unaffected: cpack's bundle_fixup copies
          # libhamlib-4.dll in.
          export PATH="${{ steps.windows-deps.outputs.boost_prefix }}/lib:${{ steps.windows-deps.outputs.hamlib_prefix }}/bin:${PATH}"
          ctest --output-on-failure --output-junit ctest-results.xml
          python3 - <<'PY'
          import xml.etree.ElementTree as ET

          root = ET.parse('ctest-results.xml').getroot()
          for name in ('test_wsjtx_live_audio_jtty', 'test_wsjtx_jtty_tx_loopback',
                       'test_wsjtx_jt9_wav', 'test_wsjtx_jt65_wav', 'test_wsjtx_q65_wav',
                       'test_wsjtx_fst4_wav', 'test_wsjtx_fst4w_wav'):
              test = root.find(f".//testcase[@name='{name}']")
              if test is None or test.find('failure') is not None or test.find('skipped') is not None:
                  raise SystemExit(f'{name} was not executed successfully')
              print(f'{name} passed')
          PY
        working-directory: wsjtx-build

      - name: Publish test summary
        if: always() && steps.ctest.conclusion != 'skipped'
        working-directory: wsjtx-build
        run: python3 ../.github/scripts/publish-ctest-summary.py "Windows x86_64" >> "$GITHUB_STEP_SUMMARY"

      - name: Upload test results
        if: always() && steps.ctest.conclusion != 'skipped'
        uses: actions/upload-artifact@v7
        with:
          name: ctest-results-windows
          path: wsjtx-build/ctest-results.xml
          if-no-files-found: ignore

      # MAP65 builds by default again. Under OPENMP_ONLY, m65impl resolves
      # wsjt_fort_common to wsjt_fort_omp, so this keeps the Windows Fortran
      # linkage covered by CI.
      - name: Verify binary
        run: |
          file wsjtx-build/jt9.exe
          file wsjtx-build/map65/map65.exe
          test -f wsjtx-build/map65/map65.exe

      # Install to a staging prefix so bundle_fixup runs: its install(CODE)
      # step copies Qt and dependent runtime DLLs next to the installed
      # executables, making bin/ self-contained. Build-tree binaries are NOT
      # self-contained (they resolve Qt/libgfortran/libgomp via /mingw64/bin),
      # so the launch check below must run against the staged install, not the
      # build tree — otherwise it would fail for binaries that ship fine.
      - name: Stage install (runs bundle_fixup)
        run: |
          WORKSPACE=$(cygpath "${GITHUB_WORKSPACE}")
          cmake --install wsjtx-build --prefix "${WORKSPACE}/stage-main"
          ls -la "${WORKSPACE}/stage-main/bin"

      - name: Audit staged runtime DLL imports
        run: |
          WORKSPACE=$(cygpath "${GITHUB_WORKSPACE}")
          test -f "${WORKSPACE}/stage-main/bin/map65.exe"
          test -f "${WORKSPACE}/stage-main/bin/qmap.exe"
          bash .github/scripts/audit-staged-dll-imports-windows.sh \
            "${WORKSPACE}/stage-main/bin" \
            "${WORKSPACE}"/stage-main/bin/*.exe \
            "${WORKSPACE}"/stage-main/bin/*.dll

      - name: Smoke-launch staged WSJT-X (clean PATH)
        id: wsjtx_smoke
        run: |
          WORKSPACE=$(cygpath "${GITHUB_WORKSPACE}")
          .github/scripts/smoke-launch-windows.sh \
            "${WORKSPACE}/stage-main/bin/wsjtx.exe" \
            --startup-smoke-test --rig-name CI-STARTUP

      - name: Upload WSJT-X startup diagnostics
        if: failure() && steps.wsjtx_smoke.outcome == 'failure'
        uses: actions/upload-artifact@v7
        with:
          name: wsjtx-startup-smoke-windows
          path: launch.out
          if-no-files-found: ignore
          retention-days: 7

      - name: Smoke-launch staged jt9 (clean PATH)
        run: |
          WORKSPACE=$(cygpath "${GITHUB_WORKSPACE}")
          .github/scripts/smoke-launch-windows.sh "${WORKSPACE}/stage-main/bin/jt9.exe" --help

      - name: Package release tarballs
        run: |
          WORKSPACE=$(cygpath "${GITHUB_WORKSPACE}")
          .github/scripts/package-cli-tools.sh \
            --platform windows \
            --version "${VERSION}" \
            --arch x86_64 \
            --groups "${WORKSPACE}/CMake/release-tarballs.txt" \
            --source "${WORKSPACE}/wsjtx-build" \
            --dll-dir "${WORKSPACE}/stage-main/bin" \
            --system-dir "$(cygpath -S)" \
            --out "${WORKSPACE}/release-tarballs"

      - name: Smoke-launch release tarballs (clean PATH)
        run: |
          WORKSPACE=$(cygpath "${GITHUB_WORKSPACE}")
          .github/scripts/smoke-release-tarballs.sh \
            --platform windows \
            --version "${VERSION}" \
            --target windows-x86_64 \
            --groups "${WORKSPACE}/CMake/release-tarballs.txt" \
            --dir "${WORKSPACE}/release-tarballs"

      # Emit an NSIS installer containing the full executable set
      # (wsjtx.exe, map65.exe, jt9, wsprd, fmtave, fcal, fmeasure + WSJT_BUILD_UTILS
      # ft8code/jt65code/... + rigctl wrappers + Qt runtime via bundle_fixup).
      # CMakeLists.txt:1989-1990 sets CPACK_GENERATOR=NSIS on WIN32 and
      # CPACK_MONOLITHIC_INSTALL=1 packages every install() target.
      - name: Package NSIS installer
        id: package_installer
        run: |
          cd wsjtx-build
          # Override CPACK_PACKAGE_VERSION and
          # CPACK_PACKAGE_FILE_NAME so the NSIS installer filename
          # matches the tag-derived version exactly, including any
          # pre-release suffix (-rc1, -beta1, etc.). CMakeLists.txt
          # VERSION is numeric-only (CMake won't accept suffixes), so
          # without this override cpack produces wsjtx-<numeric>-win64.exe
          # while the sign step and upload-artifact paths below expect
          # wsjtx-<inputs.version>-win64.exe. release.yml's prepare job
          # enforces numeric-base parity; this override covers the
          # suffix gap.
          # MSYS2 supplies amd64 plugins; NSIS 3.13 can select x86 by default.
          cpack_args=(
            -G NSIS
            -D CPACK_PACKAGE_VERSION="${VERSION}"
            -D CPACK_PACKAGE_FILE_NAME="wsjtx-${VERSION}-win64"
            -D 'CPACK_NSIS_EXTRA_DEFINES=Target amd64-unicode'
          )
          if [ "${CPACK_VERBOSE:-0}" = "1" ]; then
            cpack_args+=(-V)
          fi
          if cpack "${cpack_args[@]}"; then
            ls -la *.exe
          else
            cpack_status=$?
            for nsis_log in _CPack_Packages/*/NSIS/NSISOutput.log; do
              [ -f "${nsis_log}" ] || continue
              echo "::group::${nsis_log}"
              cat "${nsis_log}"
              echo "::endgroup::"
            done
            exit "${cpack_status}"
          fi

      - name: Upload NSIS failure diagnostics
        if: ${{ failure() && steps.package_installer.outcome == 'failure' }}
        uses: actions/upload-artifact@v7
        with:
          name: nsis-diagnostics-windows
          path: |
            wsjtx-build/_CPack_Packages/*/NSIS/NSISOutput.log
            wsjtx-build/_CPack_Packages/*/NSIS/project.nsi
          if-no-files-found: warn

      - name: Verify installer has no Authenticode signature
        shell: pwsh
        run: |
          $installer = Get-Item "wsjtx-build/wsjtx-${{ inputs.version }}-win64.exe"
          $signature = Get-AuthenticodeSignature $installer.FullName
          if ($signature.Status -ne 'NotSigned') {
            throw "Installer Authenticode status is $($signature.Status), expected NotSigned"
          }

      - name: Upload installer artifact
        id: upload_installer
        uses: actions/upload-artifact@v7
        with:
          name: wsjtx-${{ inputs.version }}-windows-x86_64-installer
          path: wsjtx-build/wsjtx-${{ inputs.version }}-*.exe

      - name: Upload build artifacts
        uses: actions/upload-artifact@v7
        with:
          name: wsjtx-${{ inputs.version }}-windows-x86_64
          path: |
            wsjtx-build/jt9.exe
            wsjtx-build/wsprd.exe
            wsjtx-build/wsjtx.exe

      - name: Upload release tarballs
        uses: ./.github/actions/upload-release-tarballs
        with:
          version: ${{ inputs.version }}
          target: windows-x86_64
          directory: release-tarballs

      - name: Summarize native caches
        if: always()
        shell: bash
        env:
          CACHE_STEPS: ${{ toJSON(steps) }}
          COLD_BUILD: ${{ inputs.cold_build }}
          RECACHE: ${{ inputs.recache }}
        run: python .github/scripts/summarize-native-caches.py --compiler >> "$GITHUB_STEP_SUMMARY"