-
Notifications
You must be signed in to change notification settings - Fork 105
/
build.sh
executable file
·152 lines (140 loc) · 5.26 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
#!/bin/bash
MSM_DEFINED=ON
NTT_DEFINED=ON
G2_DEFINED=ON
ECNTT_DEFINED=ON
EXT_FIELD=ON
HASH=ON
POSEIDON=ON
CUDA_COMPILER_PATH=/usr/local/cuda/bin/nvcc
DEVMODE=OFF
BUILD_CURVES=( )
BUILD_FIELDS=( )
SUPPORTED_CURVES=("bn254" "bls12_377" "bls12_381" "bw6_761", "grumpkin")
SUPPORTED_FIELDS=("babybear")
CUDA_BACKEND=OFF
BUILD_DIR="${ICICLE_BUILD_DIR:-$(realpath "$PWD/../../icicle/build")}"
if [[ $1 == "-help" ]]; then
echo "Build script for building ICICLE cpp libraries"
echo ""
echo "If more than one curve or more than one field is supplied, the last one supplied will be built"
echo ""
echo "USAGE: ./build.sh [OPTION...]"
echo ""
echo "OPTIONS:"
echo " -curve=<curve_name> Specifies the curve to be built. If \"all\" is supplied,"
echo " all curves will be built with any additional curve options."
echo ""
echo " -skip_msm Builds the curve library with MSM (multi-scalar multiplication) disabled."
echo ""
echo " -skip_ntt Builds the curve/field library with NTT (number theoretic transform) disabled."
echo ""
echo " -skip_g2 Builds the curve library with G2 (a secondary group) disabled."
echo ""
echo " -skip_ecntt Builds the curve library with ECNTT (elliptic curve NTT) disabled."
echo ""
echo " -skip_poseidon Builds the curve or field library with poseidon hashing disabled."
echo ""
echo " -skip_hash Builds the library with Hashes (Keccak, Sha3, etc) disabled."
echo ""
echo " -field=<field_name> Specifies the field to be built. If \"all\" is supplied,"
echo " all fields will be built with any additional field options."
echo ""
echo " -skip_fieldext Builds the field library with the extension field disabled."
echo ""
echo " -cuda_backend=<option> Specifies the branch/commit to pull for CUDA backend, or \"local\" if it's"
echo " located under icicle/backend/cuda."
echo " Default: \"OFF\""
echo ""
echo " -cuda_version=<version> Specifies the version of CUDA to use for compilation."
echo ""
exit 0
fi
for arg in "$@"
do
arg_lower=$(echo "$arg" | tr '[:upper:]' '[:lower:]')
case "$arg_lower" in
-cuda_version=*)
cuda_version=$(echo "$arg" | cut -d'=' -f2)
CUDA_COMPILER_PATH=/usr/local/cuda-$cuda_version/bin/nvcc
;;
-cuda_backend=*)
CUDA_BACKEND=$(echo "$arg_lower" | cut -d'=' -f2)
;;
-skip_msm)
MSM_DEFINED=OFF
;;
-skip_ntt)
NTT_DEFINED=OFF
;;
-skip_ecntt)
ECNTT_DEFINED=OFF
;;
-skip_g2)
G2_DEFINED=OFF
;;
-skip_hash)
HASH=OFF
;;
-skip_poseidon)
POSEIDON=OFF
;;
-curve=*)
curve=$(echo "$arg_lower" | cut -d'=' -f2)
if [[ $curve == "all" ]]
then
BUILD_CURVES=("${SUPPORTED_CURVES[@]}")
else
BUILD_CURVES=( $curve )
fi
;;
-field=*)
field=$(echo "$arg_lower" | cut -d'=' -f2)
if [[ $field == "all" ]]
then
BUILD_FIELDS=("${SUPPORTED_FIELDS[@]}")
else
BUILD_FIELDS=( $field )
fi
;;
-skip_fieldext)
EXT_FIELD=OFF
;;
*)
echo "Unknown argument: $arg"
exit 1
;;
esac
done
cd ../../icicle
mkdir -p build
rm -f "$BUILD_DIR/CMakeCache.txt"
for CURVE in "${BUILD_CURVES[@]}"
do
echo "CURVE=${CURVE}" > build_config.txt
echo "MSM=${MSM_DEFINED}" >> build_config.txt
echo "NTT=${NTT_DEFINED}" >> build_config.txt
echo "ECNTT=${ECNTT_DEFINED}" >> build_config.txt
echo "G2=${G2_DEFINED}" >> build_config.txt
echo "DEVMODE=${DEVMODE}" >> build_config.txt
cmake -DCMAKE_CUDA_COMPILER=$CUDA_COMPILER_PATH -DCUDA_BACKEND=$CUDA_BACKEND -DCURVE=$CURVE -DMSM=$MSM_DEFINED -DNTT=$NTT_DEFINED -DG2=$G2_DEFINED -DECNTT=$ECNTT_DEFINED -DPOSEIDON=$POSEIDON -DHASH=$POSEIDON -DCMAKE_BUILD_TYPE=Release -S . -B build
cmake --build build --target install -j8 && rm build_config.txt
rm -f "$BUILD_DIR/CMakeCache.txt"
done
# Needs to remove the CMakeCache.txt file to allow building fields after curves
# have been built since CURVE and FIELD cannot both be defined
rm -f "$BUILD_DIR/CMakeCache.txt"
for FIELD in "${BUILD_FIELDS[@]}"
do
echo "FIELD=${FIELD}" > build_config.txt
echo "NTT=${NTT_DEFINED}" >> build_config.txt
echo "DEVMODE=${DEVMODE}" >> build_config.txt
echo "EXT_FIELD=${EXT_FIELD}" >> build_config.txt
cmake -DCMAKE_CUDA_COMPILER=$CUDA_COMPILER_PATH -DCUDA_BACKEND=$CUDA_BACKEND -DFIELD=$FIELD -DNTT=$NTT_DEFINED -DEXT_FIELD=$EXT_FIELD -DPOSEIDON=$POSEIDON -DHASH=$POSEIDON -DCMAKE_BUILD_TYPE=Release -S . -B build
cmake --build build --target install -j8 && rm build_config.txt
done
if [[ $HASH == "ON" ]]; then
echo "DEVMODE=${DEVMODE}" >> build_config.txt
cmake -DCMAKE_CUDA_COMPILER=$CUDA_COMPILER_PATH -DCUDA_BACKEND=$CUDA_BACKEND -DHASH=$HASH -DCMAKE_BUILD_TYPE=Release -S . -B build
cmake --build build --target install -j8 && rm build_config.txt
fi