-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathsetup_env.sh
More file actions
executable file
·136 lines (112 loc) · 4.5 KB
/
Copy pathsetup_env.sh
File metadata and controls
executable file
·136 lines (112 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
# This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021-Present Datadog, Inc.
echoerr() { echo "$@" 1>&2; }
# Run source ./setup_env.sh
export PATH=$PATH:${PWD}/tools:${PWD}/bench/runners
# Helper command lines for cmake. Source this file, then you can just do :
# SanCMake ../
# Attempt to use the explicit latest known working version of GCC as default
DDPROF_CC_DEFAULT=gcc
DDPROF_CXX_DEFAULT=g++
for cc_ver in gcc-{12..9}; do
if command -v "$cc_ver" > /dev/null; then
DDPROF_CC_DEFAULT="$cc_ver"
break
fi
done
for cxx_ver in g++-{12..9}; do
if command -v "$cxx_ver" > /dev/null; then
DDPROF_CXX_DEFAULT="$cxx_ver"
break
fi
done
SCRIPTDIR="$(cd -- $( dirname -- "${BASH_SOURCE[0]}" ) && pwd)" # no "$0" when sourcing
DDPROF_INSTALL_PREFIX="../deliverables/ddprof"
DDPROF_COLLATZ_INSTALL_PREFIX="../deliverables/collatz"
DDPROF_BUILD_BENCH="ON"
COMPILER_SETTING="-DCMAKE_CXX_COMPILER=\"${CXX:-${DDPROF_CXX_DEFAULT}}\" -DCMAKE_C_COMPILER=\"${CC:-${DDPROF_CC_DEFAULT}}\""
echoerr "Compiler can be overriden with CXX and CC variables when sourcing this script. Current value:"
echoerr "${COMPILER_SETTING}"
# Avoid having the vendors compiled in the same directory
DDPROF_EXTENSION_CC=${CC:-"gcc"}
# strip version number from compiler
DDPROF_EXTENSION_CC=${DDPROF_EXTENSION_CC%-*}
LIBC_HAS_MUSL=$(ldd --version 2>&1 | grep musl || true)
if [ ! -z "${LIBC_HAS_MUSL}" ]; then
DDPROF_LIBC_VERSION=$(${SCRIPTDIR}/tools/get_libc_version.sh musl)
DDPROF_EXTENSION_OS="alpine-linux-${DDPROF_LIBC_VERSION}"
else
DDPROF_LIBC_VERSION=$(${SCRIPTDIR}/tools/get_libc_version.sh gnu)
DDPROF_EXTENSION_OS="unknown-linux-${DDPROF_LIBC_VERSION}"
fi
DEFAULT_ALLOCATOR_OPT="-DDDPROF_ALLOCATOR=JEMALLOC"
GetDefaultAllocatorOptions() {
echo ${DEFAULT_ALLOCATOR_OPT}
}
GetDirectoryExtention() {
# DebTidy is clang-only by design — force the clang segment of the build-dir
# name regardless of CC. The vendor extension is forced separately in
# DebTidyCMake (because CmakeWithOptions calls this with BUILD_TYPE=Debug).
local CC_SUFFIX=${DDPROF_EXTENSION_CC}
if [[ "$1" == "DebTidy" ]]; then
CC_SUFFIX=clang
fi
echo "_${CC_SUFFIX}_${DDPROF_EXTENSION_OS}_${1}"
}
COMMON_OPT="${COMPILER_SETTING} ${DEFAULT_ALLOCATOR_OPT} -DCMAKE_INSTALL_PREFIX=${DDPROF_INSTALL_PREFIX} -DCOLLATZ_INSTALL_PREFIX=${DDPROF_COLLATZ_INSTALL_PREFIX} -DBUILD_BENCHMARKS=${DDPROF_BUILD_BENCH}"
# echoerr "Cmake settings--\n ${COMMON_OPT}"
CmakeWithOptions() {
# Build mode
# Extra Parameters to cmake
local BUILD_TYPE=${1}
shift
local VENDOR_EXTENSION=$(GetDirectoryExtention ${BUILD_TYPE})
# shellcheck disable=SC2086
cmake_cmd="cmake -GNinja ${COMMON_OPT} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DVENDOR_EXTENSION=${VENDOR_EXTENSION} $@"
echoerr "-------------- cmake command -------------- "
echoerr ${cmake_cmd}
eval ${cmake_cmd}
}
RelCMake() {
local BUILD_TYPE=Release
CmakeWithOptions ${BUILD_TYPE} $@
}
DebCMake() {
local BUILD_TYPE=Debug
CmakeWithOptions ${BUILD_TYPE} $@
}
DebTidyCMake() {
local BUILD_TYPE=Debug
# VENDOR_EXTENSION uses BUILD_TYPE (Debug), so the DebTidy special-case in
# GetDirectoryExtention does not fire here — override locally so vendored
# deps land in _clang_*_Debug and are shared with CC=clang DebCMake builds
# rather than rebuilt for clang-tidy specifically.
local DDPROF_EXTENSION_CC=clang
if [[ ( -n "${CC:-}" && "${CC%-*}" != "clang" ) || ( -n "${CXX:-}" && "${CXX%-*}" != "clang++" ) ]]; then
echoerr "DebTidyCMake: forcing clang/clang++ (ignoring CC=${CC:-} CXX=${CXX:-} — clang-tidy requires clang)."
fi
CmakeWithOptions ${BUILD_TYPE} -DENABLE_CLANG_TIDY=ON -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ $@
}
SanCMake() {
local BUILD_TYPE=SanitizedDebug
CmakeWithOptions ${BUILD_TYPE} $@
}
TSanCMake() {
local BUILD_TYPE=ThreadSanitizedDebug
CmakeWithOptions ${BUILD_TYPE} $@
}
CovCMake() {
local BUILD_TYPE=Coverage
CmakeWithOptions ${BUILD_TYPE} $@
}
## Build a directory with a naming that reflects the OS / compiler we are using
## Example: MkBuildDir Rel --> build_gcc_unknown-linux-2.39_Rel
MkBuildDir() {
local BUILD_DIR_EXTENSION=$(GetDirectoryExtention ${1})
echo ${BUILD_DIR_EXTENSION}
mkdir -p build${BUILD_DIR_EXTENSION} && cd "$_" || exit 1
}
RunDDBuild() {
# run command as ddbuild user
su ddbuild su -s /bin/bash -c "$@" ddbuild
}