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# This is required to run any git command in the docker since owner will 24# have changed between the clone environment, and the docker container. 25# Marking the root of the repo as safe for ownership changes. 26git config --global --add safe.directory $ROOT_DIR 27 28. /bin/using.sh # Declare the bash `using` function for configuring toolchains. 29 30using python-3.12 31 32if [ $COMPILER = "clang" ]; then 33 using clang-10.0.0 34elif [ $COMPILER = "gcc" ]; then 35 using gcc-9 36fi 37 38cd $ROOT_DIR 39 40function clean_dir() { 41 dir=$1 42 if [[ -d "$dir" ]]; then 43 rm -fr "$dir" 44 fi 45 mkdir "$dir" 46} 47 48if [ $TOOL != "cmake-smoketest" ]; then 49 # Get source for dependencies, as specified in the DEPS file 50 /usr/bin/python3 utils/git-sync-deps --treeless 51fi 52 53if [ $TOOL = "cmake" ]; then 54 using cmake-3.17.2 55 using ninja-1.10.0 56 57 # Possible configurations are: 58 # ASAN, UBSAN, COVERAGE, RELEASE, DEBUG, DEBUG_EXCEPTION, RELEASE_MINGW 59 BUILD_TYPE="Debug" 60 if [ $CONFIG = "RELEASE" ] || [ $CONFIG = "RELEASE_MINGW" ]; then 61 BUILD_TYPE="RelWithDebInfo" 62 fi 63 64 SKIP_TESTS="False" 65 ADDITIONAL_CMAKE_FLAGS="" 66 if [ $CONFIG = "ASAN" ]; then 67 ADDITIONAL_CMAKE_FLAGS="-DSPIRV_USE_SANITIZER=address,bounds,null" 68 [ $COMPILER = "clang" ] || { echo "$CONFIG requires clang"; exit 1; } 69 elif [ $CONFIG = "UBSAN" ]; then 70 # UBSan requires RTTI, and by default UBSan does not exit when errors are 71 # encountered - additional compiler options are required to force this. 72 # The -DSPIRV_USE_SANITIZER=undefined option instructs SPIR-V Tools to be 73 # built with UBSan enabled. 74 ADDITIONAL_CMAKE_FLAGS="-DSPIRV_USE_SANITIZER=undefined -DENABLE_RTTI=ON -DCMAKE_C_FLAGS=-fno-sanitize-recover=all -DCMAKE_CXX_FLAGS=-fno-sanitize-recover=all" 75 [ $COMPILER = "clang" ] || { echo "$CONFIG requires clang"; exit 1; } 76 elif [ $CONFIG = "COVERAGE" ]; then 77 ADDITIONAL_CMAKE_FLAGS="-DENABLE_CODE_COVERAGE=ON" 78 SKIP_TESTS="True" 79 elif [ $CONFIG = "DEBUG_EXCEPTION" ]; then 80 ADDITIONAL_CMAKE_FLAGS="-DDISABLE_EXCEPTIONS=ON -DDISABLE_RTTI=ON" 81 elif [ $CONFIG = "RELEASE_MINGW" ]; then 82 ADDITIONAL_CMAKE_FLAGS="-Dgtest_disable_pthreads=ON -DCMAKE_TOOLCHAIN_FILE=$SRC/cmake/linux-mingw-toolchain.cmake" 83 SKIP_TESTS="True" 84 fi 85 86 if [ $COMPILER = "clang" ]; then 87 ADDITIONAL_CMAKE_FLAGS="$ADDITIONAL_CMAKE_FLAGS -DSPIRV_BUILD_LIBFUZZER_TARGETS=ON" 88 fi 89 90 clean_dir "$ROOT_DIR/build" 91 cd "$ROOT_DIR/build" 92 93 # Invoke the build. 94 BUILD_SHA=${KOKORO_GITHUB_COMMIT:-$KOKORO_GITHUB_PULL_REQUEST_COMMIT} 95 echo $(date): Starting build... 96 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 .. 97 98 echo $(date): Build everything... 99 ninja 100 echo $(date): Build completed. 101 102 if [ $CONFIG = "COVERAGE" ]; then 103 echo $(date): Check coverage... 104 ninja report-coverage 105 echo $(date): Check coverage completed. 106 fi 107 108 echo $(date): Starting ctest... 109 if [ $SKIP_TESTS = "False" ]; then 110 ctest -j4 --output-on-failure --timeout 300 111 fi 112 echo $(date): ctest completed. 113 114 # Package the build. 115 ninja install 116 cd $KOKORO_ARTIFACTS_DIR 117 tar czf install.tgz install 118elif [ $TOOL = "cmake-smoketest" ]; then 119 using cmake-3.17.2 120 using ninja-1.10.0 121 122 # Get shaderc. 123 SHADERC_DIR=/tmp/shaderc 124 clean_dir "$SHADERC_DIR" 125 cd $SHADERC_DIR 126 git clone https://github.com/google/shaderc.git . 127 cd $SHADERC_DIR/third_party 128 129 # Get shaderc dependencies. Link the appropriate SPIRV-Tools. 130 git clone https://github.com/google/googletest.git 131 git clone https://github.com/KhronosGroup/glslang.git 132 ln -s $ROOT_DIR spirv-tools 133 git clone https://github.com/KhronosGroup/SPIRV-Headers.git spirv-headers 134 git clone https://github.com/google/re2 135 git clone https://github.com/google/effcee 136 git clone https://github.com/abseil/abseil-cpp abseil_cpp 137 138 cd $SHADERC_DIR 139 mkdir build 140 cd $SHADERC_DIR/build 141 142 # Invoke the build. 143 echo $(date): Starting build... 144 cmake -GNinja -DRE2_BUILD_TESTING=OFF -DCMAKE_BUILD_TYPE="Release" .. 145 146 echo $(date): Build glslang... 147 ninja glslang-standalone 148 149 echo $(date): Build everything... 150 ninja 151 echo $(date): Build completed. 152 153 echo $(date): Check Shaderc for copyright notices... 154 ninja check-copyright 155 156 echo $(date): Starting ctest... 157 ctest --output-on-failure -j4 158 echo $(date): ctest completed. 159elif [ $TOOL = "cmake-android-ndk" ]; then 160 using cmake-3.17.2 161 using ndk-r25c 162 using ninja-1.10.0 163 164 clean_dir "$ROOT_DIR/build" 165 cd "$ROOT_DIR/build" 166 167 echo $(date): Starting build... 168 cmake -DCMAKE_BUILD_TYPE=Release \ 169 -DANDROID_NATIVE_API_LEVEL=android-24 \ 170 -DANDROID_ABI="armeabi-v7a with NEON" \ 171 -DSPIRV_SKIP_TESTS=ON \ 172 -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \ 173 -GNinja \ 174 -DANDROID_NDK=$ANDROID_NDK \ 175 .. 176 177 echo $(date): Build everything... 178 ninja 179 echo $(date): Build completed. 180elif [ $TOOL = "android-ndk-build" ]; then 181 using ndk-r25c 182 183 clean_dir "$ROOT_DIR/build" 184 cd "$ROOT_DIR/build" 185 186 echo $(date): Starting ndk-build ... 187 $ANDROID_NDK_HOME/ndk-build \ 188 -C $ROOT_DIR/android_test \ 189 NDK_PROJECT_PATH=. \ 190 NDK_LIBS_OUT=./libs \ 191 NDK_APP_OUT=./app \ 192 -j4 193 194 echo $(date): ndk-build completed. 195elif [ $TOOL = "bazel" ]; then 196 using bazel-7.0.2 197 198 echo $(date): Build everything... 199 bazel build --cxxopt=-std=c++17 :all 200 echo $(date): Build completed. 201 202 echo $(date): Starting bazel test... 203 bazel test --cxxopt=-std=c++17 :all 204 echo $(date): Bazel test completed. 205fi 206