• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.1
55
56if [ $TOOL = "cmake" ]; then
57  using cmake-3.17.2
58  using ninja-1.10.0
59
60  # Possible configurations are:
61  # ASAN, UBSAN, 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 = "UBSAN" ]; then
73    # UBSan requires RTTI, and by default UBSan does not exit when errors are
74    # encountered - additional compiler options are required to force this.
75    # The -DSPIRV_USE_SANITIZER=undefined option instructs SPIR-V Tools to be
76    # built with UBSan enabled.
77    ADDITIONAL_CMAKE_FLAGS="-DSPIRV_USE_SANITIZER=undefined -DENABLE_RTTI=ON -DCMAKE_C_FLAGS=-fno-sanitize-recover=all -DCMAKE_CXX_FLAGS=-fno-sanitize-recover=all"
78    [ $COMPILER = "clang" ] || { echo "$CONFIG requires clang"; exit 1; }
79  elif [ $CONFIG = "COVERAGE" ]; then
80    ADDITIONAL_CMAKE_FLAGS="-DENABLE_CODE_COVERAGE=ON"
81    SKIP_TESTS="True"
82  elif [ $CONFIG = "DEBUG_EXCEPTION" ]; then
83    ADDITIONAL_CMAKE_FLAGS="-DDISABLE_EXCEPTIONS=ON -DDISABLE_RTTI=ON"
84  elif [ $CONFIG = "RELEASE_MINGW" ]; then
85    ADDITIONAL_CMAKE_FLAGS="-Dgtest_disable_pthreads=ON -DCMAKE_TOOLCHAIN_FILE=$SRC/cmake/linux-mingw-toolchain.cmake"
86    SKIP_TESTS="True"
87  fi
88
89  if [ $COMPILER = "clang" ]; then
90    ADDITIONAL_CMAKE_FLAGS="$ADDITIONAL_CMAKE_FLAGS -DSPIRV_BUILD_LIBFUZZER_TARGETS=ON"
91  fi
92
93  clean_dir "$ROOT_DIR/build"
94  cd "$ROOT_DIR/build"
95
96  # Invoke the build.
97  BUILD_SHA=${KOKORO_GITHUB_COMMIT:-$KOKORO_GITHUB_PULL_REQUEST_COMMIT}
98  echo $(date): Starting build...
99  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 ..
100
101  echo $(date): Build everything...
102  ninja
103  echo $(date): Build completed.
104
105  if [ $CONFIG = "COVERAGE" ]; then
106    echo $(date): Check coverage...
107    ninja report-coverage
108    echo $(date): Check coverage completed.
109  fi
110
111  echo $(date): Starting ctest...
112  if [ $SKIP_TESTS = "False" ]; then
113    ctest -j4 --output-on-failure --timeout 300
114  fi
115  echo $(date): ctest completed.
116
117  # Package the build.
118  ninja install
119  cd $KOKORO_ARTIFACTS_DIR
120  tar czf install.tgz install
121elif [ $TOOL = "cmake-smoketest" ]; then
122  using cmake-3.17.2
123  using ninja-1.10.0
124
125  # Get shaderc.
126  SHADERC_DIR=/tmp/shaderc
127  clean_dir "$SHADERC_DIR"
128  cd $SHADERC_DIR
129  git clone https://github.com/google/shaderc.git .
130  cd $SHADERC_DIR/third_party
131
132  # Get shaderc dependencies. Link the appropriate SPIRV-Tools.
133  git clone https://github.com/google/googletest.git
134  git clone https://github.com/KhronosGroup/glslang.git
135  ln -s $ROOT_DIR spirv-tools
136  git clone https://github.com/KhronosGroup/SPIRV-Headers.git spirv-headers
137  git clone https://github.com/google/re2
138  git clone https://github.com/google/effcee
139
140  cd $SHADERC_DIR
141  mkdir build
142  cd $SHADERC_DIR/build
143
144  # Invoke the build.
145  echo $(date): Starting build...
146  cmake -GNinja -DRE2_BUILD_TESTING=OFF -DCMAKE_BUILD_TYPE="Release" ..
147
148  echo $(date): Build glslang...
149  ninja glslangValidator
150
151  echo $(date): Build everything...
152  ninja
153  echo $(date): Build completed.
154
155  echo $(date): Check Shaderc for copyright notices...
156  ninja check-copyright
157
158  echo $(date): Starting ctest...
159  ctest --output-on-failure -j4
160  echo $(date): ctest completed.
161elif [ $TOOL = "cmake-android-ndk" ]; then
162  using cmake-3.17.2
163  using ndk-r21d
164  using ninja-1.10.0
165
166  clean_dir "$ROOT_DIR/build"
167  cd "$ROOT_DIR/build"
168
169  echo $(date): Starting build...
170  cmake -DCMAKE_BUILD_TYPE=Release \
171        -DANDROID_NATIVE_API_LEVEL=android-16 \
172        -DANDROID_ABI="armeabi-v7a with NEON" \
173        -DSPIRV_SKIP_TESTS=ON \
174        -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \
175        -GNinja \
176        -DANDROID_NDK=$ANDROID_NDK \
177        ..
178
179  echo $(date): Build everything...
180  ninja
181  echo $(date): Build completed.
182elif [ $TOOL = "android-ndk-build" ]; then
183  using ndk-r21d
184
185  clean_dir "$ROOT_DIR/build"
186  cd "$ROOT_DIR/build"
187
188  echo $(date): Starting ndk-build ...
189  $ANDROID_NDK_HOME/ndk-build \
190    -C $ROOT_DIR/android_test \
191    NDK_PROJECT_PATH=. \
192    NDK_LIBS_OUT=./libs \
193    NDK_APP_OUT=./app \
194    -j4
195
196  echo $(date): ndk-build completed.
197elif [ $TOOL = "bazel" ]; then
198  using bazel-3.1.0
199
200  echo $(date): Build everything...
201  bazel build :all
202  echo $(date): Build completed.
203
204  echo $(date): Starting bazel test...
205  bazel test :all
206  echo $(date): Bazel test completed.
207fi
208