• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3# Copyright 2021 The Tint 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#     https://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 any error.
18
19function show_cmds { set -x; }
20function hide_cmds { { set +x; } 2>/dev/null; }
21function task_begin {
22    TASK_NAME="$@"
23    SECONDS=0
24}
25function print_last_task_duration {
26    if [ ! -z "${TASK_NAME}" ]; then
27        echo "${TASK_NAME} completed in $(($SECONDS / 3600))h$((($SECONDS / 60) % 60))m$(($SECONDS % 60))s"
28    fi
29}
30function status {
31    echo ""
32    echo ""
33    print_last_task_duration
34    echo ""
35    echo "*****************************************************************"
36    echo "* $@"
37    echo "*****************************************************************"
38    echo ""
39    task_begin $@
40}
41function with_retry {
42  local MAX_ATTEMPTS=5
43  local RETRY_DELAY_SECS=5
44  local ATTEMPT=1
45  while true; do
46    "$@" && break
47    if [[ $ATTEMPT -ge $MAX_ATTEMPTS ]]; then
48        echo "The command has failed after $ATTEMPT attempts."
49        exit $?
50    fi
51    ((ATTEMPT++))
52    echo "'$@' failed. Attempt ($ATTEMPT/$MAX_ATTEMPTS). Retrying..."
53    sleep $RETRY_DELAY_SECS;
54  done
55}
56
57CLONE_SRC_DIR="$(pwd)"
58
59. /bin/using.sh # Declare the bash `using` function for configuring toolchains.
60
61using depot_tools
62using go-1.14.4      # Speeds up ./tools/lint
63using doxygen-1.8.18
64
65status "Cloning to clean source directory at '${SRC_DIR}'"
66
67mkdir -p ${SRC_DIR}
68cd ${SRC_DIR}
69git clone ${CLONE_SRC_DIR} .
70
71status "Fetching dependencies"
72cp standalone.gclient .gclient
73with_retry gclient sync
74
75status "Linting"
76./tools/lint
77
78status "Configuring build system"
79if [ "$BUILD_SYSTEM" == "cmake" ]; then
80    using cmake-3.17.2
81
82    BUILD_DIR=/tmp/tint-build
83    mkdir -p ${BUILD_DIR}
84
85    COMMON_CMAKE_FLAGS=""
86    COMMON_CMAKE_FLAGS+=" -DCMAKE_BUILD_TYPE=${BUILD_TYPE}"
87    COMMON_CMAKE_FLAGS+=" -DTINT_DOCS_WARN_AS_ERROR=ON"
88
89    if [ "$BUILD_TOOLCHAIN" == "clang" ]; then
90        using clang-10.0.0
91        COMMON_CMAKE_FLAGS+=" -DTINT_BUILD_FUZZERS=1"
92        COMMON_CMAKE_FLAGS+=" -DTINT_BUILD_SPIRV_TOOLS_FUZZER=1"
93        COMMON_CMAKE_FLAGS+=" -DTINT_BUILD_AST_FUZZER=1"
94        COMMON_CMAKE_FLAGS+=" -DTINT_BUILD_REGEX_FUZZER=1"
95    elif [ "$BUILD_TOOLCHAIN" == "gcc" ]; then
96        using gcc-9
97    fi
98
99    if [ "$BUILD_SANITIZER" == "asan" ]; then
100        COMMON_CMAKE_FLAGS+=" -DTINT_ENABLE_ASAN=1"
101    elif [ "$BUILD_SANITIZER" == "ubsan" ]; then
102        COMMON_CMAKE_FLAGS+=" -DTINT_ENABLE_UBSAN=1"
103        export UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1
104    fi
105
106    cd ${BUILD_DIR}
107
108    status "Running Doxygen"
109    echo "NOTE: This will fail on first warning. Run with -DTINT_DOCS_WARN_AS_ERROR=OFF to see all warnings".
110    echo ""
111    show_cmds
112        # NOTE: If we upgrade Doxygen to a more recent version, we can set DOXYGEN_WARN_AS_ERROR to
113        # "FAIL_ON_WARNINGS" instead of "YES" in our CMakeLists.txt so see all warnings, and then
114        # fail. See https://www.doxygen.nl/manual/config.html#cfg_warn_as_error
115        cmake ${SRC_DIR} ${CMAKE_FLAGS} ${COMMON_CMAKE_FLAGS}
116        cmake --build . --target tint-docs
117    hide_cmds
118
119    status "Building tint"
120    show_cmds
121        cmake ${SRC_DIR} ${CMAKE_FLAGS} ${COMMON_CMAKE_FLAGS}
122        cmake --build . -- --jobs=$(nproc)
123    hide_cmds
124
125    status "Running tint_unittests"
126    show_cmds
127        ./tint_unittests
128    hide_cmds
129
130    if [ -f ./tint_ast_fuzzer_unittests ]; then
131        status "Running tint_ast_fuzzer_unittests"
132        show_cmds
133            ./tint_ast_fuzzer_unittests
134        hide_cmds
135    fi
136
137    if [ -f ./tint_regex_fuzzer_unittests ]; then
138        status "Running tint_regex_fuzzer_unittests"
139        show_cmds
140            ./tint_regex_fuzzer_unittests
141        hide_cmds
142    fi
143
144    status "Testing test/test-all.sh"
145    show_cmds
146        ${SRC_DIR}/test/test-all.sh "${BUILD_DIR}/tint" --verbose
147    hide_cmds
148
149    status "Checking _other.cc files also build"
150    show_cmds
151        cmake ${SRC_DIR} ${CMAKE_FLAGS} ${COMMON_CMAKE_FLAGS} -DTINT_BUILD_AS_OTHER_OS=ON
152        cmake --build . -- --jobs=$(nproc)
153        cmake ${SRC_DIR} ${CMAKE_FLAGS} ${COMMON_CMAKE_FLAGS} -DTINT_BUILD_AS_OTHER_OS=OFF
154    hide_cmds
155
156    status "Checking disabling all readers and writers also builds"
157    show_cmds
158        cmake ${SRC_DIR} ${CMAKE_FLAGS} ${COMMON_CMAKE_FLAGS} -DTINT_BUILD_SPV_READER=OFF -DTINT_BUILD_SPV_WRITER=OFF -DTINT_BUILD_WGSL_READER=OFF -DTINT_BUILD_WGSL_WRITER=OFF -DTINT_BUILD_MSL_WRITER=OFF -DTINT_BUILD_HLSL_WRITER=OFF
159        cmake --build . -- --jobs=$(nproc)
160        cmake ${SRC_DIR} ${CMAKE_FLAGS} ${COMMON_CMAKE_FLAGS} -DTINT_BUILD_SPV_READER=ON -DTINT_BUILD_SPV_WRITER=ON -DTINT_BUILD_WGSL_READER=ON -DTINT_BUILD_WGSL_WRITER=ON -DTINT_BUILD_MSL_WRITER=ON -DTINT_BUILD_HLSL_WRITER=ON
161    hide_cmds
162else
163    status "Unsupported build system: $BUILD_SYSTEM"
164    exit 1
165fi
166
167status "Done"
168