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