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 23. /bin/using.sh # Declare the bash `using` function for configuring toolchains. 24 25if [ $COMPILER = "clang" ]; then 26 using clang-10.0.0 27elif [ $COMPILER = "gcc" ]; then 28 using gcc-9 29fi 30 31cd $ROOT_DIR 32 33function clone_if_missing() { 34 url=$1 35 dir=$2 36 if [[ ! -d "$dir" ]]; then 37 git clone ${@:3} "$url" "$dir" 38 fi 39} 40 41function clean_dir() { 42 dir=$1 43 if [[ -d "$dir" ]]; then 44 rm -fr "$dir" 45 fi 46 mkdir "$dir" 47} 48 49clone_if_missing https://github.com/KhronosGroup/SPIRV-Headers external/spirv-headers --depth=1 50clone_if_missing https://github.com/google/googletest external/googletest 51pushd external/googletest; git reset --hard 1fb1bb23bb8418dc73a5a9a82bbed31dc610fec7; popd 52clone_if_missing https://github.com/google/effcee external/effcee --depth=1 53clone_if_missing https://github.com/google/re2 external/re2 --depth=1 54clone_if_missing https://github.com/protocolbuffers/protobuf external/protobuf --branch v3.13.0 55 56if [ $TOOL = "cmake" ]; then 57 using cmake-3.17.2 58 using ninja-1.10.0 59 60 # Possible configurations are: 61 # ASAN, COVERAGE, RELEASE, DEBUG, DEBUG_EXCEPTION, RELEASE_MINGW 62 BUILD_TYPE="Debug" 63 if [ $CONFIG = "RELEASE" ] || [ $CONFIG = "RELEASE_MINGW" ]; then 64 BUILD_TYPE="RelWithDebInfo" 65 fi 66 67 SKIP_TESTS="False" 68 ADDITIONAL_CMAKE_FLAGS="" 69 if [ $CONFIG = "ASAN" ]; then 70 ADDITIONAL_CMAKE_FLAGS="-DSPIRV_USE_SANITIZER=address,bounds,null" 71 [ $COMPILER = "clang" ] || { echo "$CONFIG requires clang"; exit 1; } 72 elif [ $CONFIG = "COVERAGE" ]; then 73 ADDITIONAL_CMAKE_FLAGS="-DENABLE_CODE_COVERAGE=ON" 74 SKIP_TESTS="True" 75 elif [ $CONFIG = "DEBUG_EXCEPTION" ]; then 76 ADDITIONAL_CMAKE_FLAGS="-DDISABLE_EXCEPTIONS=ON -DDISABLE_RTTI=ON" 77 elif [ $CONFIG = "RELEASE_MINGW" ]; then 78 ADDITIONAL_CMAKE_FLAGS="-Dgtest_disable_pthreads=ON -DCMAKE_TOOLCHAIN_FILE=$SRC/cmake/linux-mingw-toolchain.cmake" 79 SKIP_TESTS="True" 80 fi 81 82 clean_dir "$ROOT_DIR/build" 83 cd "$ROOT_DIR/build" 84 85 # Invoke the build. 86 BUILD_SHA=${KOKORO_GITHUB_COMMIT:-$KOKORO_GITHUB_PULL_REQUEST_COMMIT} 87 echo $(date): Starting build... 88 cmake -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 .. 89 90 echo $(date): Build everything... 91 ninja 92 echo $(date): Build completed. 93 94 if [ $CONFIG = "COVERAGE" ]; then 95 echo $(date): Check coverage... 96 ninja report-coverage 97 echo $(date): Check coverage completed. 98 fi 99 100 echo $(date): Starting ctest... 101 if [ $SKIP_TESTS = "False" ]; then 102 ctest -j4 --output-on-failure --timeout 300 103 fi 104 echo $(date): ctest completed. 105 106 # Package the build. 107 ninja install 108 cd $KOKORO_ARTIFACTS_DIR 109 tar czf install.tgz install 110elif [ $TOOL = "cmake-smoketest" ]; then 111 using cmake-3.17.2 112 using ninja-1.10.0 113 114 # Get shaderc. 115 SHADERC_DIR=/tmp/shaderc 116 clean_dir "$SHADERC_DIR" 117 cd $SHADERC_DIR 118 git clone https://github.com/google/shaderc.git . 119 cd $SHADERC_DIR/third_party 120 121 # Get shaderc dependencies. Link the appropriate SPIRV-Tools. 122 git clone https://github.com/google/googletest.git 123 git clone https://github.com/KhronosGroup/glslang.git 124 ln -s $ROOT_DIR spirv-tools 125 git clone https://github.com/KhronosGroup/SPIRV-Headers.git spirv-headers 126 git clone https://github.com/google/re2 127 git clone https://github.com/google/effcee 128 129 cd $SHADERC_DIR 130 mkdir build 131 cd $SHADERC_DIR/build 132 133 # Invoke the build. 134 echo $(date): Starting build... 135 cmake -GNinja -DRE2_BUILD_TESTING=OFF -DCMAKE_BUILD_TYPE="Release" .. 136 137 echo $(date): Build glslang... 138 ninja glslangValidator 139 140 echo $(date): Build everything... 141 ninja 142 echo $(date): Build completed. 143 144 echo $(date): Check Shaderc for copyright notices... 145 ninja check-copyright 146 147 echo $(date): Starting ctest... 148 ctest --output-on-failure -j4 149 echo $(date): ctest completed. 150elif [ $TOOL = "cmake-android-ndk" ]; then 151 using cmake-3.17.2 152 using ndk-r21d 153 using ninja-1.10.0 154 155 clean_dir "$ROOT_DIR/build" 156 cd "$ROOT_DIR/build" 157 158 echo $(date): Starting build... 159 cmake -DCMAKE_BUILD_TYPE=Release \ 160 -DANDROID_NATIVE_API_LEVEL=android-16 \ 161 -DANDROID_ABI="armeabi-v7a with NEON" \ 162 -DSPIRV_SKIP_TESTS=ON \ 163 -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \ 164 -GNinja \ 165 -DANDROID_NDK=$ANDROID_NDK \ 166 .. 167 168 echo $(date): Build everything... 169 ninja 170 echo $(date): Build completed. 171elif [ $TOOL = "android-ndk-build" ]; then 172 using ndk-r21d 173 174 clean_dir "$ROOT_DIR/build" 175 cd "$ROOT_DIR/build" 176 177 echo $(date): Starting ndk-build ... 178 $ANDROID_NDK_HOME/ndk-build \ 179 -C $ROOT_DIR/android_test \ 180 NDK_PROJECT_PATH=. \ 181 NDK_LIBS_OUT=./libs \ 182 NDK_APP_OUT=./app \ 183 -j4 184 185 echo $(date): ndk-build completed. 186elif [ $TOOL = "bazel" ]; then 187 using bazel-3.1.0 188 189 echo $(date): Build everything... 190 bazel build :all 191 echo $(date): Build completed. 192 193 echo $(date): Starting bazel test... 194 bazel test :all 195 echo $(date): Bazel test completed. 196fi 197