2022-04-07 19:22:21 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# Copyright 2022 The Tint Authors
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
set -e # Fail on any error.
|
|
|
|
|
|
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )"
|
2022-10-13 12:55:42 +00:00
|
|
|
ROOT_DIR="$( cd "$SCRIPT_DIR/.." >/dev/null 2>&1 && pwd )"
|
|
|
|
|
|
|
|
POSSIBLE_BUILD_SYSTEMS="[gn|cmake]"
|
|
|
|
POSSIBLE_BUILD_TYPES="[debug|release]"
|
|
|
|
POSSIBLE_BUILD_ARCHS="[native|x86]"
|
|
|
|
|
|
|
|
BUILD_SYSTEM=""
|
|
|
|
BUILD_TYPE=""
|
|
|
|
BUILD_ARCH=""
|
2022-04-07 19:22:21 +00:00
|
|
|
|
|
|
|
function show_usage() {
|
2022-10-13 12:55:42 +00:00
|
|
|
echo "setup-build $POSSIBLE_BUILD_SYSTEMS $POSSIBLE_BUILD_TYPES $POSSIBLE_BUILD_ARCHS"
|
2022-04-07 19:22:21 +00:00
|
|
|
echo
|
|
|
|
echo "creates a build directory in <dawn>/out using either GN or CMake, then"
|
|
|
|
echo "updates the '<dawn>/out/active' symlink to point to the build directory"
|
2022-10-13 12:55:42 +00:00
|
|
|
if [[ ! -z "$1" ]]; then
|
|
|
|
echo
|
|
|
|
echo "$1"
|
|
|
|
fi
|
2022-04-07 19:22:21 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2022-10-13 12:55:42 +00:00
|
|
|
function set_build_system() {
|
|
|
|
if [[ ! -z "$BUILD_SYSTEM" ]]; then
|
|
|
|
echo "conflicting build systems $BUILD_SYSTEM and $1"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
BUILD_SYSTEM=$1
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_build_type() {
|
|
|
|
if [[ ! -z "$BUILD_TYPE" ]]; then
|
|
|
|
echo "conflicting build types $BUILD_TYPE and $1"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
BUILD_TYPE=$1
|
|
|
|
}
|
|
|
|
|
|
|
|
function set_build_arch() {
|
|
|
|
if [[ ! -z "$BUILD_ARCH" ]]; then
|
|
|
|
echo "conflicting build architectures $BUILD_ARCH and $1"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
BUILD_ARCH=$1
|
|
|
|
}
|
|
|
|
|
|
|
|
for arg in "$@"; do
|
|
|
|
lowered_arg=$(echo "$arg" | tr '[:upper:]' '[:lower:]') # lowercase
|
|
|
|
case $lowered_arg in
|
|
|
|
"gn")
|
|
|
|
set_build_system $lowered_arg
|
|
|
|
;;
|
|
|
|
"cmake")
|
|
|
|
set_build_system $lowered_arg
|
|
|
|
;;
|
|
|
|
"debug")
|
|
|
|
set_build_type $lowered_arg
|
|
|
|
;;
|
|
|
|
"release")
|
|
|
|
set_build_type $lowered_arg
|
|
|
|
;;
|
|
|
|
"x86")
|
|
|
|
set_build_arch $lowered_arg
|
|
|
|
;;
|
|
|
|
"native")
|
|
|
|
;;
|
|
|
|
"--help" | "-help" | "-h")
|
|
|
|
show_usage
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
show_usage "unknown argument '$arg'"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ -z "$BUILD_SYSTEM" ]]; then
|
|
|
|
show_usage "build system $POSSIBLE_BUILD_SYSTEMS is required"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z "$BUILD_TYPE" ]]; then
|
|
|
|
show_usage "build type $POSSIBLE_BUILD_TYPES required"
|
|
|
|
fi
|
|
|
|
|
|
|
|
BUILD_DIR="$BUILD_SYSTEM-$BUILD_TYPE"
|
|
|
|
if [[ ! -z "$BUILD_ARCH" ]]; then
|
|
|
|
BUILD_DIR+="-$BUILD_ARCH"
|
|
|
|
fi
|
|
|
|
|
2022-04-07 19:22:21 +00:00
|
|
|
function generate() {
|
|
|
|
pushd "$ROOT_DIR" > /dev/null
|
2022-04-29 20:18:45 +00:00
|
|
|
mkdir -p "out/$BUILD_DIR"
|
|
|
|
rm -fr "out/active" || true
|
|
|
|
ln -s "$BUILD_DIR" "out/active"
|
2022-10-13 12:55:42 +00:00
|
|
|
"$@"
|
2022-04-07 19:22:21 +00:00
|
|
|
popd > /dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
case $BUILD_SYSTEM in
|
|
|
|
"gn")
|
2022-10-13 12:55:42 +00:00
|
|
|
GN_ARGS=""
|
2022-04-07 19:22:21 +00:00
|
|
|
case $BUILD_TYPE in
|
|
|
|
"debug")
|
2022-10-13 12:55:42 +00:00
|
|
|
GN_ARGS+="is_debug=true"
|
2022-04-07 19:22:21 +00:00
|
|
|
;;
|
|
|
|
"release")
|
2022-10-13 12:55:42 +00:00
|
|
|
GN_ARGS+="is_debug=false"
|
2022-04-07 19:22:21 +00:00
|
|
|
;;
|
|
|
|
*)
|
2022-10-13 12:55:42 +00:00
|
|
|
show_usage "invalid build type '$BUILD_TYPE'"
|
2022-04-07 19:22:21 +00:00
|
|
|
;;
|
|
|
|
esac
|
2022-10-13 12:55:42 +00:00
|
|
|
case $BUILD_ARCH in
|
|
|
|
"")
|
|
|
|
;;
|
|
|
|
"x86")
|
|
|
|
GN_ARGS+=" target_cpu=\"x86\""
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
show_usage "invalid build architecture '$BUILD_ARCH'"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
generate "gn" "gen" "out/active" "--args=$GN_ARGS"
|
2022-04-07 19:22:21 +00:00
|
|
|
;;
|
|
|
|
"cmake")
|
2022-10-13 12:55:42 +00:00
|
|
|
CMAKE_FLAGS=()
|
|
|
|
CMAKE_FLAGS+=("-DTINT_BUILD_GLSL_WRITER=1")
|
|
|
|
CMAKE_FLAGS+=("-DTINT_BUILD_HLSL_WRITER=1")
|
|
|
|
CMAKE_FLAGS+=("-DTINT_BUILD_MSL_WRITER=1")
|
|
|
|
CMAKE_FLAGS+=("-DTINT_BUILD_SPV_WRITER=1")
|
|
|
|
CMAKE_FLAGS+=("-DTINT_BUILD_WGSL_WRITER=1")
|
2022-04-29 20:18:45 +00:00
|
|
|
if [[ -x $(command -v ccache) ]]; then
|
2022-10-13 12:55:42 +00:00
|
|
|
CMAKE_FLAGS+=("-DCMAKE_CXX_COMPILER_LAUNCHER=ccache")
|
2022-04-29 20:18:45 +00:00
|
|
|
fi
|
2022-04-07 19:22:21 +00:00
|
|
|
case $BUILD_TYPE in
|
|
|
|
"debug")
|
2022-10-13 12:55:42 +00:00
|
|
|
CMAKE_FLAGS+=("-DCMAKE_BUILD_TYPE=Debug")
|
2022-04-07 19:22:21 +00:00
|
|
|
;;
|
|
|
|
"release")
|
2022-10-13 12:55:42 +00:00
|
|
|
CMAKE_FLAGS+=("-DCMAKE_BUILD_TYPE=RelWithDebInfo")
|
2022-04-07 19:22:21 +00:00
|
|
|
;;
|
|
|
|
*)
|
2022-10-13 12:55:42 +00:00
|
|
|
show_usage "invalid build type '$BUILD_TYPE'"
|
2022-04-07 19:22:21 +00:00
|
|
|
;;
|
|
|
|
esac
|
2022-10-13 12:55:42 +00:00
|
|
|
case $BUILD_ARCH in
|
|
|
|
"")
|
|
|
|
;;
|
|
|
|
"x86")
|
|
|
|
CMAKE_FLAGS+=("-DCMAKE_CXX_FLAGS=-m32")
|
|
|
|
CMAKE_FLAGS+=("-DCMAKE_C_FLAGS=-m32")
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
show_usage "invalid build architecture '$BUILD_ARCH'"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
generate "cmake" \
|
|
|
|
"-S" "." \
|
|
|
|
"-B" "out/active" \
|
|
|
|
"-GNinja" \
|
|
|
|
"${CMAKE_FLAGS[@]}"
|
2022-04-07 19:22:21 +00:00
|
|
|
;;
|
|
|
|
*)
|
2022-10-13 12:55:42 +00:00
|
|
|
echo "invalid build system '$BUILD_SYSTEM'"
|
2022-04-07 19:22:21 +00:00
|
|
|
show_usage
|
|
|
|
;;
|
|
|
|
esac
|