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 PATH=/usr/lib/llvm-3.8/bin:$PATH 35 CMAKE_C_CXX_COMPILER="-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++" 36fi 37 38# Possible configurations are: 39# ASAN, COVERAGE, RELEASE, DEBUG, DEBUG_EXCEPTION, RELEASE_MINGW 40 41if [ $CONFIG = "RELEASE" ] || [ $CONFIG = "RELEASE_MINGW" ] 42then 43 BUILD_TYPE="RelWithDebInfo" 44fi 45 46ADDITIONAL_CMAKE_FLAGS="" 47if [ $CONFIG = "ASAN" ] 48then 49 ADDITIONAL_CMAKE_FLAGS="SPIRV_USE_SANITIZER=address" 50 [ $COMPILER = "clang" ] || { echo "$CONFIG requires clang"; exit 1; } 51elif [ $CONFIG = "COVERAGE" ] 52then 53 ADDITIONAL_CMAKE_FLAGS="-DENABLE_CODE_COVERAGE=ON" 54 SKIP_TESTS="True" 55elif [ $CONFIG = "DEBUG_EXCEPTION" ] 56then 57 ADDITIONAL_CMAKE_FLAGS="-DDISABLE_EXCEPTIONS=ON -DDISABLE_RTTI=ON" 58elif [ $CONFIG = "RELEASE_MINGW" ] 59then 60 ADDITIONAL_CMAKE_FLAGS="-Dgtest_disable_pthreads=ON -DCMAKE_TOOLCHAIN_FILE=$SRC/cmake/linux-mingw-toolchain.cmake" 61 SKIP_TESTS="True" 62fi 63 64# Get NINJA. 65wget -q https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-linux.zip 66unzip -q ninja-linux.zip 67export PATH="$PWD:$PATH" 68 69cd $SRC 70git clone --depth=1 https://github.com/KhronosGroup/SPIRV-Headers external/spirv-headers 71git clone --depth=1 https://github.com/google/googletest external/googletest 72git clone --depth=1 https://github.com/google/effcee external/effcee 73git clone --depth=1 https://github.com/google/re2 external/re2 74git clone --depth=1 https://github.com/protocolbuffers/protobuf external/protobuf 75pushd external/protobuf 76git fetch --all --tags --prune 77git checkout v3.7.1 78popd 79 80mkdir build && cd $SRC/build 81 82# Invoke the build. 83BUILD_SHA=${KOKORO_GITHUB_COMMIT:-$KOKORO_GITHUB_PULL_REQUEST_COMMIT} 84echo $(date): Starting build... 85cmake -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/python3 -GNinja -DCMAKE_INSTALL_PREFIX=$KOKORO_ARTIFACTS_DIR/install -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DRE2_BUILD_TESTING=OFF -DSPIRV_BUILD_FUZZER=ON $ADDITIONAL_CMAKE_FLAGS $CMAKE_C_CXX_COMPILER .. 86 87echo $(date): Build everything... 88ninja 89echo $(date): Build completed. 90 91if [ $CONFIG = "COVERAGE" ] 92then 93 echo $(date): Check coverage... 94 ninja report-coverage 95 echo $(date): Check coverage completed. 96fi 97 98echo $(date): Starting ctest... 99if [ $SKIP_TESTS = "False" ] 100then 101 ctest -j4 --output-on-failure --timeout 300 102fi 103echo $(date): ctest completed. 104 105# Package the build. 106ninja install 107cd $KOKORO_ARTIFACTS_DIR 108tar czf install.tgz install 109