summaryrefslogtreecommitdiff
path: root/.github/workflows/build.yaml
blob: f5dcfc75c9fe546f6f0143a2eb053da9a2b8dee0 (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
name: Build
on:
  push:
  pull_request:

env:
  CTEST_OUTPUT_ON_FAILURE: ON
  VERBOSE: 1

defaults:
  run:
    shell: bash

permissions:
  contents: read

jobs:
  build_and_test:
    env:
      CMAKE_GENERATOR: Ninja

    name: ${{ matrix.config.os }}-${{ matrix.config.compiler }}-${{ matrix.config.version }}
    runs-on: ${{ matrix.config.os }}
    strategy:
      fail-fast: false
      matrix:
        config:
          - os: ubuntu-20.04
            compiler: gcc
            version: "8"

          - os: ubuntu-20.04
            compiler: gcc
            version: "9"

          - os: ubuntu-20.04
            compiler: gcc
            version: "10"

          - os: ubuntu-20.04
            compiler: clang
            version: "9"

          - os: ubuntu-20.04
            compiler: clang
            version: "10"

          - os: ubuntu-20.04
            compiler: clang
            version: "11"

          - os: ubuntu-20.04
            compiler: clang
            version: "12"

          - os: ubuntu-22.04
            compiler: clang
            version: "13"

          - os: ubuntu-22.04
            compiler: clang
            version: "14"

          - os: ubuntu-22.04
            compiler: gcc
            version: "11"

          - os: ubuntu-22.04
            compiler: gcc
            version: "12"

          - os: macOS-11
            compiler: xcode
            version: "11.7"

          - os: macOS-11
            compiler: xcode
            version: "12.5.1"

          - os: macOS-12
            compiler: xcode
            version: "13.4.1"

          - os: macOS-12
            compiler: xcode
            version: "14.2"
    steps:
      - name: Install dependencies
        run: |
          if [ "${{ runner.os }}" = "Linux" ]; then
            sudo apt-get update

            packages="elfutils libhiredis-dev libzstd-dev ninja-build pkg-config python3 redis-server redis-tools"
            # Install ld.gold (binutils) and ld.lld (lld) on different runs.
            if [ "${{ matrix.config.os }}" = "ubuntu-22.04" ]; then
              sudo apt-get install -y $packages binutils
            else
              sudo apt-get install -y $packages lld
            fi

            if [ "${{ matrix.config.compiler }}" = "gcc" ]; then
              echo "CC=gcc-${{ matrix.config.version }}" >> $GITHUB_ENV
              echo "CXX=g++-${{ matrix.config.version }}" >> $GITHUB_ENV

              sudo apt install -y g++-${{ matrix.config.version }} g++-${{ matrix.config.version }}-multilib
              if [ "${{ matrix.config.version }}" = 8 ]; then
                # The compilation test in StdFilesystem.cmake doesn't work when
                # GCC 9 is installed as well, so need to force linking with
                # libstdc++fs for GCC 8. Note: This requires using -fuse-ld=lld to
                # work.
                echo "LDFLAGS=-lstdc++fs" >> $GITHUB_ENV
              fi
            else
              echo "CC=clang-${{ matrix.config.version }}" >> $GITHUB_ENV
              echo "CXX=clang++-${{ matrix.config.version }}" >> $GITHUB_ENV

              sudo apt install -y clang-${{ matrix.config.version }} g++-multilib lld-${{ matrix.config.version }}
            fi
          elif [ "${{ runner.os }}" = "macOS" ]; then
            HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 \
              brew install ninja pkg-config hiredis redis

            if [ "${{ matrix.config.compiler }}" = "gcc" ]; then
              brew install gcc@${{ matrix.config.version }}
              echo "CC=gcc-${{ matrix.config.version }}" >> $GITHUB_ENV
              echo "CXX=g++-${{ matrix.config.version }}" >> $GITHUB_ENV
            else
              sudo xcode-select -switch /Applications/Xcode_${{ matrix.config.version }}.app
              echo "CC=clang" >> $GITHUB_ENV
              echo "CXX=clang++" >> $GITHUB_ENV
            fi
          fi

      - name: Get source
        uses: actions/checkout@v3

      - name: Build and test
        run: ci/build
        env:
          ENABLE_CACHE_CLEANUP_TESTS: true
          CMAKE_PARAMS: -DCMAKE_BUILD_TYPE=CI

      - name: Collect testdir from failed tests
        if: failure()
        run: ci/collect-testdir

      - name: Upload testdir from failed tests
        if: failure()
        uses: actions/upload-artifact@v3
        with:
          name: ${{ matrix.config.os }}-${{ matrix.config.compiler }}-${{ matrix.config.version }}-testdir.tar.xz
          path: testdir.tar.xz

  build_and_test_msys:
    runs-on: windows-latest
    strategy:
      fail-fast: false
      matrix:
        config:
          - sys: mingw64
            env: x86_64
            compiler: gcc

          - sys: mingw64
            env: x86_64
            compiler: clang

    name: 'Windows ${{ matrix.config.sys }} ${{ matrix.config.compiler }}'
    defaults:
      run:
        shell: msys2 {0}
    steps:
      - name: '${{ matrix.config.sys }} Setup MSYS2'
        uses: msys2/setup-msys2@v2
        with:
          msystem: ${{matrix.config.sys}}
          update: true
          install: >-
            git
            diffutils
            tar
            mingw-w64-${{matrix.config.env}}-toolchain
            mingw-w64-${{matrix.config.env}}-cmake
            mingw-w64-${{matrix.config.env}}-ninja
            mingw-w64-${{matrix.config.env}}-hiredis
            mingw-w64-${{matrix.config.env}}-lld
            mingw-w64-${{matrix.config.env}}-${{matrix.config.compiler}}

      - name: setup env
        run: |
          if [ "${{ matrix.config.compiler }}" = "gcc" ]; then
            echo "CC=gcc" >> $GITHUB_ENV
            echo "CXX=g++" >> $GITHUB_ENV
          else
            echo "CC=clang" >> $GITHUB_ENV
            echo "CXX=clang++" >> $GITHUB_ENV
          fi

      - name: Get source
        uses: actions/checkout@v3

      - name: Build and test
        run: ci/build
        continue-on-error: ${{ matrix.config.allow_test_failures == true &&
          steps.build-and-test.outputs.exit_status == 8 }}
        env:
          ENABLE_CACHE_CLEANUP_TESTS: 1
          CMAKE_GENERATOR: Ninja
          CMAKE_PARAMS: -DCMAKE_BUILD_TYPE=CI
          TEST_CC: gcc

      - name: Collect testdir from failed tests
        if: failure()
        run: ci/collect-testdir

      - name: Upload testdir from failed tests
        if: failure()
        uses: actions/upload-artifact@v3
        with:
          name: ${{ matrix.config.sys}}-${{ matrix.config.env }}-${{ matrix.config.compiler }}-testdir.tar.xz
          path: testdir.tar.xz

  build_macos_universal:
    name: macOS universal binary
    runs-on: macos-12
    env:
      CMAKE_GENERATOR: Ninja
    steps:
      - name: Get source
        uses: actions/checkout@v3
      - name: Install Dependencies
        run: |
          HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 \
              brew install ninja
      - name: Build macOS universal binary
        run: ci/build-macos-binary
      - name: Archive universal binary
        uses: actions/upload-artifact@v3
        with:
          name: macOS-binary
          path: build_universal/ccache

  specific_tests:
    name: ${{ matrix.config.name }}
    runs-on: ${{ matrix.config.os }}
    strategy:
      fail-fast: false
      matrix:
        config:
          - name: Linux GCC debug + in source + tracing
            os: ubuntu-20.04
            CC: gcc
            CXX: g++
            ENABLE_CACHE_CLEANUP_TESTS: 1
            BUILDDIR: .
            CCACHE_LOC: .
            CMAKE_PARAMS: -DCMAKE_BUILD_TYPE=Debug -DENABLE_TRACING=1
            apt_get: elfutils libzstd-dev pkg-config libhiredis-dev

          - name: Linux GCC 32-bit
            os: ubuntu-20.04
            CC: gcc
            CXX: g++
            CFLAGS: -m32 -g -O2
            CXXFLAGS: -m32 -g -O2
            LDFLAGS: -m32
            CMAKE_PARAMS: -DCMAKE_BUILD_TYPE=CI -DZSTD_FROM_INTERNET=ON -DHIREDIS_FROM_INTERNET=ON
            ENABLE_CACHE_CLEANUP_TESTS: 1
            apt_get: elfutils gcc-multilib g++-multilib lib32stdc++-10-dev

          - name: Linux GCC CUDA
            os: ubuntu-20.04
            CC: gcc
            CXX: g++
            CMAKE_PARAMS: -DCMAKE_BUILD_TYPE=CI -DZSTD_FROM_INTERNET=ON -DHIREDIS_FROM_INTERNET=ON
            ENABLE_CACHE_CLEANUP_TESTS: 1
            CUDA: 11.7.0-1
            apt_get: elfutils libzstd-dev

          - name: Linux MinGW 32-bit
            os: ubuntu-20.04
            CC: i686-w64-mingw32-gcc-posix
            CXX: i686-w64-mingw32-g++-posix
            CMAKE_PARAMS: -DCMAKE_BUILD_TYPE=CI -DCMAKE_SYSTEM_NAME=Windows -DZSTD_FROM_INTERNET=ON -DHIREDIS_FROM_INTERNET=ON
            RUN_TESTS: none
            apt_get: elfutils mingw-w64

          - name: Linux MinGW 64-bit
            os: ubuntu-20.04
            CC: x86_64-w64-mingw32-gcc-posix
            CXX: x86_64-w64-mingw32-g++-posix
            ENABLE_CACHE_CLEANUP_TESTS: 1
            CMAKE_PARAMS: -DCMAKE_BUILD_TYPE=CI -DCMAKE_SYSTEM_NAME=Windows -DZSTD_FROM_INTERNET=ON -DHIREDIS_FROM_INTERNET=ON
            RUN_TESTS: unittest-in-wine
            apt_get: elfutils mingw-w64 wine

          - name: Windows VS2019 32-bit Ninja
            os: windows-2019
            msvc_arch: x64_x86
            CC: cl
            CXX: cl
            ENABLE_CACHE_CLEANUP_TESTS: 1
            CMAKE_GENERATOR: Ninja
            CMAKE_PARAMS: -DCMAKE_BUILD_TYPE=CI -DZSTD_FROM_INTERNET=ON -DHIREDIS_FROM_INTERNET=ON
            TEST_CC: clang -target i686-pc-windows-msvc

          - name: Windows VS2019 32-bit MSBuild
            os: windows-2019
            msvc_arch: x64_x86
            allow_test_failures: true  # For now, don't fail the build on failure
            CC: cl
            CXX: cl
            ENABLE_CACHE_CLEANUP_TESTS: 1
            CMAKE_GENERATOR: Visual Studio 16 2019
            CMAKE_PARAMS: -DCMAKE_BUILD_TYPE=CI -DZSTD_FROM_INTERNET=ON -DHIREDIS_FROM_INTERNET=ON -A Win32
            TEST_CC: clang -target i686-pc-windows-msvc

          - name: Windows VS2019 64-bit Ninja
            os: windows-2019
            msvc_arch: x64
            CC: cl
            CXX: cl
            ENABLE_CACHE_CLEANUP_TESTS: 1
            CMAKE_GENERATOR: Ninja
            CMAKE_PARAMS: -DCMAKE_BUILD_TYPE=CI -DZSTD_FROM_INTERNET=ON -DHIREDIS_FROM_INTERNET=ON
            TEST_CC: clang -target x86_64-pc-windows-msvc

          # Issue: #1278
          # - name: Windows VS2019 64-bit MSBuild
          #   os: windows-2019
          #   msvc_arch: x64
          #   allow_test_failures: true  # For now, don't fail the build on failure
          #   CC: cl
          #   CXX: cl
          #   ENABLE_CACHE_CLEANUP_TESTS: 1
          #   CMAKE_GENERATOR: Visual Studio 16 2019
          #   CMAKE_PARAMS: -DCMAKE_BUILD_TYPE=CI -DZSTD_FROM_INTERNET=ON -DHIREDIS_FROM_INTERNET=ON -A x64
          #   TEST_CC: clang -target x86_64-pc-windows-msvc

          - name: Windows VS2022 32-bit Ninja
            os: windows-2022
            msvc_arch: x64_x86
            allow_test_failures: true  # For now, don't fail the build on failure
            CC: cl
            CXX: cl
            ENABLE_CACHE_CLEANUP_TESTS: 1
            CMAKE_GENERATOR: Ninja
            CMAKE_PARAMS: -DCMAKE_BUILD_TYPE=CI -DZSTD_FROM_INTERNET=ON -DHIREDIS_FROM_INTERNET=ON
            TEST_CC: clang -target i686-pc-windows-msvc

          - name: Windows VS2022 32-bit MSBuild
            os: windows-2022
            msvc_arch: x64_x86
            allow_test_failures: true  # For now, don't fail the build on failure
            CC: cl
            CXX: cl
            ENABLE_CACHE_CLEANUP_TESTS: 1
            CMAKE_GENERATOR: Visual Studio 17 2022
            CMAKE_PARAMS: -DCMAKE_BUILD_TYPE=CI -DZSTD_FROM_INTERNET=ON -DHIREDIS_FROM_INTERNET=ON -A Win32
            TEST_CC: clang -target i686-pc-windows-msvc

          - name: Windows VS2022 64-bit Ninja
            os: windows-2022
            msvc_arch: x64
            allow_test_failures: true  # For now, don't fail the build on failure
            CC: cl
            CXX: cl
            ENABLE_CACHE_CLEANUP_TESTS: 1
            CMAKE_GENERATOR: Ninja
            CMAKE_PARAMS: -DCMAKE_BUILD_TYPE=CI -DZSTD_FROM_INTERNET=ON -DHIREDIS_FROM_INTERNET=ON
            TEST_CC: clang -target x86_64-pc-windows-msvc

          # Issue: #1278
          # - name: Windows VS2022 64-bit MSBuild
          #   os: windows-2022
          #   msvc_arch: x64
          #   allow_test_failures: true  # For now, don't fail the build on failure
          #   CC: cl
          #   CXX: cl
          #   ENABLE_CACHE_CLEANUP_TESTS: 1
          #   CMAKE_GENERATOR: Visual Studio 17 2022
          #   CMAKE_PARAMS: -DCMAKE_BUILD_TYPE=CI -DZSTD_FROM_INTERNET=ON -DHIREDIS_FROM_INTERNET=ON -A x64
          #   TEST_CC: clang -target x86_64-pc-windows-msvc

          - name: Clang address & UB sanitizer
            os: ubuntu-20.04
            CC: clang
            CXX: clang++
            ENABLE_CACHE_CLEANUP_TESTS: 1
            CMAKE_PARAMS: -DCMAKE_BUILD_TYPE=CI -DENABLE_SANITIZER_ADDRESS=ON -DENABLE_SANITIZER_UNDEFINED_BEHAVIOR=ON
            ASAN_OPTIONS: detect_leaks=0
            apt_get: elfutils libzstd-dev pkg-config libhiredis-dev

          - name: Clang static analyzer
            os: ubuntu-20.04
            CC: clang
            CXX: clang++
            ENABLE_CACHE_CLEANUP_TESTS: 1
            CMAKE_PREFIX: scan-build
            RUN_TESTS: none
            apt_get: libzstd-dev pkg-config libhiredis-dev

          - name: Linux binary
            os: ubuntu-20.04
            CC: gcc
            CXX: g++
            SPECIAL: build-and-verify-package
            CMAKE_PARAMS: -DCMAKE_BUILD_TYPE=Release
            apt_get: elfutils libzstd-dev pkg-config libhiredis-dev ninja-build

          - name: Source package
            os: ubuntu-20.04
            CC: gcc
            CXX: g++
            SPECIAL: build-and-verify-source-package
            apt_get: elfutils libzstd-dev pkg-config libhiredis-dev ninja-build asciidoctor

          - name: HTML documentation
            os: ubuntu-20.04
            EXTRA_CMAKE_BUILD_FLAGS: --target doc-html
            RUN_TESTS: none
            apt_get: libzstd-dev pkg-config libhiredis-dev asciidoctor

          - name: Manual page
            os: ubuntu-20.04
            EXTRA_CMAKE_BUILD_FLAGS: --target doc-man-page
            RUN_TESTS: none
            apt_get: libzstd-dev pkg-config libhiredis-dev asciidoctor

          - name: Clang-Tidy
            os: ubuntu-20.04
            CC: clang-12
            CXX: clang++-12
            RUN_TESTS: none
            CMAKE_PARAMS: -DENABLE_CLANG_TIDY=ON -DCLANGTIDY=/usr/bin/clang-tidy-12
            apt_get: libzstd-dev pkg-config libhiredis-dev clang-12 clang-tidy-12

    steps:
      - name: Get source
        uses: actions/checkout@v3

      - name: Install CUDA
        if: matrix.config.CUDA != ''
        run: sudo --preserve-env=CUDA,GITHUB_PATH ci/install-cuda
        env:
          CUDA: ${{ matrix.config.CUDA }}

      - name: Run apt-get
        if: matrix.config.apt_get != ''
        run: sudo apt-get update && sudo apt-get install ${{ matrix.config.apt_get }}

      - name: Prepare Windows environment (Visual Studio)
        if: runner.os == 'Windows'
        uses: ilammy/msvc-dev-cmd@v1.12.0
        with:
          arch: ${{ matrix.config.msvc_arch }}

      - name: Prepare Windows environment (Clang)
        if: runner.os == 'Windows'
        shell: powershell
        run: |
          $ErrorActionPreference = 'Stop'

          # The test suite currently requires that the compiler specified by the
          # "CC" environment variable is on a path without spaces. Provide that
          # by creating a junction from ~/opt/llvm to the Visual Studio path.
          $null = New-Item `
            -Path "${HOME}\opt\llvm" `
            -ItemType Junction `
            -Target "${env:VCINSTALLDIR}\Tools\Llvm\x64" `
            -Force
          "Path=${HOME}\opt\llvm\bin;${env:Path}" | `
            Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append

      - name: Build and test
        id: build-and-test
        env:
          ASAN_OPTIONS: ${{ matrix.config.ASAN_OPTIONS }}
          BUILDDIR: ${{ matrix.config.BUILDDIR }}
          CC: ${{ matrix.config.CC }}
          CCACHE_LOC: ${{ matrix.config.CCACHE_LOC }}
          CFLAGS: ${{ matrix.config.CFLAGS }}
          CMAKE_GENERATOR: ${{ matrix.config.CMAKE_GENERATOR }}
          CMAKE_PARAMS: ${{ matrix.config.CMAKE_PARAMS }}
          CXX: ${{ matrix.config.CXX }}
          CXXFLAGS: ${{ matrix.config.CXXFLAGS }}
          ENABLE_CACHE_CLEANUP_TESTS: ${{ matrix.config.ENABLE_CACHE_CLEANUP_TESTS }}
          EXTRA_CMAKE_BUILD_FLAGS: ${{ matrix.config.EXTRA_CMAKE_BUILD_FLAGS }}
          LDFLAGS: ${{ matrix.config.LDFLAGS }}
          RUN_TESTS: ${{ matrix.config.RUN_TESTS }}
          SPECIAL: ${{ matrix.config.SPECIAL }}
          TEST_CC: ${{ matrix.config.TEST_CC }}
        run: |
          rc=0
          ci/build || rc=$?
          echo "exit_status=$rc" >> $GITHUB_OUTPUT
          exit $rc
        # CTest exits with return code 8 on test failure.
        continue-on-error: ${{ matrix.config.allow_test_failures == true &&
          steps.build-and-test.outputs.exit_status == 8 }}

      - name: Collect testdir from failed tests
        if: failure() || steps.build-and-test.outcome == 'failure'
        run: ci/collect-testdir
        # TODO: in case of build-and-verify-*package the BUILDDIR is set within those scripts.

      - name: Upload testdir from failed tests
        if: failure() || steps.build-and-test.outcome == 'failure'
        uses: actions/upload-artifact@v3
        with:
          name: ${{ matrix.config.name }} - testdir.tar.xz
          path: testdir.tar.xz

  check_format:
    name: Code formatting
    runs-on: ubuntu-20.04
    strategy:
      fail-fast: false
    steps:
      - name: Get source
        uses: actions/checkout@v3

      - name: Run Clang-Format in check mode
        run: misc/format-files --all --check

  codespell:
    name: Spelling
    runs-on: ubuntu-20.04
    strategy:
      fail-fast: false
    steps:
      - name: Get source
        uses: actions/checkout@v3

      - name: Install codespell
        run: |
          sudo apt-get update
          sudo apt-get install python3-pip
          pip3 install codespell==2.1.0

      - name: Run codespell
        run: codespell -q 7 -S ".git,build*,./misc/typos.toml,./src/third_party/*" -I misc/codespell-allowlist.txt