• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# For details, see README.md in this directory.
2
3###############################################################
4# C compilers
5#
6# - gcc
7# - clang
8#
9# Known Issue
10# - All test cases which described as 'fail' must be fixed and replaced with 'true'.
11#   - gcc-11 (x32, x86) : "../lib/lz4hc.c:148: LZ4HC_countBack: Assertion `(size_t)(match - mMin) < (1U<<31)' failed."
12#   - all clangs (x32, x86) : "../lib/lz4hc.c:282: int LZ4HC_InsertAndGetWiderMatch(...): Assertion `matchPtr >= lowPrefixPtr' failed."
13#
14name: lz4 CI
15on: [push, pull_request]
16permissions:
17  contents: read
18
19concurrency:
20  cancel-in-progress: true
21  group: ${{ github.workflow }}-${{ github.head_ref }}
22
23jobs:
24  lz4-c-compilers:
25    name: CC=${{ matrix.cc }}, ${{ matrix.os }}
26    strategy:
27      fail-fast: false  # 'false' means Don't stop matrix workflows even if some matrix failed.
28      matrix:
29        include: [
30          # You can access the following values via ${{ matrix.??? }}
31          #
32          #   pkgs         : apt-get package names.  It can include multiple package names which are delimited by space.
33          #   cc           : C compiler executable.
34          #   cxx          : C++ compiler executable for targets `cxxtest` and `ctocxxtest`.
35          #   x32          : Set 'true' if compiler supports x32.  Otherwise, set 'false'.
36          #                  Set 'fail' if it supports x32 but fails for now.  'fail' cases must be removed.
37          #   x86          : Set 'true' if compiler supports x86 (-m32).  Otherwise, set 'false'.
38          #                  Set 'fail' if it supports x86 but fails for now.  'fail' cases must be removed.
39          #   cxxtest      : Set 'true' if it can be compiled as C++ code.  Otherwise, set 'false'.
40          #   freestanding : Set 'true' if it can be compiled and execute freestanding code.  Otherwise, set 'false'.
41          #                  Usually, it requires Linux, x86_64 and gcc/g++.
42          #   os           : GitHub Actions YAML workflow label.  See https://github.com/actions/virtual-environments#available-environments
43
44          # cc
45          { pkgs: '',                                                   cc: cc,        cxx: c++,         x32: 'false', x86: 'true', cxxtest: 'true',  freestanding: 'true',  os: ubuntu-latest, },
46
47          # gcc
48          { pkgs: '',                                                   cc: gcc,       cxx: g++,         x32: 'false', x86: 'true', cxxtest: 'true',  freestanding: 'true',  os: ubuntu-latest, },
49        # { pkgs: 'gcc-13 g++-13 lib32gcc-13-dev libx32gcc-13-dev',     cc: gcc-13,    cxx: g++-13,      x32: 'false', x86: 'true', cxxtest: 'true',  freestanding: 'true',  os: ubuntu-22.04,  },
50          { pkgs: 'gcc-12 g++-12 lib32gcc-12-dev libx32gcc-12-dev',     cc: gcc-12,    cxx: g++-12,      x32: 'false', x86: 'true', cxxtest: 'true',  freestanding: 'true',  os: ubuntu-22.04,  },
51          { pkgs: 'gcc-11 g++-11 lib32gcc-11-dev libx32gcc-11-dev',     cc: gcc-11,    cxx: g++-11,      x32: 'false', x86: 'true', cxxtest: 'true',  freestanding: 'true',  os: ubuntu-22.04,  },
52          { pkgs: 'gcc-10 g++-10 lib32gcc-10-dev libx32gcc-10-dev',     cc: gcc-10,    cxx: g++-10,      x32: 'false', x86: 'true', cxxtest: 'true',  freestanding: 'true',  os: ubuntu-22.04,  },
53          { pkgs: 'gcc-9 g++-9 lib32gcc-9-dev libx32gcc-9-dev',         cc: gcc-9,     cxx: g++-9,       x32: 'false', x86: 'true', cxxtest: 'true',  freestanding: 'true',  os: ubuntu-22.04,  },
54          { pkgs: 'gcc-8 g++-8 lib32gcc-8-dev libx32gcc-8-dev',         cc: gcc-8,     cxx: g++-8,       x32: 'true', x86: 'true', cxxtest: 'true',  freestanding: 'true',  os: ubuntu-20.04,  },
55          { pkgs: 'gcc-7 g++-7 lib32gcc-7-dev libx32gcc-7-dev',         cc: gcc-7,     cxx: g++-7,       x32: 'true', x86: 'true', cxxtest: 'true',  freestanding: 'true',  os: ubuntu-20.04,  },
56
57          # clang
58          { pkgs: 'lib32gcc-12-dev libx32gcc-12-dev',                   cc: clang,     cxx: clang++,     x32: 'false', x86: 'true', cxxtest: 'true',  freestanding: 'false', os: ubuntu-latest, },
59          { pkgs: 'clang-15  lib32gcc-12-dev libx32gcc-12-dev',         cc: clang-15,  cxx: clang++-15,  x32: 'false', x86: 'true', cxxtest: 'true',  freestanding: 'false', os: ubuntu-22.04,  },
60          { pkgs: 'clang-14  lib32gcc-12-dev libx32gcc-12-dev',         cc: clang-14,  cxx: clang++-14,  x32: 'false', x86: 'true', cxxtest: 'true',  freestanding: 'false', os: ubuntu-22.04,  },
61          { pkgs: 'clang-13  lib32gcc-12-dev libx32gcc-12-dev',         cc: clang-13,  cxx: clang++-13,  x32: 'false', x86: 'true', cxxtest: 'true',  freestanding: 'false', os: ubuntu-22.04,  },
62          { pkgs: 'clang-12  lib32gcc-12-dev libx32gcc-12-dev',         cc: clang-12,  cxx: clang++-12,  x32: 'false', x86: 'true', cxxtest: 'true',  freestanding: 'false', os: ubuntu-22.04,  },
63          { pkgs: 'clang-11  lib32gcc-12-dev libx32gcc-12-dev',         cc: clang-11,  cxx: clang++-11,  x32: 'false', x86: 'true', cxxtest: 'true',  freestanding: 'false', os: ubuntu-22.04,  },
64          { pkgs: 'clang-10  lib32gcc-10-dev libx32gcc-10-dev',         cc: clang-10,  cxx: clang++-10,  x32: 'fail', x86: 'true', cxxtest: 'true',  freestanding: 'false', os: ubuntu-20.04,  },
65          { pkgs: 'clang-9   lib32gcc-10-dev libx32gcc-10-dev',         cc: clang-9,   cxx: clang++-9,   x32: 'fail', x86: 'true', cxxtest: 'true',  freestanding: 'false', os: ubuntu-20.04,  },
66          { pkgs: 'clang-8   lib32gcc-10-dev libx32gcc-10-dev',         cc: clang-8,   cxx: clang++-8,   x32: 'fail', x86: 'true', cxxtest: 'true',  freestanding: 'false', os: ubuntu-20.04,  },
67          { pkgs: 'clang-7   lib32gcc-7-dev  libx32gcc-7-dev',          cc: clang-7,   cxx: clang++-7,   x32: 'fail', x86: 'true', cxxtest: 'true',  freestanding: 'false', os: ubuntu-20.04,  },
68          { pkgs: 'clang-6.0 lib32gcc-10-dev libx32gcc-10-dev',         cc: clang-6.0, cxx: clang++-6.0, x32: 'fail', x86: 'true', cxxtest: 'true',  freestanding: 'false', os: ubuntu-20.04,  },
69        ]
70
71    runs-on: ${{ matrix.os }}
72    env:                        # Set environment variables
73      # We globally set CC and CXX to improve compatibility
74      CC: ${{ matrix.cc }}
75      CXX: ${{ matrix.cxx }}
76      FIXME__LZ4_CI_IGNORE : ' echo Error.  But we ignore it for now.'
77    steps:
78    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
79
80    - name: apt-get install
81      run: |
82        sudo apt-get update
83        sudo apt-get install gcc-multilib
84        sudo apt-get install ${{ matrix.pkgs }}
85
86    - name: Environment info
87      run: |
88        echo && type $CC && which $CC && $CC --version
89        echo && type $CXX && which $CXX && $CXX --version
90
91    - name: make
92      if: always()
93      run: make -j V=1
94
95    - name: install test
96      if: always()
97      run: make -C tests test-install V=1
98
99    - name: make all
100      if: always()
101      run: make clean; CFLAGS="-Werror -O0" make -j all V=1
102
103    - name: make c_standards (C90)
104      if: always()
105      run: make clean; make -j c_standards_c90 V=1
106
107    - name: make c_standards (C11)
108      if: always()
109      run: make clean; make -j c_standards_c11 V=1
110
111    - name: c lib for c++ program
112      if: ${{ matrix.cxxtest == 'true' }}
113      run: make clean; make -j ctocxxtest V=1
114
115    - name: compiled as c++ source
116      if: ${{ matrix.cxxtest == 'true' }}
117      run: make clean; make -j cxxtest V=1
118
119    - name: make test-freestanding
120      if: ${{ matrix.freestanding == 'true' }}
121      run: make clean; make test-freestanding V=1
122
123    - name: make -C programs default -D_FORTIFY_SOURCE=2
124      if: always()
125      run: make clean; CFLAGS='-fPIC' LDFLAGS='-pie -fPIE -D_FORTIFY_SOURCE=2' make -j -C programs default V=1
126
127    - name: make -C tests test-lz4
128      if: always()
129      run: make clean; CPPFLAGS=-DLZ4IO_NO_TSAN_ONLY make -j V=1 -C tests test-lz4
130
131    - name: make -C tests test CFLAGS='-mx32'
132      if: ${{ matrix.x32 == 'true' }}
133      run: make clean; CFLAGS='-mx32' make -j -C tests test V=1
134
135    - name: make -C tests test-lz4c32
136      if: ${{ matrix.x86 == 'true' }}
137      run: make clean; CFLAGS='-Werror -O1' make -j -C tests test-lz4c32 V=1
138
139
140    ###############################################################
141    #                                                             #
142    #      Remove this block when we relevant tests run properly  #
143    #                                                             #
144
145    - name: make -C tests test CFLAGS='-mx32' || echo Ignore failure for now.
146      if: ${{ matrix.x32 == 'fail' }}
147      run: make clean; CFLAGS='-mx32' make -C tests test V=1 || $FIXME__LZ4_CI_IGNORE
148
149    #                                                             #
150    ###############################################################
151
152
153
154###############################################################
155# LZ4 self tests
156#
157# - Fullbench
158# - Fuzzer
159# - LZ4 Frame
160# - LZ4 versions
161# - Custom LZ4_DISTANCE_MAX
162#
163  lz4-benchmark:
164    name: Fullbench
165    runs-on: ubuntu-latest
166    steps:
167    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
168
169    - name: apt-get install
170      run: |
171        sudo apt-get update
172        sudo apt-get install gcc-multilib
173
174    - name: test-lz4
175      run: make -j -C tests test-lz4 V=1
176
177    - name: test-lz4c
178      run: make -j -C tests test-lz4c V=1
179
180    - name: test-lz4c32
181      run: make -j -C tests test-lz4c32 V=1
182
183    - name: test-fullbench
184      run: make -j -C tests test-fullbench V=1
185
186    - name: test-fullbench32
187      run: make -j -C tests test-fullbench32 V=1
188
189
190  lz4-fuzzer:
191    name: Fuzzer test
192    runs-on: ubuntu-latest
193    steps:
194    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
195
196    - name: apt-get install
197      run: |
198        sudo apt-get update
199        sudo apt-get install gcc-multilib
200
201    - name: setup
202      run: sudo sysctl -w vm.mmap_min_addr=4096
203
204    - name: fuzzer
205      run: make -j -C tests test-fuzzer V=1
206
207    - name: fuzzer32
208      run: make -C tests test-fuzzer32 V=1
209
210
211  lz4-standard-makefile-variables:
212    name: LZ4 Makefile - support for standard variables
213    runs-on: ubuntu-latest
214    steps:
215    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
216
217    - name: make standard_variables
218      run: make standard_variables V=1
219
220
221  lz4-versions:
222    name: LZ4 versions test
223    runs-on: ubuntu-latest
224    steps:
225    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
226
227    - name: apt-get install
228      run: |
229        sudo apt-get update
230        sudo apt-get install gcc-multilib
231
232    - name: versionsTest
233      run: make -j -C tests versionsTest V=1
234
235
236  lz4-abi:
237    name: LZ4 inter-versions ABI compatibility test
238    runs-on: ubuntu-latest
239    steps:
240    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
241
242    - name: apt-get install
243      run: |
244        sudo apt-get update
245        sudo apt-get install gcc-multilib
246
247    - name: abiTests
248      run: make -j -C tests abiTests V=1
249
250
251  lz4-frame:
252    name: LZ4 frame test
253    runs-on: ubuntu-latest
254    steps:
255    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
256
257    - name: apt-get install
258      run: |
259        sudo apt-get update
260        sudo apt-get install gcc-multilib
261
262    - name: LZ4 frame test
263      run: make -j -C tests test-frametest V=1
264
265    - name: LZ4 frame test (32-bit)
266      run: make -j -C tests test-frametest32 V=1
267
268  lz4-memory-usage:
269    name: test different values of LZ4_MEMORY_USAGE
270    runs-on: ubuntu-latest
271    steps:
272    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
273    - name: LZ4_MEMORY_USAGE
274      run: make V=1 -C tests test-compile-with-lz4-memory-usage
275
276  # Custom LZ4_DISTANCE_MAX ; lz4-wlib (CLI linked to dynamic library); LZ4_USER_MEMORY_FUNCTIONS
277  lz4-custom-distance:
278    name: Custom LZ4_DISTANCE_MAX
279    runs-on: ubuntu-latest
280    steps:
281    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
282    - name: custom LZ4_DISTANCE_MAX; test LZ4_USER_MEMORY_FUNCTIONS
283      run: |
284        CPPFLAGS='-DLZ4_DISTANCE_MAX=8000' make V=1 check
285        make clean
286        make -C programs lz4-wlib V=1
287        make clean
288        make -C tests fullbench-wmalloc V=1  # test LZ4_USER_MEMORY_FUNCTIONS
289        make clean
290        CC="c++ -Wno-deprecated" make -C tests fullbench-wmalloc V=1 # stricter function signature check
291
292  # test block device compression #1086
293  lz4cli-block-device:
294    name: Test lz4 compression on a block device
295    runs-on: ubuntu-latest
296    steps:
297    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
298    - name: create a block device, compress it with lz4 # alternative : blindly use /dev/loop0, seems to always exist
299      run: |
300        make lz4
301        dd if=/dev/zero of=full0.img bs=2M count=1
302        BLOCK_DEVICE=$(sudo losetup --show -fP full0.img)
303        sudo chmod 666 $BLOCK_DEVICE
304        ./lz4 -v $BLOCK_DEVICE -c > /dev/null
305        sudo losetup -d $BLOCK_DEVICE
306        rm full0.img
307
308
309###############################################################
310# Check tools
311#
312# - cppcheck
313# - scan-build
314# - valgrind
315# - ubsan
316# - asan
317# - unicode-lint
318# - build examples
319#
320  lz4-cppcheck:
321    name: make cppcheck
322    runs-on: ubuntu-latest
323    steps:
324    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
325    - name: apt-get install
326      run: |
327        sudo apt-get update
328        sudo apt-get install cppcheck
329
330    - name: Environment info
331      run: echo && type cppcheck && which cppcheck && cppcheck --version
332
333    - name: cppcheck
334      # This test script ignores the exit code of cppcheck.
335      # See known issues in README.md.
336      run: make V=1 clean cppcheck || echo There are some cppcheck reports but we ignore it.
337
338
339  lz4-scan-build:
340    name: make staticAnalyze
341    runs-on: ubuntu-latest
342    steps:
343    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
344    - name: apt-get install
345      run: |
346        sudo apt-get update
347        sudo apt-get install clang-tools
348
349    - name: Environment info
350      run: |
351        echo && type gcc && which gcc && gcc --version
352        echo && type clang && which clang && clang --version
353        echo && type scan-build && which scan-build               # scan-build doesn't have any --version equivalent option
354        echo && type make && which make && make -v
355        echo && cat /proc/cpuinfo || echo /proc/cpuinfo is not present
356
357    - name: make staticAnalyze
358      run: make V=1 clean staticAnalyze
359
360
361  lz4-valgrind:
362    name: valgrind
363    runs-on: ubuntu-latest
364    steps:
365    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
366    - name: apt-get install
367      run: |
368        sudo apt-get update
369        sudo apt-get install valgrind
370
371    - name: Environment info
372      run: |
373        echo && type cc && which cc && cc --version
374        echo && type valgrind && which valgrind && valgrind --version
375
376    - name: valgrind
377      run: make V=1 -C tests test-mem
378
379
380  lz4-ubsan-x64:
381    name: Linux x64 ubsan
382    runs-on: ubuntu-latest
383    steps:
384    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
385
386    - name: ubsan
387      run: |
388        make clean
389        make V=1 usan
390
391
392  lz4-ubsan-x86:
393    name: Linux x86 ubsan
394    runs-on: ubuntu-latest
395    steps:
396    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
397
398    - name: apt-get install
399      run: |
400        sudo apt-get update
401        sudo apt-get install gcc-multilib
402        sudo apt-get install lib32gcc-11-dev
403
404    - name: ubsan32
405      run: |
406        make clean
407        CC=clang make V=1 usan32
408
409
410  lz4-asan-x64:
411    name: Linux x64 ASAN
412    runs-on: ubuntu-latest
413    steps:
414    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
415
416    - name: setup
417      run: sudo sysctl -w vm.mmap_min_addr=4096
418
419    - name: check lz4
420      run: make clean; CFLAGS=-fsanitize=address LDFLAGS=-fsanitize=address make -j check V=1
421
422    - name: frametest
423      run: make clean; CFLAGS=-fsanitize=address LDFLAGS=-fsanitize=address make -j -C tests test-frametest V=1
424
425    - name: fuzzer
426      run: make clean; CFLAGS=-fsanitize=address LDFLAGS=-fsanitize=address make -j -C tests test-fuzzer V=1
427
428  lz4-msan-x64:
429    name: Linux x64 MSAN
430    runs-on: ubuntu-latest
431    steps:
432    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
433
434    - name: check lz4
435      run: make clean; CC=clang CFLAGS=-fsanitize=memory LDFLAGS=-fsanitize=memory make -j check V=1
436
437    - name: frametest
438      run: make clean; CC=clang CFLAGS=-fsanitize=memory LDFLAGS=-fsanitize=memory make -j -C tests test-frametest V=1
439
440    - name: fuzzer
441      run: make clean; CC=clang CFLAGS=-fsanitize=memory LDFLAGS=-fsanitize=memory make -j -C tests test-fuzzer V=1
442
443  lz4-tsan-x64:
444    name: Linux x64 TSAN
445    runs-on: ubuntu-latest
446    steps:
447    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
448
449    - name: lz4 cli
450      run: make clean; CC=clang CPPFLAGS="-fsanitize=thread" make -j -C tests test-lz4 V=1
451
452
453  unicode-lint:
454    name: lint unicode in ./lib/, ./tests/ and ./programs/
455    runs-on: ubuntu-latest
456    steps:
457    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
458    - name: unicode lint
459      run: bash ./tests/unicode_lint.sh
460
461  lz4-examples:
462    name: make examples
463    runs-on: ubuntu-latest
464    steps:
465    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
466    - name: apt-get install
467      run: |
468        sudo apt-get update
469
470    - name: Environment info
471      run: |
472        echo && type cc && which cc && cc --version
473        echo && type c++ && which c++ && c++ --version
474
475    - name: examples
476      run: make V=1 clean examples
477
478  # lasts ~8mn
479  oss-fuzz:
480    runs-on: ubuntu-latest
481    strategy:
482      fail-fast: false
483      matrix:
484        sanitizer: [address, undefined, memory]
485    steps:
486    - name: Build Fuzzers (${{ matrix.sanitizer }})
487      id: build
488      uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
489      with:
490        oss-fuzz-project-name: 'lz4'
491        dry-run: false
492        sanitizer: ${{ matrix.sanitizer }}
493    - name: Run Fuzzers (${{ matrix.sanitizer }})
494      uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
495      with:
496        oss-fuzz-project-name: 'lz4'
497        fuzz-seconds: 300
498        dry-run: false
499        sanitizer: ${{ matrix.sanitizer }}
500    - name: Upload Crash
501      uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # https://github.com/actions/upload-artifact v4.3.4
502      if: failure() && steps.build.outcome == 'success'
503      with:
504        name: ${{ matrix.sanitizer }}-artifacts
505        path: ./out/artifacts
506
507
508
509###############################################################
510# Platforms
511#
512# - QEMU (ARM, ARM64, PPC, PPC64LE, S390X)
513# - macOS
514# - Windows
515#
516
517  # QEMU
518  # All tests use QEMU (static) and gcc cross compiler.
519  #
520  lz4-qemu-platforms:
521    name: QEMU ${{ matrix.type }}
522    strategy:
523      fail-fast: false  # 'false' means Don't stop matrix workflows even if some matrix instance failed.
524      matrix:
525        include: [
526          # You can access the following values via ${{ matrix.??? }}
527          #   type : Architecture type for `if:` statement.
528          #   pkgs : apt-get package names.  You can include multiple packages which are delimited by space.
529          #   xcc  : gcc cross C compiler executable.
530          #   xemu : QEMU static emulator executable.
531          #   os   : GitHub Actions YAML workflow label.  See https://github.com/actions/virtual-environments#available-environments
532
533          { type: ARM,      pkgs: 'qemu-system-arm   gcc-arm-linux-gnueabi',     xcc: arm-linux-gnueabi-gcc,     xemu: qemu-arm-static,     os: ubuntu-latest, makevar: "", },
534          { type: ARM64,    pkgs: 'qemu-system-arm   gcc-aarch64-linux-gnu',     xcc: aarch64-linux-gnu-gcc,     xemu: qemu-aarch64-static, os: ubuntu-latest, makevar: "", },
535          { type: PPC,      pkgs: 'qemu-system-ppc   gcc-powerpc-linux-gnu',     xcc: powerpc-linux-gnu-gcc,     xemu: qemu-ppc-static,     os: ubuntu-latest, makevar: "", },
536          { type: PPC64LE,  pkgs: 'qemu-system-ppc   gcc-powerpc64le-linux-gnu', xcc: powerpc64le-linux-gnu-gcc, xemu: qemu-ppc64le-static, os: ubuntu-latest, makevar: "", },
537          { type: S390X,    pkgs: 'qemu-system-s390x gcc-s390x-linux-gnu',       xcc: s390x-linux-gnu-gcc,       xemu: qemu-s390x-static,   os: ubuntu-latest, makevar: "", },
538          { type: MIPS,     pkgs: 'qemu-system-mips gcc-mips-linux-gnu',         xcc: mips-linux-gnu-gcc,        xemu: qemu-mips-static,    os: ubuntu-latest, makevar: "", },
539          { type: M68K,     pkgs: 'qemu-system-m68k gcc-m68k-linux-gnu',         xcc: m68k-linux-gnu-gcc,        xemu: qemu-m68k-static,    os: ubuntu-latest, makevar: "HAVE_MULTITHREAD=0", }, # bug in MT mode on m68k
540          { type: RISC-V,   pkgs: 'qemu-system-riscv64 gcc-riscv64-linux-gnu',   xcc: riscv64-linux-gnu-gcc,     xemu: qemu-riscv64-static, os: ubuntu-latest, makevar: "", },
541          { type: SPARC,    pkgs: 'qemu-system-sparc gcc-sparc64-linux-gnu',     xcc: sparc64-linux-gnu-gcc,     xemu: qemu-sparc64-static, os: ubuntu-20.04, makevar: "", },
542        ]
543
544    runs-on: ${{ matrix.os }}
545    env:                        # Set environment variables
546      XCC: ${{ matrix.xcc }}
547      XEMU: ${{ matrix.xemu }}
548      MAKEVAR: ${{ matrix.makevar }}
549    steps:
550    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
551
552    - name: apt-get install
553      run: |
554        sudo apt-get update
555        sudo apt-get install gcc-multilib
556        sudo apt-get install qemu-utils qemu-user-static
557        sudo apt-get install ${{ matrix.pkgs }}
558
559    - name: Environment info
560      run: |
561        echo && type $XCC && which $XCC && $XCC --version
562        echo && $XCC -v                       # Show built-in specs
563        echo && type $XEMU && which $XEMU && $XEMU --version
564
565    - name: ARM-ARM64-PPC-S390X
566      if: ${{ matrix.type == 'ARM' || matrix.type == 'ARM64' || matrix.type == 'PPC' || matrix.type == 'S390X'}}
567      run: make platformTest V=1  CC=$XCC QEMU_SYS=$XEMU
568
569    - name: PPC64LE
570      if: ${{ matrix.type == 'PPC64LE' }}
571      run: CFLAGS=-m64 make platformTest V=1 CC=$XCC QEMU_SYS=$XEMU
572
573    - name: MIPS-M68K-RISCV-SPARC
574      if: ${{ matrix.type == 'MIPS' || matrix.type == 'M68K' || matrix.type == 'RISC-V' || matrix.type == 'SPARC' }}
575      run: make platformTest V=1 CC=$XCC QEMU_SYS=$XEMU $MAKEVAR
576
577
578
579  # macOS
580  lz4-platform-macos-latest:
581    name: macOS
582    runs-on: macos-latest
583    steps:
584    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
585
586    - name: Environment info
587      run: |
588        echo && type cc && which cc && cc --version
589        echo && type make && which make && make -v
590        echo && sysctl -a | grep machdep.cpu   # cpuinfo
591
592    - name: make default
593      run: make clean; CFLAGS="-Werror -O0" make default V=1
594
595    - name: make test
596      run: make clean; CFLAGS="-O3 -Werror -Wconversion -Wno-sign-conversion" make -j test V=1
597
598    - name: Ensure `make test` doesn't depend on the status of the console
599      # see issue #990 for detailed explanations
600      run: make -j test > /dev/null
601
602
603###############################################################
604# Build systems (other than make)
605#
606# - cmake
607# - visual
608# - meson
609#
610
611  # cmake
612  lz4-build-cmake:
613    name: cmake
614    runs-on: ubuntu-latest
615    steps:
616    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
617
618    - name: Environment info
619      run: |
620        echo && type cmake && which cmake && cmake --version
621        echo && type make && which make && make -v
622
623    - name: cmake
624      run: |
625        CFLAGS="-Werror -O1" cmake -S build/cmake -B build -D CMAKE_INSTALL_PREFIX=install
626        VERBOSE=1 cmake --build build --target install
627        cmake -S tests/cmake -B build_test -D CMAKE_INSTALL_PREFIX=install
628        VERBOSE=1 cmake --build build_test
629
630  lz4-build-cmake-static-lib: # See https://github.com/lz4/lz4/issues/1269
631    name: cmake (static lib)
632    runs-on: ubuntu-latest
633    steps:
634    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
635
636    - name: Environment info
637      run: |
638        echo && type cmake && which cmake && cmake --version
639        echo && type make && which make && make -v
640
641    - name: cmake (static lib)
642      run: |
643        CFLAGS="-Werror -O1" cmake -S build/cmake -B build -D CMAKE_INSTALL_PREFIX=install_test_dir -DBUILD_STATIC_LIBS=ON
644        VERBOSE=1 cmake --build build --target install
645        cmake -S tests/cmake -B build_test -D CMAKE_INSTALL_PREFIX=install_test_dir
646        VERBOSE=1 cmake --build build_test
647
648  # Invoke cmake via Makefile
649  lz4-build-make-cmake:
650    name: make cmakebuild
651    runs-on: ubuntu-latest
652    steps:
653    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
654    - name: make cmakebuild
655      # V=1 for lz4 Makefile, VERBOSE=1 for cmake Makefile.
656      run: make clean; make cmakebuild V=1 VERBOSE=1
657
658  # Windows + Visual
659  lz4-platform-windows:
660    name: ${{ matrix.system.os }}
661    runs-on: ${{ matrix.system.os }}
662    strategy:
663      fail-fast: false  # 'false' means Don't stop matrix workflows even if some matrix failed.
664      matrix:
665        system: [
666          { os: windows-2022, build_path: ".\\build\\VS2022" },
667        ]
668    steps:
669    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
670
671    - name: Build ${{ matrix.system.os }}, Win32
672      run: |
673        pushd ${{ matrix.system.build_path }}
674        .\\build-and-test-win32-release.bat
675        popd
676
677    - name: Build ${{ matrix.system.os }}, x64
678      run: |
679        pushd ${{ matrix.system.build_path }}
680        .\\build-and-test-x64-release.bat
681        popd
682
683    - name: VS solution generation
684      run: |
685        pushd ".\\build\\visual"
686        .\\generate_vs2022.cmd
687        popd
688
689    - name: Upload Generated VS2022 Directory
690      uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # https://github.com/actions/upload-artifact v4.3.4
691      with:
692        name: VS2022-Build-Dir
693        path: "build/visual/Visual Studio 17 2022"
694
695    - name: Build executable with generated solution
696      run: |
697        cmake --build "build/visual/Visual Studio 17 2022" --config Debug
698
699    - name: Minimal runtime test
700      run: |
701        & ".\\build\\visual\\Visual Studio 17 2022\\Debug\\lz4.exe" -vvV
702        & ".\\build\\visual\\Visual Studio 17 2022\\Debug\\lz4.exe" -bi1
703        & ".\\build\\visual\\Visual Studio 17 2022\\Debug\\lz4.exe" ".\\build\\visual\\Visual Studio 17 2022\\Debug\\lz4.exe"
704        & ".\\build\\visual\\Visual Studio 17 2022\\Debug\\lz4.exe" -t ".\\build\\visual\\Visual Studio 17 2022\\Debug\\lz4.exe.lz4"
705
706  # Meson
707  lz4-build-meson:
708    name: Meson + Ninja
709    runs-on: ubuntu-latest
710    steps:
711    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
712    - uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # https://github.com/actions/setup-python v5.1.1
713      with:
714        python-version: '3.x'
715
716    - name: Install
717      run: |
718        sudo apt-get update
719        sudo apt-get install tree ninja-build
720        python -m pip install --upgrade pip
721        pip3 install --user meson
722
723    - name: Environment info
724      run: |
725        echo && type clang && which clang && clang --version
726        echo && type python && which python && python --version
727        echo && type meson && which meson && meson --version
728
729    - name: setup
730      # 'run: >' replaces all newlines in the following block with spaces
731      run: >
732        meson setup
733        --fatal-meson-warnings
734        --buildtype=debug
735        -Db_lundef=false
736        -Dauto_features=enabled
737        -Dprograms=true
738        -Dcontrib=true
739        -Dtests=true
740        -Dexamples=true
741        build/meson builddir
742
743    - name: test
744      run: |
745        meson test -C builddir
746
747    - name: staging
748      run: |
749        cd builddir
750        DESTDIR=./staging ninja install
751        tree ./staging
752
753
754
755############################################################
756# Check git tag for LZ4 releases
757#
758  lz4-check-tag:
759    name: git version tag checking for release
760    runs-on: ubuntu-latest
761    steps:
762    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
763    - name: make -C tests checkTag
764      if: startsWith(github.ref, 'refs/tags/v')   # If git tag name starts with 'v'
765      run: |
766        echo "tag=${GITHUB_REF#refs/*/}"
767        make -C tests checkTag
768        tests/checkTag ${GITHUB_REF#refs/*/}
769
770
771
772############################################################
773# Gather CI environment information.
774#
775  lz4-env-info:
776    name: GH-Actions Virtual Env Info (${{ matrix.os }})
777    strategy:
778      matrix:
779        include: [
780          { os: ubuntu-latest,  }, # https://github.com/actions/runner-images/?tab=readme-ov-file#available-images
781          { os: ubuntu-24.04,   }, # https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md
782          { os: ubuntu-22.04,   }, # https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md
783          { os: ubuntu-20.04,   }, # https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2004-Readme.md
784        ]
785
786    runs-on: ${{ matrix.os }}
787    steps:
788    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # https://github.com/actions/checkout v4.1.7
789
790    - name: init
791      run: |
792        sudo apt-get update
793
794    - name: cc --version
795      run: echo && type cc && which cc && cc --version
796
797    - name: gcc --version
798      run: echo && type gcc && which gcc && gcc --version
799
800    - name: clang --version
801      run: echo && type clang && which clang && clang --version
802
803    - name: make -v
804      run: echo && type make && which make && make -v
805
806    - name: g++ --version
807      run: echo && type g++ && which g++ && g++ --version
808
809    - name: git --version
810      run: echo && type git && which git && git --version
811
812    - name: gcc packages (apt-cache)
813      run: apt-cache search gcc | grep "^gcc-[0-9\.]* " | sort
814
815    - name: lib32gcc packages for i386 (apt-cache)
816      run: apt-cache search lib32gcc | grep "^lib32gcc-" | sort
817
818    - name: libx32gcc packages for x32 (apt-cache)
819      run: apt-cache search libx32gcc | grep "^libx32gcc-" | sort
820
821    - name: gcc multilib packages (apt-cache)
822      run: apt-cache search multilib | grep "gcc-" | sort
823
824    - name: clang packages (apt-cache)
825      run: apt-cache search clang | grep "^clang-[0-9\.]* " | sort
826
827    - name: QEMU packages (apt-cache)
828      run: apt-cache search qemu | grep "^qemu-system-.*QEMU full system" | sort
829