| 1 |
# Copyright 2021 Google Inc. All Rights Reserved. |
| 2 |
# |
| 3 |
# Redistribution and use in source and binary forms, with or without |
| 4 |
# modification, are permitted provided that the following conditions are |
| 5 |
# met: |
| 6 |
# |
| 7 |
# * Redistributions of source code must retain the above copyright |
| 8 |
# notice, this list of conditions and the following disclaimer. |
| 9 |
# * Redistributions in binary form must reproduce the above |
| 10 |
# copyright notice, this list of conditions and the following disclaimer |
| 11 |
# in the documentation and/or other materials provided with the |
| 12 |
# distribution. |
| 13 |
# * Neither the name of Google Inc. nor the names of its |
| 14 |
# contributors may be used to endorse or promote products derived from |
| 15 |
# this software without specific prior written permission. |
| 16 |
# |
| 17 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 |
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 |
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 20 |
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 21 |
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 22 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 23 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 |
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 |
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 |
|
| 29 |
name: ci |
| 30 |
on: [push, pull_request] |
| 31 |
|
| 32 |
permissions: |
| 33 |
contents: read |
| 34 |
|
| 35 |
jobs: |
| 36 |
build-and-test: |
| 37 |
name: >- |
| 38 |
CI |
| 39 |
${{ matrix.os }} |
| 40 |
${{ matrix.cpu_level }} |
| 41 |
${{ matrix.compiler }} |
| 42 |
${{ matrix.optimized && 'release' || 'debug' }} |
| 43 |
runs-on: ${{ matrix.os }} |
| 44 |
strategy: |
| 45 |
fail-fast: false |
| 46 |
matrix: |
| 47 |
compiler: [clang, gcc, msvc] |
| 48 |
os: [ubuntu-latest, macos-latest, windows-latest] |
| 49 |
cpu_level: [baseline, avx, avx2] |
| 50 |
optimized: [true, false] |
| 51 |
exclude: |
| 52 |
# MSVC only works on Windows. |
| 53 |
- os: ubuntu-latest |
| 54 |
compiler: msvc |
| 55 |
- os: macos-latest |
| 56 |
compiler: msvc |
| 57 |
# GitHub servers seem to run on pre-Haswell CPUs. Attempting to use AVX2 |
| 58 |
# results in crashes. |
| 59 |
- os: macos-latest |
| 60 |
cpu_level: avx2 |
| 61 |
# Not testing with GCC on macOS. |
| 62 |
- os: macos-latest |
| 63 |
compiler: gcc |
| 64 |
# Only testing with MSVC on Windows. |
| 65 |
- os: windows-latest |
| 66 |
compiler: clang |
| 67 |
- os: windows-latest |
| 68 |
compiler: gcc |
| 69 |
include: |
| 70 |
- compiler: clang |
| 71 |
CC: clang |
| 72 |
CXX: clang++ |
| 73 |
- compiler: gcc |
| 74 |
CC: gcc |
| 75 |
CXX: g++ |
| 76 |
- compiler: msvc |
| 77 |
CC: |
| 78 |
CXX: |
| 79 |
|
| 80 |
env: |
| 81 |
CMAKE_BUILD_DIR: ${{ github.workspace }}/build |
| 82 |
CMAKE_BUILD_TYPE: ${{ matrix.optimized && 'RelWithDebInfo' || 'Debug' }} |
| 83 |
CC: ${{ matrix.CC }} |
| 84 |
CXX: ${{ matrix.CXX }} |
| 85 |
SNAPPY_REQUIRE_AVX: ${{ matrix.cpu_level == 'baseline' && '0' || '1' }} |
| 86 |
SNAPPY_REQUIRE_AVX2: ${{ matrix.cpu_level == 'avx2' && '1' || '0' }} |
| 87 |
SNAPPY_FUZZING_BUILD: >- |
| 88 |
${{ (startsWith(matrix.os, 'ubuntu') && matrix.compiler == 'clang' && |
| 89 |
!matrix.optimized) && '1' || '0' }} |
| 90 |
BINARY_SUFFIX: ${{ startsWith(matrix.os, 'windows') && '.exe' || '' }} |
| 91 |
BINARY_PATH: >- |
| 92 |
${{ format( |
| 93 |
startsWith(matrix.os, 'windows') && '{0}\build\{1}\' || '{0}/build/', |
| 94 |
github.workspace, |
| 95 |
matrix.optimized && 'RelWithDebInfo' || 'Debug') }} |
| 96 |
|
| 97 |
steps: |
| 98 |
- uses: actions/checkout@v2 |
| 99 |
with: |
| 100 |
submodules: true |
| 101 |
|
| 102 |
- name: Generate build config |
| 103 |
run: >- |
| 104 |
cmake -S "${{ github.workspace }}" -B "${{ env.CMAKE_BUILD_DIR }}" |
| 105 |
-DCMAKE_BUILD_TYPE=${{ env.CMAKE_BUILD_TYPE }} |
| 106 |
-DCMAKE_INSTALL_PREFIX=${{ runner.temp }}/install_test/ |
| 107 |
-DSNAPPY_FUZZING_BUILD=${{ env.SNAPPY_FUZZING_BUILD }} |
| 108 |
-DSNAPPY_REQUIRE_AVX=${{ env.SNAPPY_REQUIRE_AVX }} |
| 109 |
-DSNAPPY_REQUIRE_AVX2=${{ env.SNAPPY_REQUIRE_AVX2 }} |
| 110 |
|
| 111 |
- name: Build |
| 112 |
run: >- |
| 113 |
cmake --build "${{ env.CMAKE_BUILD_DIR }}" |
| 114 |
--config "${{ env.CMAKE_BUILD_TYPE }}" |
| 115 |
|
| 116 |
- name: Run C++ API Tests |
| 117 |
run: ${{ env.BINARY_PATH }}snappy_unittest${{ env.BINARY_SUFFIX }} |
| 118 |
|
| 119 |
- name: Run Compression Fuzzer |
| 120 |
if: ${{ env.SNAPPY_FUZZING_BUILD == '1' }} |
| 121 |
run: >- |
| 122 |
${{ env.BINARY_PATH }}snappy_compress_fuzzer${{ env.BINARY_SUFFIX }} |
| 123 |
-runs=1000 -close_fd_mask=3 |
| 124 |
|
| 125 |
- name: Run Decompression Fuzzer |
| 126 |
if: ${{ env.SNAPPY_FUZZING_BUILD == '1' }} |
| 127 |
run: >- |
| 128 |
${{ env.BINARY_PATH }}snappy_uncompress_fuzzer${{ env.BINARY_SUFFIX }} |
| 129 |
-runs=1000 -close_fd_mask=3 |
| 130 |
|
| 131 |
- name: Run Benchmarks |
| 132 |
run: ${{ env.BINARY_PATH }}snappy_benchmark${{ env.BINARY_SUFFIX }} |
| 133 |
|
| 134 |
- name: Test CMake installation |
| 135 |
run: cmake --build "${{ env.CMAKE_BUILD_DIR }}" --target install |