1#!/bin/bash 2# Copyright (c) 2018 Google LLC. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16# Linux Build Script. 17 18# Fail on any error. 19set -e 20# Display commands being run. 21set -x 22 23BUILD_ROOT=$PWD 24SRC=$PWD/github/SPIRV-Tools 25CONFIG=$1 26COMPILER=$2 27 28SKIP_TESTS="False" 29BUILD_TYPE="Debug" 30 31CMAKE_C_CXX_COMPILER="" 32if [ $COMPILER = "clang" ] 33then 34 sudo ln -s /usr/bin/clang-3.8 /usr/bin/clang 35 sudo ln -s /usr/bin/clang++-3.8 /usr/bin/clang++ 36 CMAKE_C_CXX_COMPILER="-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++" 37fi 38 39# Possible configurations are: 40# ASAN, COVERAGE, RELEASE, DEBUG, DEBUG_EXCEPTION, RELEASE_MINGW 41 42if [ $CONFIG = "RELEASE" ] || [ $CONFIG = "RELEASE_MINGW" ] 43then 44 BUILD_TYPE="RelWithDebInfo" 45fi 46 47ADDITIONAL_CMAKE_FLAGS="" 48if [ $CONFIG = "ASAN" ] 49then 50 ADDITIONAL_CMAKE_FLAGS="-DCMAKE_CXX_FLAGS=-fsanitize=address -DCMAKE_C_FLAGS=-fsanitize=address" 51 export ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer-3.4 52elif [ $CONFIG = "COVERAGE" ] 53then 54 ADDITIONAL_CMAKE_FLAGS="-DENABLE_CODE_COVERAGE=ON" 55 SKIP_TESTS="True" 56elif [ $CONFIG = "DEBUG_EXCEPTION" ] 57then 58 ADDITIONAL_CMAKE_FLAGS="-DDISABLE_EXCEPTIONS=ON -DDISABLE_RTTI=ON" 59elif [ $CONFIG = "RELEASE_MINGW" ] 60then 61 ADDITIONAL_CMAKE_FLAGS="-Dgtest_disable_pthreads=ON -DCMAKE_TOOLCHAIN_FILE=$SRC/cmake/linux-mingw-toolchain.cmake" 62 SKIP_TESTS="True" 63fi 64 65# Get NINJA. 66wget -q https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-linux.zip 67unzip -q ninja-linux.zip 68export PATH="$PWD:$PATH" 69 70cd $SRC 71git clone --depth=1 https://github.com/KhronosGroup/SPIRV-Headers external/spirv-headers 72git clone --depth=1 https://github.com/google/googletest external/googletest 73git clone --depth=1 https://github.com/google/effcee external/effcee 74git clone --depth=1 https://github.com/google/re2 external/re2 75 76mkdir build && cd $SRC/build 77 78# Invoke the build. 79BUILD_SHA=${KOKORO_GITHUB_COMMIT:-$KOKORO_GITHUB_PULL_REQUEST_COMMIT} 80echo $(date): Starting build... 81cmake -GNinja -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_INSTALL_PREFIX=install -DRE2_BUILD_TESTING=OFF $ADDITIONAL_CMAKE_FLAGS $CMAKE_C_CXX_COMPILER .. 82 83echo $(date): Build everything... 84ninja 85echo $(date): Build completed. 86 87if [ $CONFIG = "COVERAGE" ] 88then 89 echo $(date): Check coverage... 90 ninja report-coverage 91 echo $(date): Check coverage completed. 92fi 93 94echo $(date): Starting ctest... 95if [ $SKIP_TESTS = "False" ] 96then 97 ctest -j4 --output-on-failure --timeout 300 98fi 99echo $(date): ctest completed. 100 101