forked from facebook/mvfst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_helper.sh
executable file
·212 lines (187 loc) · 5.8 KB
/
build_helper.sh
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/bin/bash -eu
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
# This is a helpful script to build MVFST in the supplied dir
# It pulls in dependencies such as folly and fizz in the _build/deps dir.
# Useful constants
COLOR_RED="\033[0;31m"
COLOR_GREEN="\033[0;32m"
COLOR_OFF="\033[0m"
usage() {
cat 1>&2 <<EOF
Usage ${0##*/} [-h|?] [-p PATH] [-i INSTALL_PREFIX]
-p BUILD_DIR (optional): Path of the base dir for mvfst
-i INSTALL_PREFIX (optional): install prefix path
-m (optional): Build folly without jemalloc
-h|? Show this help message
EOF
}
while getopts ":hp:i:m" arg; do
case $arg in
p)
BUILD_DIR="${OPTARG}"
;;
i)
INSTALL_PREFIX="${OPTARG}"
;;
m)
MVFST_FOLLY_USE_JEMALLOC="n"
;;
h | *) # Display help.
usage
exit 0
;;
esac
done
# Validate required parameters
if [ -z "${BUILD_DIR-}" ] ; then
echo -e "${COLOR_RED}[ INFO ] Build dir is not set. So going to build into _build ${COLOR_OFF}"
BUILD_DIR=_build
mkdir -p $BUILD_DIR
fi
if [[ -n "${MVFST_FOLLY_USE_JEMALLOC-}" ]]; then
if [[ "$MVFST_FOLLY_USE_JEMALLOC" != "n" ]]; then
unset $MVFST_FOLLY_USE_JEMALLOC
fi
fi
### configure necessary build and install directories
cd $BUILD_DIR || exit
BWD=$(pwd)
DEPS_DIR=$BWD/deps
mkdir -p "$DEPS_DIR"
MVFST_BUILD_DIR=$BWD/build
mkdir -p "$MVFST_BUILD_DIR"
if [ -z "${INSTALL_PREFIX-}" ]; then
FOLLY_INSTALL_DIR=$DEPS_DIR
MVFST_INSTALL_DIR=$BWD
else
FOLLY_INSTALL_DIR=$INSTALL_PREFIX
MVFST_INSTALL_DIR=$INSTALL_PREFIX
fi
# Default to parallel build width of 4.
# If we have "nproc", use that to get a better value.
# If not, then intentionally go a bit conservative and
# just use the default of 4 (e.g., some desktop/laptop OSs
# have a tendency to freeze if we actually use all cores).
set +x
nproc=4
if [ -z "$(hash nproc 2>&1)" ]; then
nproc=$(nproc)
fi
set -x
function install_dependencies_linux() {
sudo apt-get install \
g++ \
cmake \
libboost-all-dev \
libevent-dev \
libdouble-conversion-dev \
libgoogle-glog-dev \
libgflags-dev \
libiberty-dev \
liblz4-dev \
liblzma-dev \
libsnappy-dev \
make \
zlib1g-dev \
binutils-dev \
libjemalloc-dev \
libssl-dev \
pkg-config \
libsodium-dev
}
function install_dependencies_mac() {
# install the default dependencies from homebrew
brew install \
cmake \
boost \
double-conversion \
gflags \
glog \
libevent \
lz4 \
snappy \
xz \
openssl \
libsodium
brew link \
boost \
double-conversion \
gflags \
glog \
libevent \
lz4 \
snappy \
xz \
libsodium
}
function setup_folly() {
FOLLY_DIR=$DEPS_DIR/folly
FOLLY_BUILD_DIR=$DEPS_DIR/folly/build/
if [ ! -d "$FOLLY_DIR" ] ; then
echo -e "${COLOR_GREEN}[ INFO ] Cloning folly repo ${COLOR_OFF}"
git clone https://github.com/facebook/folly.git "$FOLLY_DIR"
echo -e "${COLOR_GREEN}[ INFO ] install dependencies ${COLOR_OFF}"
if [ "$Platform" = "Linux" ]; then
install_dependencies_linux
elif [ "$Platform" = "Mac" ]; then
install_dependencies_mac
else
echo -e "${COLOR_RED}[ ERROR ] Unknown platform: $Platform ${COLOR_OFF}"
exit 1
fi
fi
if [ "$Platform" = "Mac" ]; then
# Homebrew installs OpenSSL in a non-default location on MacOS >= Mojave
# 10.14 because MacOS has its own SSL implementation. If we find the
# typical Homebrew OpenSSL dir, load OPENSSL_ROOT_DIR so that cmake
# will find the Homebrew version.
dir=/usr/local/opt/openssl
if [ -d $dir ]; then
export OPENSSL_ROOT_DIR=$dir
fi
fi
echo -e "${COLOR_GREEN}Building Folly ${COLOR_OFF}"
mkdir -p "$FOLLY_BUILD_DIR"
cd "$FOLLY_BUILD_DIR" || exit
# check for environment variable. If
if [[ -z "${MVFST_FOLLY_USE_JEMALLOC-}" ]]; then
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_PREFIX_PATH="$FOLLY_INSTALL_DIR" \
-DCMAKE_INSTALL_PREFIX="$FOLLY_INSTALL_DIR" \
..
else
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_PREFIX_PATH="$FOLLY_INSTALL_DIR" \
-DCMAKE_INSTALL_PREFIX="$FOLLY_INSTALL_DIR" \
-DFOLLY_USE_JEMALLOC=0 \
..
fi
make -j "$nproc"
make install
echo -e "${COLOR_GREEN}Folly is installed ${COLOR_OFF}"
cd "$BWD" || exit
}
function detect_platform() {
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) Platform=Linux;;
Darwin*) Platform=Mac;;
*) Platform="UNKNOWN:${unameOut}"
esac
echo -e "${COLOR_GREEN}Detected platform: $Platform ${COLOR_OFF}"
}
detect_platform
setup_folly
# build mvfst:
cd "$MVFST_BUILD_DIR" || exit
cmake -DCMAKE_PREFIX_PATH="$FOLLY_INSTALL_DIR" \
-DCMAKE_INSTALL_PREFIX="$MVFST_INSTALL_DIR" \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DBUILD_TESTS=On \
../..
make -j "$nproc"
echo -e "${COLOR_GREEN}MVFST build is complete. To run unit test: \
cd _build/build && make test ${COLOR_OFF}"