|
| 1 | +name: ubuntu-builds |
| 2 | + |
| 3 | +on: workflow_call |
| 4 | + |
| 5 | +env: |
| 6 | + CMAKE_VERSION: 3.21.1 |
| 7 | + NINJA_VERSION: 1.11.1 |
| 8 | + CCACHE_VERSION: 4.8 |
| 9 | + CC: '' |
| 10 | + CXX: '' |
| 11 | + GCC_VERSION: '' |
| 12 | + CLANG_VERSION: '' |
| 13 | + |
| 14 | +jobs: |
| 15 | + dev-build: |
| 16 | + runs-on: ubuntu-22.04 |
| 17 | + strategy: |
| 18 | + matrix: |
| 19 | + compiler: [gcc-10, gcc-11, gcc-12, clang-14, clang-15, clang-16] |
| 20 | + build_type: [Debug, Release] |
| 21 | + include: |
| 22 | + - build_type: Debug |
| 23 | + examples: ON |
| 24 | + tests: OFF # the template asap has no unit tests |
| 25 | + - build_type: Release |
| 26 | + examples: ON |
| 27 | + tests: OFF # the template asap has no unit tests |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Split compiler name and version |
| 31 | + id: split |
| 32 | + env: |
| 33 | + COMPILER: ${{ matrix.compiler }} |
| 34 | + COMPILER_NAME: '' |
| 35 | + COMPILER_VERSION: '' |
| 36 | + run: | |
| 37 | + COMPILER_NAME=${COMPILER%%-*} |
| 38 | + COMPILER_VERSION=${COMPILER##*-} |
| 39 | + echo "compiler_name=$COMPILER_NAME" >> $GITHUB_OUTPUT |
| 40 | + if [ $COMPILER_NAME == 'gcc' ] |
| 41 | + then |
| 42 | + echo "gcc_version=$COMPILER_VERSION" >> $GITHUB_OUTPUT |
| 43 | + elif [ $COMPILER_NAME == 'clang' ] |
| 44 | + then |
| 45 | + echo "clang_version=$COMPILER_VERSION" >> $GITHUB_OUTPUT |
| 46 | + echo "gcc_version=11" >> $GITHUB_OUTPUT |
| 47 | + fi |
| 48 | +
|
| 49 | + - name: Install basic OS packages |
| 50 | + run: | |
| 51 | + sudo apt-get -qq update |
| 52 | + sudo apt-get -qq -y install \ |
| 53 | + software-properties-common \ |
| 54 | + apt-transport-https \ |
| 55 | + lsb-release \ |
| 56 | + ca-certificates \ |
| 57 | + curl \ |
| 58 | + gnupg \ |
| 59 | + build-essential |
| 60 | +
|
| 61 | + - name: Install GCC (always runs) |
| 62 | + run: | |
| 63 | + # sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test |
| 64 | + sudo apt-get -qq update && \ |
| 65 | + sudo apt-get -qq -y install gcc-${{steps.split.outputs.gcc_version}} g++-${{steps.split.outputs.gcc_version}} |
| 66 | +
|
| 67 | + - name: Install clang (only if building with clang) |
| 68 | + if: ${{ steps.split.outputs.compiler_name == 'clang' }} |
| 69 | + run: | |
| 70 | + curl https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - |
| 71 | + sudo add-apt-repository -y 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-${{steps.split.outputs.clang_version}} main' |
| 72 | + sudo apt-get -qq update |
| 73 | + sudo apt-get -qq -y install \ |
| 74 | + libllvm${{steps.split.outputs.clang_version}} \ |
| 75 | + llvm-${{steps.split.outputs.clang_version}} \ |
| 76 | + llvm-${{steps.split.outputs.clang_version}}-dev \ |
| 77 | + llvm-${{steps.split.outputs.clang_version}}-runtime \ |
| 78 | + llvm-${{steps.split.outputs.clang_version}}-linker-tools \ |
| 79 | + lld-${{steps.split.outputs.clang_version}} \ |
| 80 | + clang-${{steps.split.outputs.clang_version}} \ |
| 81 | + clang-tools-${{steps.split.outputs.clang_version}} \ |
| 82 | + clang-format-${{steps.split.outputs.clang_version}} \ |
| 83 | + libclang1-${{steps.split.outputs.clang_version}} \ |
| 84 | + libc++-${{steps.split.outputs.clang_version}}-dev \ |
| 85 | + libc++abi-${{steps.split.outputs.clang_version}}-dev \ |
| 86 | + clang-format-${{steps.split.outputs.clang_version}} \ |
| 87 | + python3-clang-${{steps.split.outputs.clang_version}} \ |
| 88 | + clang-tools-${{steps.split.outputs.clang_version}} \ |
| 89 | + clang-tidy-${{steps.split.outputs.clang_version}} |
| 90 | +
|
| 91 | + - uses: actions/checkout@v3 |
| 92 | + with: |
| 93 | + submodules: recursive |
| 94 | + |
| 95 | + - name: Use GNU compilers (only if building with gcc/g++) |
| 96 | + if: ${{ steps.split.outputs.compiler_name == 'gcc' }} |
| 97 | + run: | |
| 98 | + echo "CC=gcc" >> $GITHUB_ENV |
| 99 | + echo "CXX=g++" >> $GITHUB_ENV |
| 100 | + sudo update-alternatives --install \ |
| 101 | + /usr/bin/gcc gcc /usr/bin/gcc-${{steps.split.outputs.gcc_version}} 110 \ |
| 102 | + --slave /usr/bin/g++ g++ /usr/bin/g++-${{steps.split.outputs.gcc_version}} \ |
| 103 | + --slave /usr/bin/gcov gcov /usr/bin/gcov-${{steps.split.outputs.gcc_version}} |
| 104 | +
|
| 105 | + - name: Use clang (only if building with clang/clang++) |
| 106 | + if: ${{ steps.split.outputs.compiler_name == 'clang' }} |
| 107 | + run: | |
| 108 | + echo "CC=clang" >> $GITHUB_ENV |
| 109 | + echo "CXX=clang++" >> $GITHUB_ENV |
| 110 | + for command in clang clang++ clang-apply-replacements clang-check \ |
| 111 | + clang-query clang-tidy clang-format scan-build scan-view llvm-cov \ |
| 112 | + llvm-profdata |
| 113 | + do |
| 114 | + sudo update-alternatives --install /usr/bin/$command $command \ |
| 115 | + /usr/bin/$command-${{steps.split.outputs.clang_version}} 110 |
| 116 | + done |
| 117 | + clang --version |
| 118 | +
|
| 119 | + - name: Setup ninja |
| 120 | + # Do not use ninja-build from the distro repos as it is always old |
| 121 | + uses: abdes/gha-setup-ninja@master |
| 122 | + with: |
| 123 | + version: ${{ env.NINJA_VERSION }} |
| 124 | + |
| 125 | + - name: Setup cmake |
| 126 | + # Do not use cmake from the distro repos as it is not the version we |
| 127 | + # want |
| 128 | + uses: jwlawson/actions-setup-cmake@v1 |
| 129 | + with: |
| 130 | + cmake-version: ${{ env.CMAKE_VERSION }} |
| 131 | + |
| 132 | + - name: Install ccache from latest |
| 133 | + run: | |
| 134 | + CCACHE_DIST="ccache-${{ env.CCACHE_VERSION }}-linux-x86_64" |
| 135 | + CCACHE_URL="https://github.com/ccache/ccache/releases/download/v$CCACHE_VERSION/$CCACHE_DIST.tar.xz" |
| 136 | + echo "Installing ccache from: $CCACHE_URL" |
| 137 | + curl -s -L -o ./ccache.tar.xz $CCACHE_URL |
| 138 | + tar xf ./ccache.tar.xz |
| 139 | + rm -f ./ccache.tar.xz |
| 140 | + echo "$GITHUB_WORKSPACE/$CCACHE_DIST" >> $GITHUB_PATH |
| 141 | +
|
| 142 | + - name: Log environment properties |
| 143 | + run: | |
| 144 | + echo "Build Type : ${{matrix.build_type}}" |
| 145 | + echo "Compiler Name : ${{steps.split.outputs.compiler_name}}" |
| 146 | + if [ ${{steps.split.outputs.compiler_name}} == 'clang' ] |
| 147 | + then |
| 148 | + echo "Clang Version : ${{steps.split.outputs.clang_version}}" |
| 149 | + fi |
| 150 | + echo "GCC Version : ${{steps.split.outputs.gcc_version}}" |
| 151 | + ninja --version |
| 152 | + cmake --version |
| 153 | + gcc --version |
| 154 | + clang --version |
| 155 | + ccache --version |
| 156 | +
|
| 157 | + - name: Setup ccache |
| 158 | + uses: Chocobo1/setup-ccache-action@v1 |
| 159 | + with: |
| 160 | + install_ccache: false |
| 161 | + update_packager_index: false |
| 162 | + prepend_symlinks_to_path: false |
| 163 | + windows_compile_environment: msvc # this field is required |
| 164 | + |
| 165 | + - name: Configure build |
| 166 | + working-directory: ${{runner.workspace}} |
| 167 | + run: | |
| 168 | + cmake -B build -S $GITHUB_WORKSPACE \ |
| 169 | + -D CMAKE_BUILD_TYPE=${{matrix.build_type}} \ |
| 170 | + -G Ninja \ |
| 171 | + -D CMAKE_MAKE_PROGRAM=ninja \ |
| 172 | + -D USE_CCACHE=ON \ |
| 173 | + -D ASAP_BUILD_TESTS=${{matrix.tests}} \ |
| 174 | + -D ASAP_BUILD_EXAMPLES=${{matrix.examples}} \ |
| 175 | + -D ASAP_BUILD_DOCS=OFF \ |
| 176 | + -D CMAKE_INSTALL_PREFIX=install \ |
| 177 | + -D CMAKE_VERBOSE_MAKEFILE=ON |
| 178 | +
|
| 179 | + - name: Build main targets |
| 180 | + working-directory: ${{runner.workspace}} |
| 181 | + run: | |
| 182 | + cmake --build build --target all |
| 183 | +
|
| 184 | + - name: Build test targets |
| 185 | + working-directory: ${{runner.workspace}} |
| 186 | + if: ${{ matrix.tests == true }} |
| 187 | + run: | |
| 188 | + cmake --build build --target build-all-tests |
| 189 | +
|
| 190 | + - name: Run tests with ctest |
| 191 | + working-directory: ${{runner.workspace}} |
| 192 | + # Hardcode 2 cores we know are there |
| 193 | + run: | |
| 194 | + ctest \ |
| 195 | + --test-dir build \ |
| 196 | + -C ${{matrix.build_type}} \ |
| 197 | + -j 2 \ |
| 198 | + --output-on-failure |
0 commit comments