summaryrefslogtreecommitdiffstats
path: root/.github/workflows/ci.yml
blob: 0307b454bf4a392590ddc6f8fa0686530ae8e686 (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
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
name: GitHub CI

on:
  push:
    branches: ['**']
  pull_request:

# Cancels all previous workflow runs for pull requests that have not completed.
concurrency:
  # The concurrency group contains the workflow name and the branch name for
  # pull requests or the commit hash for any other events.
  group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
  cancel-in-progress: true

permissions:
  contents: read # to fetch code (actions/checkout)

jobs:
  linux:
    runs-on: ubuntu-22.04

    env:
      CC: ${{ matrix.compiler }}
      GCC_VER: 13
      CLANG_VER: 18
      TEST: test
      SRCDIR: ./src
      LEAK_CFLAGS: -DEXITFREE
      LOG_DIR: ${{ github.workspace }}/logs
      TERM: xterm
      DISPLAY: ':99'
      DEBIAN_FRONTEND: noninteractive

    strategy:
      fail-fast: false
      matrix:
        features: [tiny, normal, huge]
        compiler: [clang, gcc]
        extra: [[]]
        # Only use non-native architecture when features != huge.
        # features=huge tries to install python3-dev, which fails to install
        # for the non-native architecture.
        architecture: [native]
        include:
          - features: tiny
            compiler: clang
            extra: [nogui]
          - features: tiny
            compiler: gcc
            extra: [nogui]
          - features: normal
            shadow: ./src/shadow
            compiler: gcc
            architecture: i386
          - features: huge
            coverage: true
          - features: huge
            compiler: clang
            interface: dynamic
            python3: stable-abi
          - features: huge
            compiler: gcc
            coverage: true
            interface: dynamic
            extra: [uchar, testgui]
          - features: huge
            compiler: clang
            # Lua5.1 is the most widely used version (since it's what LuaJIT is
            # compatible with), so ensure it works
            lua_ver: '5.1'
            extra: [asan]
          - features: huge
            compiler: gcc
            coverage: true
            extra: [unittests]
          - features: normal
            compiler: gcc
            extra: [vimtags]

    steps:
      - name: Checkout repository from github
        uses: actions/checkout@v4

      - name: Check Filelist (for packaging)
        run: |
          # If any files in the repository are not listed in Filelist this will
          # exit with an error code and list the missing entries.
          make -f ci/unlisted.make

      - run: sudo dpkg --add-architecture i386
        if: matrix.architecture == 'i386'

      - name: Uninstall snap
        run: |
          sudo bash ci/remove_snap.sh

      - name: Install packages
        run: |
          # This is added by default, and it is often broken, but we don't need anything from it
          sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list
          PKGS=( \
            gettext \
            libgtk2.0-dev:${{ matrix.architecture }} \
            desktop-file-utils \
            libtool-bin \
            libncurses-dev:${{ matrix.architecture }} \
            libxt-dev:${{ matrix.architecture }} \
          )
          if ${{ matrix.features == 'huge' }}; then
            LUA_VER=${{ matrix.lua_ver || '5.4' }}
            PKGS+=( \
              autoconf \
              gdb \
              lcov \
              libcanberra-dev \
              libperl-dev \
              python2-dev \
              python3-dev \
              liblua${LUA_VER}-dev \
              lua${LUA_VER} \
              ruby-dev \
              tcl-dev \
              cscope \
              libsodium-dev \
              attr \
              libattr1-dev
            )
          fi
          sudo apt-get update && sudo apt-get upgrade && sudo apt-get install -y "${PKGS[@]}"

      - name: Install gcc-${{ env.GCC_VER }}
        if:  matrix.compiler == 'gcc'
        run: |
          # ubuntu-toolchain-r/test PPA for gcc-13 compiler
          sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
          sudo apt-get update -y
          sudo apt-get install -y gcc-${{ env.GCC_VER }}:${{ matrix.architecture }}
          sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${{ env.GCC_VER }} 100
          sudo update-alternatives --set gcc /usr/bin/gcc-${{ env.GCC_VER }}

      - name: Install clang-${{ env.CLANG_VER }}
        if: matrix.compiler == 'clang'
        run: |
          wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
          . /etc/lsb-release
          sudo add-apt-repository -y "deb http://apt.llvm.org/${DISTRIB_CODENAME}/ llvm-toolchain-${DISTRIB_CODENAME}-${{ env.CLANG_VER }} main"
          sudo apt-get install -y clang-${{ env.CLANG_VER }} llvm-${{ env.CLANG_VER }}
          sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${{ env.CLANG_VER }} 100
          sudo update-alternatives --set clang /usr/bin/clang-${{ env.CLANG_VER }}
          sudo update-alternatives --install /usr/bin/llvm-cov llvm-cov /usr/bin/llvm-cov-${{ env.CLANG_VER }} 100
          sudo update-alternatives --install /usr/bin/asan_symbolize asan_symbolize /usr/bin/asan_symbolize-${{ env.CLANG_VER }} 100

      - name: Set up environment
        run: |
          mkdir -p "${LOG_DIR}"
          mkdir -p "${HOME}/bin"
          echo "${HOME}/bin" >> $GITHUB_PATH
          (
          echo "LINUX_VERSION=$(uname -r)"
          echo "NPROC=$(getconf _NPROCESSORS_ONLN)"
          echo "TMPDIR=${{ runner.temp }}"

          case "${{ matrix.features }}" in
          tiny)
            echo "TEST=testtiny"
            if ${{ contains(matrix.extra, 'nogui') }}; then
              echo "CONFOPT=--disable-gui"
            fi
            ;;
          normal)
            ;;
          huge)
            echo "TEST=scripttests test_libvterm"
            INTERFACE=${{ matrix.interface || 'yes' }}
            if ${{ matrix.python3 == 'stable-abi' }}; then
              PYTHON3_CONFOPT="--with-python3-stable-abi=3.8"
            fi
            echo "CONFOPT=--enable-perlinterp=${INTERFACE} --enable-pythoninterp=${INTERFACE} --enable-python3interp=${INTERFACE} --enable-rubyinterp=${INTERFACE} --enable-luainterp=${INTERFACE} --enable-tclinterp=${INTERFACE} ${PYTHON3_CONFOPT}"
            ;;
          esac

          if ${{ matrix.coverage == true }}; then
            CFLAGS="${CFLAGS} --coverage -DUSE_GCOV_FLUSH"
            echo "LDFLAGS=--coverage"
          fi
          if ${{ contains(matrix.extra, 'uchar') }}; then
            CFLAGS="${CFLAGS} -funsigned-char"
          fi
          if ${{ contains(matrix.extra, 'testgui') }}; then
            echo "TEST=-C src testgui"
          fi
          if ${{ contains(matrix.extra, 'unittests') }}; then
            echo "TEST=unittests"
          fi
          if ${{ contains(matrix.extra, 'asan') }}; then
            echo "SANITIZER_CFLAGS=-g -O1 -DABORT_ON_INTERNAL_ERROR -DEXITFREE -fsanitize-recover=all -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer"
            echo "ASAN_OPTIONS=print_stacktrace=1 log_path=${LOG_DIR}/asan"
            echo "UBSAN_OPTIONS=print_stacktrace=1 log_path=${LOG_DIR}/ubsan"
            echo "LSAN_OPTIONS=suppressions=${GITHUB_WORKSPACE}/src/testdir/lsan-suppress.txt"
          fi
          if ${{ contains(matrix.extra, 'vimtags') }}; then
            echo "TEST=-C runtime/doc vimtags VIMEXE=../../${SRCDIR}/vim"
          fi
          echo "CFLAGS=${CFLAGS}"
          ) >> $GITHUB_ENV

      - name: Set up system
        run: |
          if [[ ${CC} = clang ]]; then
            # Use llvm-cov instead of gcov when compiler is clang.
            ln -fs /usr/bin/llvm-cov ${HOME}/bin/gcov
          fi
          sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=0
          sudo usermod -a -G audio "${USER}"
          sudo bash ci/setup-xvfb.sh

      - name: Set up snd-dummy
        if: (!(contains(matrix.extra, 'unittests') || contains(matrix.extra, 'vimtags')))
        env:
          DEST_DIR: ${{ env.TMPDIR }}/linux-modules-extra-${{ env.LINUX_VERSION }}
        uses: tecolicom/actions-use-apt-tools@main
        with:
          tools: linux-modules-extra-${{ env.LINUX_VERSION }}
          path: "${DEST_DIR}"

      - name: modprobe snd-dummy
        if: (!(contains(matrix.extra, 'unittests') || contains(matrix.extra, 'vimtags')))
        run: |
          sudo depmod --verbose
          sudo modprobe --verbose snd-dummy || true

      - name: Check autoconf
        if: contains(matrix.extra, 'unittests')
        run: |
          make -C src autoconf

      - name: Set up shadow dir
        if: matrix.shadow
        run: |
          make -C src shadow
          echo "SRCDIR=${{ matrix.shadow }}" >> $GITHUB_ENV
          echo "SHADOWOPT=-C ${{ matrix.shadow }}" >> $GITHUB_ENV

      - name: Configure
        run: |
          ./configure --with-features=${{ matrix.features }} ${CONFOPT} --enable-fail-if-missing
          # Append various warning flags to CFLAGS.
          sed -i -f ci/config.mk.sed ${SRCDIR}/auto/config.mk
          sed -i -f ci/config.mk.${CC}.sed ${SRCDIR}/auto/config.mk
          if [[ ${CC} = clang ]]; then
            # Suppress some warnings produced by clang 12 and later.
            sed -i -f ci/config.mk.clang-12.sed ${SRCDIR}/auto/config.mk
          fi

      - name: Build
        if: (!contains(matrix.extra, 'unittests'))
        run: |
          make ${SHADOWOPT} -j${NPROC}

      - name: Check version
        if: (!contains(matrix.extra, 'unittests'))
        run: |
          "${SRCDIR}"/vim --version
          "${SRCDIR}"/vim -u NONE -i NONE --not-a-term -esNX -V1 -S ci/if_ver-1.vim -c quit
          "${SRCDIR}"/vim -u NONE -i NONE --not-a-term -esNX -V1 -S ci/if_ver-2.vim -c quit

      - name: Test
        timeout-minutes: 25
        run: |
          do_test() { sg audio "sg $(id -gn) '$*'"; }
          do_test make ${SHADOWOPT} ${TEST}

      - name: Vim tags
        if: contains(matrix.extra, 'vimtags')
        run: |
          # This will exit with an error code if the generated vim tags differs from source.
          (
            cd runtime/doc
            git diff --exit-code -- tags
            make html; rm *.html tags.ref;
            test -f errors.log && exit 3;
            true
          )

      - name: Generate gcov files
        if: matrix.coverage
        run: |
          cd "${SRCDIR}"
          find . -type f -name '*.gcno' -exec gcov -pb {} + || true

      - name: Codecov
        timeout-minutes: 20
        if: matrix.coverage
        uses: codecov/codecov-action@v4
        with:
          flags: linux,${{ matrix.features }}-${{ matrix.compiler }}-${{ matrix.extra }}
          token: ${{ secrets.CODECOV_TOKEN }}

      - name: ASan logs
        if: contains(matrix.extra, 'asan') && !cancelled()
        run: |
          for f in $(grep -lR '#[[:digit:]]* *0x[[:xdigit:]]*' "${LOG_DIR}"); do
            asan_symbolize -l "$f"
            false # in order to fail a job
          done

  macos:
    runs-on: ${{ matrix.runner }}

    env:
      CC: clang
      TEST: test
      SRCDIR: ./src
      LEAK_CFLAGS: -DEXITFREE
      TERM: xterm

    strategy:
      fail-fast: false
      matrix:
        features: [tiny, normal, huge]
        runner: [macos-12, macos-14]

    steps:
      - name: Checkout repository from github
        uses: actions/checkout@v4

      - name: Install packages
        if: matrix.features == 'huge'
        run: |
          brew install lua libtool
          echo "LUA_PREFIX=$(brew --prefix)" >> $GITHUB_ENV

      - name: Grant microphone access for macos-14
        if: matrix.runner == 'macos-14'
        run: |
          # Temporary fix to fix microphone permission issues for macos-14 when playing sound.
          sqlite3 $HOME/Library/Application\ Support/com.apple.TCC/TCC.db "INSERT OR IGNORE INTO access VALUES ('kTCCServiceMicrophone','/usr/local/opt/runner/provisioner/provisioner',1,2,4,1,NULL,NULL,0,'UNUSED',NULL,0,1687786159,NULL,NULL,'UNUSED',1687786159);"

      - name: Set up environment
        run: |
          (
          echo "NPROC=$(getconf _NPROCESSORS_ONLN)"
          case "${{ matrix.features }}" in
          tiny)
            echo "TEST=testtiny"
            echo "CONFOPT=--disable-gui"
            ;;
          normal)
            ;;
          huge)
            echo "CONFOPT=--enable-perlinterp --enable-python3interp --enable-rubyinterp --enable-luainterp --enable-tclinterp"
            ;;
          esac
          ) >> $GITHUB_ENV

      - name: Configure
        run: |
          ./configure --with-features=${{ matrix.features }} ${CONFOPT} --enable-fail-if-missing
          # Append various warning flags to CFLAGS.
          # BSD sed needs backup extension specified.
          sed -i.bak -f ci/config.mk.sed ${SRCDIR}/auto/config.mk
          # On macOS, the entity of gcc is clang.
          sed -i.bak -f ci/config.mk.clang.sed ${SRCDIR}/auto/config.mk
          # Suppress some warnings produced by clang 12 and later.
          if clang --version | grep -qs 'Apple clang version \(1[3-9]\|[2-9]\)\.'; then
            sed -i.bak -f ci/config.mk.clang-12.sed ${SRCDIR}/auto/config.mk
          fi

      - name: Build
        env:
          LC_ALL: C
        run: |
          make -j${NPROC}

      - name: Check version
        run: |
          "${SRCDIR}"/vim --version
          "${SRCDIR}"/vim -u NONE -i NONE --not-a-term -esNX -V1 -S ci/if_ver-1.vim -c quit
          "${SRCDIR}"/vim -u NONE -i NONE --not-a-term -esNX -V1 -S ci/if_ver-2.vim -c quit

      - name: Install packages for testing
        run: |
          # Apple diff is broken. Use GNU diff instead. See #14032.
          brew install diffutils

      - name: Test
        timeout-minutes: 20
        run: |
          make ${TEST}

  windows:
    runs-on: windows-2022

    env:
      # Interfaces
      # Lua
      LUA_VER: 54
      LUA_VER_DOT: '5.4'
      LUA_RELEASE: 5.4.2
      LUA32_URL: https://downloads.sourceforge.net/luabinaries/lua-%LUA_RELEASE%_Win32_dllw6_lib.zip
      LUA64_URL: https://downloads.sourceforge.net/luabinaries/lua-%LUA_RELEASE%_Win64_dllw6_lib.zip
      LUA_DIR: D:\Lua
      # do not want \L to end up in pathdef.c and compiler complaining about unknown escape sequences \l
      LUA_DIR_SLASH: D:/Lua
      # Python 2
      PYTHON_VER: 27
      PYTHON_VER_DOT: '2.7'
      PYTHON_DIR: 'C:\Python27'
      # Python 3
      PYTHON3_VER: 311
      PYTHON3_VER_DOT: '3.11'
      # Other dependencies
      # winpty
      WINPTY_URL: https://github.com/rprichard/winpty/releases/download/0.4.3/winpty-0.4.3-msvc2015.zip
      # libsodium
      SODIUM_VER: '1.0.19'
      # SODIUM_MSVC_URL: https://download.libsodium.org/libsodium/releases/libsodium-%SODIUM_VER%-stable-msvc.zip
      SODIUM_MSVC_URL: https://github.com/jedisct1/libsodium/releases/download/%SODIUM_VER%-RELEASE/libsodium-%SODIUM_VER%-msvc.zip
      SODIUM_MSVC_VER: v143
      # SODIUM_MINGW_URL: https://download.libsodium.org/libsodium/releases/libsodium-%SODIUM_VER%-stable-mingw.tar.gz
      SODIUM_MINGW_URL: https://github.com/jedisct1/libsodium/releases/download/%SODIUM_VER%-RELEASE/libsodium-%SODIUM_VER%-mingw.tar.gz
      SODIUM_MINGW_VER: 26
      # Escape sequences
      COL_RED: "\x1b[31m"
      COL_GREEN: "\x1b[32m"
      COL_YELLOW: "\x1b[33m"
      COL_RESET: "\x1b[m"

    strategy:
      fail-fast: false
      matrix:
        include:
          - { features: HUGE,   toolchain: msvc,  VIMDLL: no,  GUI: no,  arch: x64, python3: stable }
          - { features: HUGE,   toolchain: mingw, VIMDLL: yes, GUI: yes, arch: x86, python3: stable, coverage: yes }
          - { features: HUGE,   toolchain: msvc,  VIMDLL: no,  GUI: yes, arch: x86 }
          - { features: HUGE,   toolchain: mingw, VIMDLL: yes, GUI: no,  arch: x64, coverage: yes }
          - { features: NORMAL, toolchain: msvc,  VIMDLL: yes, GUI: no,  arch: x86 }
          - { features: NORMAL, toolchain: mingw, VIMDLL: no,  GUI: yes, arch: x64 }
          - { features: TINY,   toolchain: msvc,  VIMDLL: yes, GUI: yes, arch: x64 }
          - { features: TINY,   toolchain: mingw, VIMDLL: no,  GUI: no,  arch: x86 }

    steps:
      - name: Initialize
        id: init
        shell: bash
        run: |
          # Show Windows version
          cmd /c ver

          git config --global core.autocrlf input

          if ${{ matrix.arch == 'x64' }}; then
            cygreg=registry
            pyreg=
            echo "VCARCH=amd64" >> $GITHUB_ENV
            echo "WARCH=x64" >> $GITHUB_ENV
            echo "BITS=64" >> $GITHUB_ENV
            echo "MSYSTEM=MINGW64" >> $GITHUB_ENV
          else
            cygreg=registry32
            pyreg=-32
            echo "VCARCH=x86" >> $GITHUB_ENV
            echo "WARCH=ia32" >> $GITHUB_ENV
            echo "BITS=32" >> $GITHUB_ENV
            echo "MSYSTEM=MINGW32" >> $GITHUB_ENV
          fi

          echo "VCVARSALL=$(vswhere -products \* -latest -property installationPath)\\VC\\Auxiliary\\Build\\vcvarsall.bat" >> $GITHUB_ENV
          if ${{ matrix.features != 'TINY' }}; then
            if ${{ matrix.arch == 'x86' }}; then
              choco install python2 --no-progress --forcex86
            else
              choco install python2 --no-progress
            fi
          fi
          python3_dir=$(cat "/proc/$cygreg/HKEY_LOCAL_MACHINE/SOFTWARE/Python/PythonCore/${PYTHON3_VER_DOT}$pyreg/InstallPath/@")
          echo "PYTHON3_DIR=$python3_dir" >> $GITHUB_ENV

          if ${{ matrix.toolchain == 'msvc' }}; then
            SODIUM_DIR=D:\\libsodium
            echo "SODIUM_LIB=${SODIUM_DIR}\\${{ matrix.arch == 'x64' && 'x64' || 'Win32' }}\\Release\\${SODIUM_MSVC_VER}\\dynamic" >> $GITHUB_ENV
          else
            SODIUM_DIR=D:\\libsodium-win${{ matrix.arch == 'x64' && '64' || '32' }}
            # do not want \L to end up in pathdef.c and compiler complaining about unknown escape sequences \l
            SODIUM_DIR_SLASH=D:/libsodium-win${{ matrix.arch == 'x64' && '64' || '32' }}
            echo "SODIUM_LIB=${SODIUM_DIR}\\bin" >> $GITHUB_ENV
            echo "SODIUM_DIR_SLASH=${SODIUM_DIR_SLASH}" >> $GITHUB_ENV
          fi
          echo "SODIUM_DIR=${SODIUM_DIR}" >> $GITHUB_ENV

      - uses: msys2/setup-msys2@v2
        if: matrix.toolchain == 'mingw'
        with:
          update: true
          install: tar
          pacboy: >-
            make:p gcc:p
          msystem: ${{ env.MSYSTEM }}
          release: false

      - name: Checkout repository from github
        uses: actions/checkout@v4

      - name: Create a list of download URLs
        shell: cmd
        run: |
          type NUL > urls.txt
          echo %LUA_RELEASE%>> urls.txt
          echo %WINPTY_URL%>> urls.txt
          echo %SODIUM_VER%>> urls.txt

      - name: Cache downloaded files
        uses: actions/cache@v4
        with:
          path: downloads
          key: ${{ runner.os }}-${{ matrix.arch }}-${{ hashFiles('urls.txt') }}

      - name: Download dependencies
        shell: cmd
        run: |
          path C:\Program Files\7-Zip;%path%
          if not exist downloads mkdir downloads

          echo %COL_GREEN%Download Lua%COL_RESET%
          call :downloadfile %LUA${{ env.BITS }}_URL% downloads\lua.zip
          7z x downloads\lua.zip -o%LUA_DIR% > nul || exit 1

          echo %COL_GREEN%Download winpty%COL_RESET%
          call :downloadfile %WINPTY_URL% downloads\winpty.zip
          7z x -y downloads\winpty.zip -oD:\winpty > nul || exit 1
          copy /Y D:\winpty\%WARCH%\bin\winpty.dll        src\winpty%BITS%.dll
          copy /Y D:\winpty\%WARCH%\bin\winpty-agent.exe  src\

          echo %COL_GREEN%Download libsodium%COL_RESET%
          if "${{ matrix.toolchain }}"=="msvc" (
            call :downloadfile %SODIUM_MSVC_URL% downloads\libsodium.zip
            7z x -y downloads\libsodium.zip -oD:\ > nul || exit 1
          ) else (
            call :downloadfile %SODIUM_MINGW_URL% downloads\libsodium.tar.gz
            7z x -y downloads\libsodium.tar.gz -so | 7z x -si -ttar -oD:\ > nul || exit 1
            mklink %SODIUM_LIB%\libsodium.dll %SODIUM_LIB%\libsodium-%SODIUM_MINGW_VER%.dll
          )

          goto :eof

          :downloadfile
          :: call :downloadfile <URL> <localfile>
          if not exist %2 (
            curl -f -L %1 -o %2
          )
          if ERRORLEVEL 1 (
            rem Retry once.
            curl -f -L %1 -o %2 || exit 1
          )
          goto :eof

      - name: Build (MSVC)
        if: matrix.toolchain == 'msvc'
        shell: cmd
        run: |
          call "%VCVARSALL%" %VCARCH%
          cd src
          if "${{ matrix.VIMDLL }}"=="yes" (
            set GUI=yes
          ) else (
            set GUI=${{ matrix.GUI }}
          )
          if "${{ matrix.python3 }}"=="stable" (
            set PYTHON3_STABLE=yes
          ) else (
            set PYTHON3_STABLE=no
          )
          if "${{ matrix.features }}"=="HUGE" (
            nmake -nologo -f Make_mvc.mak ^
              FEATURES=${{ matrix.features }} ^
              GUI=%GUI% IME=yes ICONV=yes VIMDLL=${{ matrix.VIMDLL }} ^
              DYNAMIC_LUA=yes LUA=%LUA_DIR% ^
              DYNAMIC_PYTHON=yes PYTHON=%PYTHON_DIR% ^
              DYNAMIC_PYTHON3=yes PYTHON3=%PYTHON3_DIR% ^
              DYNAMIC_PYTHON3_STABLE_ABI=%PYTHON3_STABLE% ^
              DYNAMIC_SODIUM=yes SODIUM=%SODIUM_DIR%
          ) else (
            nmake -nologo -f Make_mvc.mak ^
              FEATURES=${{ matrix.features }} ^
              GUI=%GUI% IME=yes ICONV=yes VIMDLL=${{ matrix.VIMDLL }}
          )

      - name: Build (MinGW)
        if: matrix.toolchain == 'mingw'
        shell: msys2 {0}
        run: |
          cd src
          if [ "${{ matrix.VIMDLL }}" = "yes" ]; then
            GUI=yes
          else
            GUI=${{ matrix.GUI }}
          fi
          if [ "${{ matrix.python3 }}" = "stable" ]; then
            PYTHON3_STABLE=yes
          else
            PYTHON3_STABLE=no
          fi
          if [ "${{ matrix.features }}" = "HUGE" ]; then
            mingw32-make -f Make_ming.mak -j2 \
              FEATURES=${{ matrix.features }} \
              GUI=$GUI IME=yes ICONV=yes VIMDLL=${{ matrix.VIMDLL }} \
              DYNAMIC_LUA=yes LUA=${LUA_DIR_SLASH} \
              DYNAMIC_PYTHON=yes PYTHON=${PYTHON_DIR} \
              DYNAMIC_PYTHON3=yes PYTHON3=${PYTHON3_DIR} \
              DYNAMIC_PYTHON3_STABLE_ABI=${PYTHON3_STABLE} \
              DYNAMIC_SODIUM=yes SODIUM=${SODIUM_DIR_SLASH} \
              STATIC_STDCPLUS=yes COVERAGE=${{ matrix.coverage }}
          else
            mingw32-make -f Make_ming.mak -j2 \
              FEATURES=${{ matrix.features }} \
              GUI=$GUI IME=yes ICONV=yes VIMDLL=${{ matrix.VIMDLL }} \
              STATIC_STDCPLUS=yes
          fi

      - name: Check version
        shell: cmd
        run: |
          PATH %LUA_DIR%;C:\msys64\%MSYSTEM%\bin;%PATH%;%PYTHON3_DIR%
          if "${{ matrix.GUI }}"=="yes" (
            start /wait src\gvim -u NONE -i NONE -c "redir > version.txt | ver | q" || exit 1
            type version.txt
            echo.
            start /wait src\gvim -u NONE -i NONE -c "redir! > version.txt | so ci\if_ver-1.vim | q"
            start /wait src\gvim -u NONE -i NONE -c "redir >> version.txt | so ci\if_ver-2.vim | q"
            type version.txt
            del version.txt
          ) else (
            src\vim --version || exit 1
            src\vim -u NONE -i NONE --not-a-term -esNX -V1 -S ci/if_ver-1.vim -c quit
            src\vim -u NONE -i NONE --not-a-term -esNX -V1 -S ci/if_ver-2.vim -c quit
          )

      #- name: Prepare Artifact
      #  shell: cmd
      #  run: |
      #    mkdir artifacts
      #    copy src\*vim.exe artifacts
      #    copy src\vim*.dll artifacts
      #
      #- name: Upload Artifact
      #  uses: actions/upload-artifact@v1
      #  with:
      #    name: vim${{ matrix.bits }}-${{ matrix.toolchain }}
      #    path: ./artifacts

      - name: Test and show the result of testing gVim
        if: matrix.GUI == 'yes' || matrix.VIMDLL == 'yes'
        shell: cmd
        timeout-minutes: 15
        run: |
          PATH %LUA_DIR%;C:\msys64\%MSYSTEM%\bin;%PATH%;%PYTHON3_DIR%;%SODIUM_LIB%
          call "%VCVARSALL%" %VCARCH%

          echo %COL_GREEN%Test gVim:%COL_RESET%
          cd src\testdir
          if "${{ matrix.GUI }}"=="yes" (
            nmake -nologo -f Make_mvc.mak VIMPROG=..\gvim || exit 1
          ) else (
            @rem Run only tiny tests.
            nmake -nologo -f Make_mvc.mak tiny VIMPROG=..\gvim  || exit 1
          )

      - name: Test and show the result of testing Vim
        if: matrix.GUI == 'no' || matrix.VIMDLL == 'yes'
        shell: cmd
        timeout-minutes: 15
        run: |
          PATH %LUA_DIR%;C:\msys64\%MSYSTEM%\bin;%PATH%;%PYTHON3_DIR%;%SODIUM_LIB%
          call "%VCVARSALL%" %VCARCH%

          echo %COL_GREEN%Test Vim:%COL_RESET%
          cd src\testdir
          nmake -nologo -f Make_mvc.mak clean
          if "${{ matrix.GUI }}"=="no" (
            nmake -nologo -f Make_mvc.mak VIMPROG=..\vim || exit 1
          ) else (
            @rem Run only tiny tests.
            nmake -nologo -f Make_mvc.mak tiny VIMPROG=..\vim  || exit 1
          )

      - name: Generate gcov files
        if: matrix.coverage
        shell: msys2 {0}
        run: |
          cd src
          find . -type f -name '*.gcno' -exec gcov -pb {} + || true

      - name: Codecov
        timeout-minutes: 20
        if: matrix.coverage
        uses: codecov/codecov-action@v4
        with:
          directory: src
          flags: windows,${{ matrix.toolchain }}-${{ matrix.arch }}-${{ matrix.features }}
          token: ${{ secrets.CODECOV_TOKEN }}