forked from hyperledger/besu-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·353 lines (278 loc) · 9.19 KB
/
build.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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#!/usr/bin/env bash
#############################
######### Variables #########
#############################
# Edit this variable to change the build options for secp256k1
SECP256K1_BUILD_OPTS="--enable-module-recovery"
#############################
####### End Variables #######
#############################
# Initialize external vars - need this to get around unbound variable errors
SKIP_GRADLE="$SKIP_GRADLE"
# Exit script if you try to use an uninitialized variable.
set -o nounset
# Exit script if a statement returns a non-true return value.
set -o errexit
# Use the error status of the first failure, rather than that of the last item in a pipeline.
set -o pipefail
# Resolve the directory that contains this script. We have to jump through a few
# hoops for this because the usual one-liners for this don't work if the script
# is a symlink
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
SCRIPTDIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
# Determine core count for parallel make
if [[ "$OSTYPE" == "linux-gnu" ]]; then
CORE_COUNT=$(nproc)
OSARCH=${OSTYPE%%[0-9.]*}-`arch`
fi
if [[ "$OSTYPE" == "darwin"* ]]; then
CORE_COUNT=$(sysctl -n hw.ncpu)
if [[ "`machine`" == "arm"* ]]; then
arch_name="aarch64"
export CFLAGS="-arch arm64"
else
arch_name="x86-64"
export CFLAGS="-arch x86_64"
fi
OSARCH="darwin-$arch_name"
fi
# add to path cargo
[ -f $HOME/.cargo/env ] && . $HOME/.cargo/env
# add to path brew
[ -f $HOME/.zprofile ] && . $HOME/.zprofile
build_blake2bf() {
cat <<EOF
#############################
###### build blake2bf ######
#############################
EOF
# This version of arm blake is actually slower than java blake on arm
if [[ "$OSARCH" == "linux-gnu-aarch64" ]]; then
return
#cd "$SCRIPTDIR/blake2bf/arm64"
else if [[ "$OSARCH" == "darwin-aarch64" ]]; then
return
#cd "$SCRIPTDIR/blake2bf/aarch64"
else
cd "$SCRIPTDIR/blake2bf/x86_64"
fi
# delete old build dir, if exists
rm -rf "$SCRIPTDIR/blake2bf/build" || true
if [[ -e makefile ]]; then
make clean
fi
make
mkdir -p "$SCRIPTDIR/blake2bf/build/${OSARCH}/lib"
mv libblake2bf.* "$SCRIPTDIR/blake2bf/build/${OSARCH}/lib"
fi
}
build_secp256k1() {
cat <<EOF
#############################
###### build secp256k1 ######
#############################
EOF
cd "$SCRIPTDIR/secp256k1/bitcoin-core-secp256k1"
# delete old build dir, if exists
rm -rf "$SCRIPTDIR/secp256k1/build" || true
if [[ -e Makefile ]]; then
make clean
fi
./autogen.sh && \
./configure --prefix="$SCRIPTDIR/secp256k1/build/${OSARCH}" $SECP256K1_BUILD_OPTS && \
make -j $CORE_COUNT && \
make -j $CORE_COUNT install
}
build_altbn128() {
cat <<EOF
############################
###### build altbn128 ######
############################
EOF
echo "building altbn128 for ${OSARCH}"
cd "$SCRIPTDIR/altbn128/sputnikvm_altbn128"
# delete old build dir, if exists
rm -rf "$SCRIPTDIR/altbn128/build" || true
mkdir -p "$SCRIPTDIR/altbn128/build/${OSARCH}/lib"
cargo clean
if [[ "$OSTYPE" == "darwin"* ]]; then
lipo_lib "libeth_altbn128" ""
else
cargo build --lib --release
fi
mkdir -p "$SCRIPTDIR/altbn128/build/${OSARCH}/lib"
cp target/release/libeth_altbn128.* "$SCRIPTDIR/altbn128/build/${OSARCH}/lib"
}
build_arithmetic() {
cat <<EOF
##############################
###### build arithmetic ######
##############################
EOF
cd "$SCRIPTDIR/arithmetic/arithmetic"
# delete old build dir, if exists
rm -rf "$SCRIPTDIR/arithmetic/build" || true
mkdir -p "$SCRIPTDIR/arithmetic/build/lib"
cargo clean
if [[ "$OSTYPE" == "darwin"* ]]; then
lipo_lib "libeth_arithmetic" ""
else
cargo build --lib --release
fi
mkdir -p "$SCRIPTDIR/arithmetic/build/${OSARCH}/lib"
cp target/release/libeth_arithmetic.* "$SCRIPTDIR/arithmetic/build/${OSARCH}/lib"
}
build_ipa_multipoint() {
cat <<EOF
##################################
###### build ipa_multipoint ######
##################################
EOF
cd "$SCRIPTDIR/ipa-multipoint/ipa_multipoint_jni"
# delete old build dir, if exists
rm -rf "$SCRIPTDIR/ipa-multipoint/build" || true
mkdir -p "$SCRIPTDIR/ipa-multipoint/build/${OSARCH}/lib"
cargo clean
if [[ "$OSARCH" == "darwin-x86-64" ]]; then
cargo build --lib --release --target=x86_64-apple-darwin
lipo -create \
-output target/release/libipa_multipoint_jni.dylib \
-arch x86_64 target/x86_64-apple-darwin/release/libipa_multipoint_jni.dylib
lipo -info ./target/release/libipa_multipoint_jni.dylib
elif [[ "$OSARCH" == "darwin-aarch64" ]]; then
cargo build --lib --release --target=aarch64-apple-darwin
lipo -create \
-output target/release/libipa_multipoint_jni.dylib \
-arch arm64 target/aarch64-apple-darwin/release/libipa_multipoint_jni.dylib
lipo -info ./target/release/libipa_multipoint_jni.dylib
else
cargo build --lib --release
fi
mkdir -p "$SCRIPTDIR/ipa-multipoint/build/${OSARCH}/lib"
cp target/release/libipa_multipoint_jni.* "$SCRIPTDIR/ipa-multipoint/build/${OSARCH}/lib"
}
build_bls12_381() {
cat <<EOF
#############################
###### build BLS12-381 ######
#############################
EOF
echo "building bls12-381 for ${OSARCH}"
cd "$SCRIPTDIR/bls12-381/updated-eip1962"
# delete old build dir, if exists
rm -rf "$SCRIPTDIR/bls12-381/build" || true
mkdir -p "$SCRIPTDIR/bls12-381/build/${OSARCH}/lib"
cargo clean
if [[ "$OSTYPE" == "darwin"* ]]; then
lipo_lib "libeth_pairings" "--features eip_2357_c_api"
else
cargo build --lib --features eip_2357_c_api --release
fi
mkdir -p "$SCRIPTDIR/bls12-381/build/${OSARCH}/lib"
cp target/release/libeth_pairings.* "$SCRIPTDIR/bls12-381/build/${OSARCH}/lib"
}
build_jars(){
########################
###### build jars ######
########################
if [[ "$SKIP_GRADLE" != "true" ]]; then
cd $SCRIPTDIR
./gradlew build
fi
}
lipo_lib() {
cat <<EOF
#################################################
# multi-arch OSX universal binary build wrapper #
#################################################
EOF
LIBNAME=$1
SWITCHES=$2
# build both architectures
cargo build --lib $SWITCHES --release --target=x86_64-apple-darwin
cargo build --lib $SWITCHES --release --target=aarch64-apple-darwin
lipo -create \
-output target/release/$1.dylib \
-arch x86_64 target/x86_64-apple-darwin/release/$1.dylib \
-arch arm64 target/aarch64-apple-darwin/release/$1.dylib
}
build_secp256r1() {
cat <<EOF
#############################
###### build secp256r1 ######
#############################
EOF
cd "$SCRIPTDIR/secp256r1/besu-native-ec"
# delete old build dir, if exists
rm -rf "$SCRIPTDIR/secp256r1/build" || true
find . -name *.o -exec rm -rf {} \;
if [[ "$OSTYPE" == "msys" ]]; then
LIBRARY_EXTENSION=dll
EXTRA_FLAGS=""
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
LIBRARY_EXTENSION=so
EXTRA_FLAGS=""
elif [[ "$OSTYPE" == "darwin"* ]]; then
LIBRARY_EXTENSION=dylib
EXTRA_FLAGS="no-asm" # avoid assembly because of pipeline error
fi
OPENSSL_PLATFORM=""
if [[ "$OSARCH" == "linux-gnu-aarch64" ]]; then
OPENSSL_PLATFORM="linux-aarch64"
fi
git submodule init
git submodule update
cd openssl
./Configure $OPENSSL_PLATFORM enable-ec_nistp_64_gcc_128 no-stdio no-ocsp no-nextprotoneg no-module \
no-legacy no-gost no-engine no-dynamic-engine no-deprecated no-comp \
no-cmp no-capieng no-ui-console no-tls no-ssl no-dtls no-aria no-bf \
no-blake2 no-camellia no-cast no-chacha no-cmac no-des no-dh no-dsa \
no-ecdh no-idea no-md4 no-mdc2 no-ocb no-poly1305 no-rc2 no-rc4 no-rmd160 \
no-scrypt no-seed no-siphash no-siv no-sm2 no-sm3 no-sm4 no-whirlpool $EXTRA_FLAGS
make build_generated libcrypto.$LIBRARY_EXTENSION
cd ../
./build.sh
if [[ "$OSTYPE" == "darwin"* ]]; then
lipo -info ./release/libbesu_native_ec.dylib
lipo -info ./release/libbesu_native_ec_crypto.dylib
fi
mkdir -p "./release/${OSARCH}"
echo `pwd`
cp ./release/libbesu_native_ec* "./release/${OSARCH}/"
}
build_gnark() {
cat <<EOF
############################
####### build gnark #######
############################
EOF
cd "$SCRIPTDIR/gnark/gnark-jni"
# delete old build dir, if exists
rm -rf "$SCRIPTDIR/gnark/build" || true
mkdir -p "$SCRIPTDIR/gnark/build/lib"
if [[ "$OSTYPE" == "msys" ]]; then
LIBRARY_EXTENSION=dll
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
LIBRARY_EXTENSION=so
elif [[ "$OSTYPE" == "darwin"* ]]; then
LIBRARY_EXTENSION=dylib
fi
go build -buildmode=c-shared -o libgnark_jni.$LIBRARY_EXTENSION gnark-jni.go
mkdir -p "$SCRIPTDIR/gnark/build/${OSARCH}/lib"
cp libgnark_jni.* "$SCRIPTDIR/gnark/build/${OSARCH}/lib"
}
build_blake2bf
build_secp256k1
build_altbn128
build_arithmetic
build_bls12_381
build_ipa_multipoint
build_secp256r1
build_gnark
build_jars
exit