-
Notifications
You must be signed in to change notification settings - Fork 16
/
build_epid_ra.sh
executable file
·159 lines (133 loc) · 4.16 KB
/
build_epid_ra.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
#!/usr/bin/env bash
THISDIR="$(dirname $(readlink -f $0))"
INSTALLDIR="/usr/local/occlum/x86_64-linux-musl"
OCCLUMCC="/usr/local/occlum/bin/occlum-gcc"
OCCLUMCXX="/usr/local/occlum/bin/occlum-g++"
export CC=$OCCLUMCC
export CXX=$OCCLUMCXX
export PATH=$PATH:$INSTALLDIR/bin
export PKG_CONFIG_LIBDIR=$PKG_CONFIG_LIBDIR:$INSTALLDIR/lib
DEPSDIR="$THISDIR/deps"
ALL_COMPONENTS="openssl libcurl secure_signer"
OPENSSLDIR=openssl
CURLDIR=curl
CPPCODECDIR=cppcodec
RAPIDJSONDIR=rapidjson
SHOW_HELP() {
LOG_INFO "Usage: $0 [component-name]\n"
LOG_INFO "Build component in [$ALL_COMPONENTS] or all by default\n"
exit 0
}
LOG_DEBUG() {
echo -e "\033[36m$@\033[0m"
}
LOG_INFO() {
echo -e "\033[32m$@\033[0m"
}
LOG_ERROR() {
echo -e "\033[31m$@\033[0m"
}
ERROR_EXIT() {
LOG_ERROR "$@" && exit 1
}
TRYGET() {
local dst=$1
local url=$2
local pkg=${3:-$(basename $url)}
local flag="./occlum_demo_source"
# Download package tarball
if [ ! -e $pkg ] ; then
LOG_DEBUG "Downloading $pkg ..."
wget $url -O $pkg || ERROR_EXIT "Fail to download $pkg"
else
LOG_INFO "[READY] $pkg"
fi
# Prepare the source code directory
if [ ! -f $dst/$flag ] ; then
LOG_DEBUG "Preparing source code: $dst ..."
mkdir -p $dst && \
tar -xvf $pkg -C $dst --strip-components 1 >/dev/null || \
ERROR_EXIT "Fail to extract archive file $pkg"
touch $dst/$flag && \
LOG_DEBUG "Prepare $(basename $dst) source code successfully"
else
LOG_INFO "[READY] $dst"
fi
}
openssl_check() {
[ -f "$INSTALLDIR/lib/libcrypto.so" ] || return 1
}
openssl_build() {
cd "$DEPSDIR/$OPENSSLDIR" && \
CC=$OCCLUMCC CXX=$OCCLUMCXX \
./config --prefix=$INSTALLDIR \
--openssldir=/usr/local/occlum/ssl \
--with-rand-seed=rdcpu \
no-zlib no-async no-tests && \
make -j && make install
}
libcurl_check() {
[ -f "$INSTALLDIR/lib/libcurl.so" ] || return 1
}
libcurl_build() {
cd "$DEPSDIR/$CURLDIR"
if [ ! -f ./configure ] ; then
LOG_DEBUG "Building configure file ..."
./buildconf || exit 1
fi
CC=$OCCLUMCC CXX=$OCCLUMCXX \
./configure \
--prefix=$INSTALLDIR \
--with-ssl=$INSTALLDIR \
--without-zlib && \
make -j && make install
}
secure_signer_check() {
[ -f "$INSTALLDIR/lib/libepid.a" ] || return 1
}
secure_signer_build() {
cd "$THISDIR"
rm -rf build && mkdir build && cd build && \
echo "[+] Cleaned libocclum.ra and libepid.ra"
cmake ../ \
-DCMAKE_NO_SYSTEM_FROM_IMPORTED=TRUE \
-DCMAKE_CXX_COMPILER=$OCCLUMCXX \
-DBUILD_MODE=${BUILDMODE} && \
make -j $BUILDVERBOSE && \
cp $THISDIR/build/libocclumra.a $INSTALLDIR/lib
cp $THISDIR/build/libepid_ra.a $INSTALLDIR/lib # added by me
cp $THISDIR/build/libepid.so $INSTALLDIR/lib # added by me
# combine the static libs into a single one to link to in rust
COMBINED_LIB="libepid.a"
ar -x ${INSTALLDIR}/lib/libocclumra.a
ar -x ${INSTALLDIR}/lib/libepid_ra.a
ar -x ${INSTALLDIR}/lib/libcurl.a
ar -x ${INSTALLDIR}/lib/libcrypto.a
ar -x ${INSTALLDIR}/lib/libssl.a
ar -crs ${COMBINED_LIB} *.o
rm *.o
cp $THISDIR/build/${COMBINED_LIB} $INSTALLDIR/lib
}
# Show help menu
[ "$1" == "-h" -o "$1" == "--help" ] && SHOW_HELP
# Check the build mode
BUILDMODE="Release"
BUILDVERBOSE=""
if [ "$1" == "--debug" ] ; then
BUILDMODE="Debug"
BUILDVERBOSE="VERBOSE=1"
shift;
fi
# Build specified component or all by default
BUILD_COMPONENTS="${1:-$ALL_COMPONENTS}"
# Download all components once here together
mkdir -p $DEPSDIR && cd $DEPSDIR || exit 1
TRYGET $OPENSSLDIR https://github.com/openssl/openssl/archive/OpenSSL_1_1_1.tar.gz
TRYGET $CURLDIR https://github.com/curl/curl/archive/curl-7_70_0.tar.gz
TRYGET $CPPCODECDIR https://github.com/tplgy/cppcodec/archive/v0.2.tar.gz cppcodec-0.2.tar.gz
TRYGET $RAPIDJSONDIR https://github.com/Tencent/rapidjson/archive/v1.1.0.tar.gz rapidjson-1.1.0.tar.gz
for i in $BUILD_COMPONENTS ; do
${i}_check && LOG_INFO "[READY] build check for $i" && continue
LOG_DEBUG "Building $i ..." && ${i}_build && \
LOG_DEBUG "Build $i successfully" || ERROR_EXIT "Fail to build $i"
done