1#!/bin/bash
2
3# Copyright 2020 The Amber Authors.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17set -e  # fail on error
18
19. /bin/using.sh # Declare the bash `using` function for configuring toolchains.
20
21set -x  # show commands
22
23# Disable git's "detected dubious ownership" error - kokoro checks out the repo with a different
24# user, and we don't care about this warning.
25git config --global --add safe.directory '*'
26
27using cmake-3.17.2
28using ninja-1.10.0
29
30if [ ! -z "$COMPILER" ]; then
31    using "$COMPILER"
32fi
33
34# Possible configurations are:
35# DEBUG, RELEASE
36
37BUILD_TYPE="Debug"
38if [ $CONFIG = "RELEASE" ]
39then
40  BUILD_TYPE="RelWithDebInfo"
41fi
42
43DEPS_ARGS=""
44if [[ "$EXTRA_CONFIG" =~ "USE_CLSPV=TRUE" ]]; then
45  DEPS_ARGS+=" --with-clspv"
46fi
47if [[ "$EXTRA_CONFIG" =~ "USE_DXC=TRUE" ]]; then
48  DEPS_ARGS+=" --with-dxc"
49fi
50if [[ "$EXTRA_CONFIG" =~ "ENABLE_SWIFTSHADER=TRUE" ]]; then
51  DEPS_ARGS+=" --with-swiftshader"
52fi
53
54cd $ROOT_DIR
55./tools/git-sync-deps $DEPS_ARGS
56
57mkdir -p build
58cd $ROOT_DIR/build
59
60# Invoke the build.
61BUILD_SHA=${KOKORO_GITHUB_COMMIT:-$KOKORO_GITHUB_PULL_REQUEST_COMMIT}
62echo $(date): Starting build...
63cmake -GNinja -DCMAKE_BUILD_TYPE=$BUILD_TYPE \
64  -DAMBER_USE_LOCAL_VULKAN=1 \
65  $EXTRA_CONFIG ..
66
67echo $(date): Build everything...
68ninja
69echo $(date): Build completed.
70
71echo $(date): Starting amber_unittests...
72./amber_unittests
73echo $(date): amber_unittests completed.
74
75# Swiftshader is only built with gcc, so only run the integration tests with gcc
76if [[ "$EXTRA_CONFIG" =~ "ENABLE_SWIFTSHADER=TRUE" ]]; then
77  OPTS=
78  if [[ $EXTRA_CONFIG =~ "USE_CLSPV=ON" ]]; then
79    OPTS="--use-opencl"
80  fi
81  if [[ "$EXTRA_CONFIG" =~ "USE_DXC=TRUE" ]]; then
82    OPTS+=" --use-dxc"
83  fi
84
85  echo $(date): Starting integration tests..
86  export LD_LIBRARY_PATH=$ROOT_DIR/build/third_party/vulkan-loader/loader
87  export VK_LAYER_PATH=$ROOT_DIR/build/third_party/vulkan-validationlayers/layers
88  export VK_ICD_FILENAMES=$ROOT_DIR/build/Linux/vk_swiftshader_icd.json
89  cd $ROOT_DIR
90  python3 ./tests/run_tests.py --build-dir $ROOT_DIR/build --use-swiftshader $OPTS
91  echo $(date): integration tests completed.
92fi
93