-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathbuild_static
executable file
·149 lines (129 loc) · 3.56 KB
/
build_static
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
#!/usr/bin/env bash
#
# Build the proxy-verifier binaries as statically linked and stripped.
#
# Copyright 2022, Verizon Media
# SPDX-License-Identifier: Apache-2.0
#
usage="`basename $0` <scons_arguments>"
tmpdir=/tmp/build_static.$$
buildout=${tmpdir}/build_output.txt
linkout=${tmpdir}/build_link_output.txt
staticout=${tmpdir}/build_static_output.txt
static_command=${tmpdir}/static_command.sh
fail()
{
echo $1
exit 1
}
set -e
os=$(uname)
[ "${os}" = "Linux" -o "${os}" = "Darwin" ] || fail "Unrecognized OS: ${os}"
#
# Do the initial build to get the build command.
#
if [ "${os}" = "Linux" ]
then
num_threads=$(nproc)
else
# MacOS.
num_threads=$(sysctl -n hw.logicalcpu)
fi
[ -f Sconstruct ] || fail "Not in the root directory of proxy-verifier."
if ! pipenv --venv > /dev/null 2>&1
then
pipenv install
fi
for i in `find . -name verifier-client -type f`; do rm $i; done
for i in `find . -name verifier-server -type f`; do rm $i; done
mkdir -p ${tmpdir}
command="pipenv run scons -j${num_threads} $@"
echo "Initial build: \"${command}\""
$command > ${buildout} 2>&1 || \
fail "Build command failed, see output in: ${buildout}"
libdir=/opt
if echo $@ | grep -q 'with-libs='
then
# Grab the argument with --with-libs=.
libdir=$(echo $@ | sed -e 's/.*--with-libs=\([^ ]*\).*/\1/')
elif echo $@ | grep -q 'with-libs '
then
# Grab the argument with --with-libs.
libdir=$(echo $@ | sed -e 's/.*--with-libs \([^ ]*\).*/\1/')
fi
grep -E '\-o _build.*\/verifier-(client|server) ' ${buildout} > ${linkout}
#
# Craft the command to statically link the binaries.
#
if [ "${os}" = "Linux" ]
then
sed 's/-o /-static -o /g' ${linkout} | \
sed 's/-Wl,-rpath[^ ]\+//g' | \
sed 's/-lpthread //g' | \
sed 's/$/ -Wl,--whole-archive -lpthread -Wl,--no-whole-archive -ldl/g' > \
${static_command}
else
openssl_dir=${libdir}/openssl
if [ -e _destdir/default/openssl ]
then
openssl_dir=_destdir/default/openssl
fi
ngtcp2_dir=${libdir}/ngtcp2
if [ -e _destdir/default/ngtcp2 ]
then
ngtcp2_dir=_destdir/default/ngtcp2
fi
nghttp2_dir=${libdir}/nghttp2
if [ -e _destdir/default/nghttp2 ]
then
nghttp2_dir=_destdir/default/nghttp2
fi
nghttp3_dir=${libdir}/nghttp3
if [ -e _destdir/default/nghttp3 ]
then
nghttp3_dir=_destdir/default/nghttp3
fi
sed "s:-lngtcp2_crypto_quictls[^[:space:]]*:${ngtcp2_dir}/lib/libngtcp2_crypto_quictls.a:g" ${linkout} | \
sed "s:-lssl[^[:space:]]*:${openssl_dir}/lib/libssl.a:g" | \
sed "s:-lcrypto[^[:space:]]*:${openssl_dir}/lib/libcrypto.a:g" | \
sed "s:-lngtcp2[^[:space:]]*:${ngtcp2_dir}/lib/libngtcp2.a:g" | \
sed "s:-lnghttp2[^[:space:]]*:${nghttp2_dir}/lib/libnghttp2.a:g" | \
sed "s:-lnghttp3[^[:space:]]*:${nghttp3_dir}/lib/libnghttp3.a:g" > \
${static_command}
fi
#
# Statically link the binaries.
#
for i in `find . -name verifier-client -type f`; do rm $i; done
for i in `find . -name verifier-server -type f`; do rm $i; done
echo "Running:"
cat ${static_command}
bash ${static_command} > ${staticout} 2>&1 || \
fail "Command to statically link failed, see: ${staticout}"
for f in $(grep -E -o '\S*/verifier-(client|server) ' ${linkout})
do
cp $f bin/
done
strip bin/verifier-*
#
# Verify they are statically linked.
#
for f in $(ls bin/verifier-*)
do
if [ "${os}" = "Linux" ]
then
ldd ${f} 2>&1 | grep -q "not a dynamic executable" || \
fail "${f} is not statically linked as expected."
fi
done
rm -rf ${tmpdir}
#
# Provide feedback to the user.
#
echo "Staticically linked binaries:"
if [ "${os}" = "Linux" ]
then
ldd bin/verifier-*
else
otool -L bin/verifier-*
fi