-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-fbcode-oss-ubuntu-18.04.sh
executable file
·272 lines (233 loc) · 7.48 KB
/
setup-fbcode-oss-ubuntu-18.04.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#!/bin/bash -ue
#
# This script will try to set up an environment with several of Facebook's
# open source components.
#
# Everything will be done relative to FBCODE_PREFIX, which must be set in
# the environment before this script is run.
ROOT="$(dirname "$(readlink -f "$0")")"
FBCODE_PREFIX=${FBCODE_PREFIX-}
FBCODE_PATCHES_DIR=${FBCODE_PATCHES_DIR-$ROOT/patches/}
export FBCODE_PREFIX
OPENSSL_DOWNLOAD_URL=${OPENSSL_DOWNLOAD_URL-'https://www.openssl.org/source/openssl-1.1.0j.tar.gz'}
log() {
echo "[$0]: $*" >&2
}
die() {
log "$*"
exit 1
}
ensure_root() {
if [ "$(id -u)" != "0" ]; then
die This script must be run as root
fi
}
setup_system_libraries() {
apt-get update && apt-get install -y \
autoconf \
autoconf-archive \
build-essential \
g++ \
cmake \
zlib1g-dev \
libzstd-dev \
libboost-all-dev \
libgoogle-glog-dev \
libdouble-conversion-dev \
libssl-dev \
libsodium-dev \
libbison-dev \
flex \
libgflags-dev \
libevent-dev \
git \
gperf \
wget \
unzip \
curl \
}
sanity_check() {
if ! grep -q "bionic" /etc/apt/sources.list; then
die This script is expected to only run on Ubuntu 18.04 instances
fi
}
get_install_order() {
tsort << 'EOF'
openssl folly
folly wangle
folly fizz
folly rsocket
fizz wangle
wangle thrift
wangle proxygen
proxygen thrift
mstch thrift
rsocket thrift
EOF
}
get_repo_commit() {
local repo="$1"
if [[ "$repo" == "mingtaoy-fbthrift" ]]; then
echo "perf_build"
elif [[ "$repo" == "rsocket" ]]; then
echo "752a99fecde36047299bb3f82f11abb6373206bc"
else
echo "v2018.12.24.00"
fi
}
assert_has_commit() {
local dir=$1
local commit=$2
pushd $dir >/dev/null
if ! git merge-base --is-ancestor "$commit" HEAD; then
die "Expected to have commit $commit in $dir"
fi
popd >/dev/null
}
CMAKE_ARGS="-DCMAKE_PREFIX_PATH=${FBCODE_PREFIX} -DCMAKE_INSTALL_PREFIX=${FBCODE_PREFIX} -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_POSITION_INDEPENDENT_CODE=On -DOPENSSL_ROOT_DIR=/fbcode"
LDFLAGS="-Wl,-rpath=$FBCODE_PREFIX/lib ${LDFLAGS-}"
PKG_CONFIG_PATH="${FBCODE_PREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH-}"
export LDFLAGS
export PKG_CONFIG_PATH
install_folly() {
[ -e "$FBCODE_PREFIX/build/folly/Makefile" ] && return
git clone https://github.com/facebook/folly "$FBCODE_PREFIX/src/folly"
cd "$FBCODE_PREFIX/src/folly"
git reset --hard $(get_repo_commit "folly")
mkdir -p "$FBCODE_PREFIX/build/folly" && cd "$FBCODE_PREFIX/build/folly"
cmake $CMAKE_ARGS "$FBCODE_PREFIX/src/folly"
make -j $(nproc)
make install
}
install_wangle() {
log "Installing wangle"
[ -e "$FBCODE_PREFIX/build/wangle/Makefile" ] && return
git clone https://github.com/facebook/wangle.git "$FBCODE_PREFIX/src/wangle"
cd "$FBCODE_PREFIX/src/wangle"
git reset --hard $(get_repo_commit "wangle")
mkdir -p "$FBCODE_PREFIX/build/wangle" && cd "$FBCODE_PREFIX/build/wangle"
cmake $CMAKE_ARGS "$FBCODE_PREFIX/src/wangle/wangle"
make -j $(nproc)
make install
}
install_mstch() {
[ -e "$FBCODE_PREFIX/build/mstch/Makefile" ] && return
git clone https://github.com/no1msd/mstch.git "$FBCODE_PREFIX/src/mstch"
mkdir -p "$FBCODE_PREFIX/build/mstch" && cd "$FBCODE_PREFIX/build/mstch"
cmake $CMAKE_ARGS "$FBCODE_PREFIX/src/mstch"
make -j $(nproc)
make install
}
install_fizz() {
[ -e "$FBCODE_PREFIX/build/fizz/Makefile" ] && return
git clone https://github.com/facebookincubator/fizz "$FBCODE_PREFIX/src/fizz"
cd "$FBCODE_PREFIX/src/fizz"
git reset --hard $(get_repo_commit "fizz")
mkdir -p "$FBCODE_PREFIX/build/fizz" && cd "$FBCODE_PREFIX/build/fizz"
cmake $CMAKE_ARGS -DBUILD_TESTS=No "$FBCODE_PREFIX/src/fizz/fizz"
make -j $(nproc)
make install
}
install_thrift() {
[ -e "$FBCODE_PREFIX/build/thrift/Makefile" ] && return
# For now, use my fork of fbthrift which has perf build support
if [ ! -d "$FBCODE_PREFIX/src/thrift" ] ; then
git clone -b perf_build https://github.com/mingtaoy/fbthrift.git "$FBCODE_PREFIX/src/thrift"
cd "$FBCODE_PREFIX/src/thrift"
git reset --hard $(get_repo_commit "mingtaoy-fbthrift")
fi
cd "$FBCODE_PREFIX/src/thrift"
mkdir -p "$FBCODE_PREFIX/build/thrift" && cd "$FBCODE_PREFIX/build/thrift"
cmake $CMAKE_ARGS "$FBCODE_PREFIX/src/thrift"
make -j $(nproc)
make install
cp "$FBCODE_PREFIX/build/thrift/bin/"{ThriftServer,loadgen} "$FBCODE_PREFIX/bin"
}
install_proxygen() {
[ -e "$FBCODE_PREFIX/src/proxygen/proxygen/configure" ] && return
if [ ! -d "$FBCODE_PREFIX/src/proxygen" ]; then
git clone https://github.com/facebook/proxygen.git "$FBCODE_PREFIX/src/proxygen"
cd "$FBCODE_PREFIX/src/proxygen"
git reset --hard $(get_repo_commit "proxygen")
assert_has_commit "$FBCODE_PREFIX/src/proxygen" 49727c7f7358b8eaa99cf2c1d910eea7cfb579d0
fi
cd "$FBCODE_PREFIX/src/proxygen/proxygen"
autoreconf -ivf
# Proxygen's autoconf script doesn't properly handle finding folly...
# so need to specify this manually.
env \
CPPFLAGS="-I${FBCODE_PREFIX}/include" \
LDFLAGS="-L${FBCODE_PREFIX}/lib" \
./configure --prefix=${FBCODE_PREFIX}
make -j $(nproc)
make install
}
install_rsocket() {
[ -e "$FBCODE_PREFIX/lib/cmake/rsocket" ] && return
if [ ! -d "$FBCODE_PREFIX/src/rsocket" ] ; then
git clone https://github.com/rsocket/rsocket-cpp.git "$FBCODE_PREFIX/src/rsocket"
cd "$FBCODE_PREFIX/src/rsocket"
git reset --hard $(get_repo_commit "rsocket")
fi
if [ ! -d "$FBCODE_PREFIX/build/rsocket" ]; then
mkdir -p "$FBCODE_PREFIX/build/rsocket"
cd "$FBCODE_PREFIX/build/rsocket"
cmake $CMAKE_ARGS -DBUILD_TESTS=No -DBUILD_BENCHMARKS=No -DBUILD_EXAMPLES=no "$FBCODE_PREFIX/src/rsocket/"
make -j $(nproc)
make install
fi
}
install_openssl() {
local openssl_src_dir="$FBCODE_PREFIX/src/openssl"
if [ -d "$openssl_src_dir" ] ; then
return
fi
local openssl_archive_name="$(basename "$OPENSSL_DOWNLOAD_URL")"
local downloaded_path=$(download_artifact "$OPENSSL_DOWNLOAD_URL" "$openssl_archive_name")
mkdir -p "$openssl_src_dir"
tar -xvf "$downloaded_path" --strip-components=1 -C "$openssl_src_dir"
cd "$openssl_src_dir"
local openssl_patches_dir="$FBCODE_PATCHES_DIR/openssl"
if [ -d "$openssl_patches_dir" ] ; then
for p in "$openssl_patches_dir"/*.patch; do
patch -p1 < "$p"
done
fi
./config --prefix="$FBCODE_PREFIX"
make -j $(nproc)
make install
if [ -d "$FBCODE_PREFIX/ssl/certs" ]; then
rm -rf "$FBCODE_PREFIX/ssl/certs"
ln -sf /etc/ssl/certs "$FBCODE_PREFIX/ssl/certs"
fi
}
download_artifact() {
local url="$1"
local target_name="$2"
mkdir -p ${FBCODE_PREFIX}/tmp
local out="${FBCODE_PREFIX}/tmp/${target_name}"
echo "$out"
if [ -e "$out" ]; then
return
fi
curl -o "$out" -fSL "$url"
}
setup_fb_components() {
set -x
local order=$(get_install_order)
log "Installation order: $order"
for item in $order; do
local cur=$(pwd)
"install_$item"
cd "$cur"
done
set +x
}
if [ -z "$FBCODE_PREFIX" ]; then
die "FBCODE_PREFIX is not set. Refusing to run".
fi
mkdir -p "$FBCODE_PREFIX/src" "$FBCODE_PREFIX/build"
ensure_root
sanity_check
setup_system_libraries
setup_fb_components