forked from hyperledger/besu-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·156 lines (120 loc) · 3.88 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
#!/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)
fi
if [[ "$OSTYPE" == "darwin"* ]]; then
export CFLAGS="-arch x86_64 -arch arm64"
CORE_COUNT=$(sysctl -n hw.ncpu)
fi
# add to path cargo
[ -f $HOME/.cargo/env ] && . $HOME/.cargo/env
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" $SECP256K1_BUILD_OPTS && \
make -j $CORE_COUNT && \
make -j $CORE_COUNT install
}
build_altbn128() {
cat <<EOF
############################
###### build altbn128 ######
############################
EOF
cd "$SCRIPTDIR/altbn128/sputnikvm_altbn128"
# delete old build dir, if exists
rm -rf "$SCRIPTDIR/altbn128/build" || true
mkdir -p "$SCRIPTDIR/altbn128/build/lib"
cargo clean
if [[ "$OSTYPE" == "darwin"* ]]; then
lipo_lib "libeth_altbn128" ""
else
cargo build --lib --release
fi
cp target/release/libeth_altbn128.* "$SCRIPTDIR/altbn128/build/lib"
}
build_bls12_381() {
cat <<EOF
#############################
###### build BLS12-381 ######
#############################
EOF
cd "$SCRIPTDIR/bls12-381/matterlabs-eip1962"
# delete old build dir, if exists
rm -rf "$SCRIPTDIR/bls12-381/build" || true
mkdir -p "$SCRIPTDIR/bls12-381/build/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
cp target/release/libeth_pairings.* "$SCRIPTDIR/bls12-381/build/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_secp256k1
build_altbn128
build_bls12_381
build_jars
exit