github.com/onflow/flow-go/crypto@v0.24.8/relic_build.sh (about) 1 #!/bin/bash 2 3 set -euo pipefail 4 5 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 6 7 pushd "$DIR" 8 9 # Ensure the directory is writeable 10 chmod -R +w "$(pwd)" 11 12 mkdir -p "$DIR/relic/build" 13 pushd "$DIR/relic/build" 14 15 16 # make cmake print its CC interpretation 17 CMAKE_FILE="${DIR}/relic/CMakeLists.txt" 18 # parameter expansion is not suitable here 19 # shellcheck disable=SC2089 20 CMAKE_PRINT_CC="message ( STATUS \"CC=\$ENV{CC}\" )" 21 # Make the cmake run print its interpretation of CC 22 echo "$CMAKE_PRINT_CC" >> "${CMAKE_FILE}" 23 24 # Probe cmake's MakeFile generation and extract the CC version 25 CMAKE_TEMP=$(mktemp) 26 cmake .. > "$CMAKE_TEMP" 27 CC_VAL="$(tail -n 5 "$CMAKE_TEMP" | grep -oE -m 1 'CC=.*$')" 28 CC_VAL="${CC_VAL:3}" 29 30 # de-mangle the CMakeLists file, using a temporary file for BSD compatibility 31 sed '$d' ../CMakeLists.txt > "$CMAKE_TEMP" 32 mv "$CMAKE_TEMP" ../CMakeLists.txt 33 34 # default to which 35 CC_VAL=${CC_VAL:-"$(which cc)"} 36 CC_VERSION_STR="$($CC_VAL --version)" 37 38 # we use uname to record which arch we are running on 39 ARCH=$(uname -m 2>/dev/null || true) 40 41 if [[ "$ARCH" =~ "x86_64" ]]; then 42 # Compile as westmere arch to avoid cross-compilation issues on machines not supporting AVX extensions. 43 # Relic performance as used in flow crypto library is not impacted by whether it is compiled with "native" or "westmere", as proven by benchmark results. 44 MARCH="-march=westmere" 45 elif [[ "$ARCH" =~ ^(arm64|armv7|armv7s)$ && "${CC_VERSION_STR[0]}" =~ (clang) ]]; then 46 # the "-march=native" option is not supported with clang on ARM 47 MARCH="" 48 else 49 MARCH="-march=native" 50 fi 51 52 # Set RELIC config for Flow 53 COMP=(-DCFLAGS="-O3 -funroll-loops -fomit-frame-pointer ${MARCH} -mtune=native") 54 GENERAL=(-DTIMER=CYCLE -DCHECK=OFF -DVERBS=OFF) 55 LIBS=(-DSHLIB=OFF -DSTLIB=ON) 56 RAND=(-DRAND=HASHD -DSEED=) 57 58 # 59 BN_REP=(-DALLOC=AUTO -DALIGN=1 -DWSIZE=64 -DBN_PRECI=1024 -DBN_MAGNI=DOUBLE) 60 ARITH=(-DARITH=EASY) 61 PRIME=(-DFP_PRIME=381) 62 63 # 64 BN_METH=(-DBN_KARAT=0 -DBN_METHD="COMBA;COMBA;MONTY;SLIDE;BINAR;BASIC") 65 FP_METH=(-DFP_KARAT=0 -DFP_METHD="INTEG;INTEG;INTEG;MONTY;MONTY;JMPDS;SLIDE") 66 PRIMES=(-DFP_PMERS=OFF -DFP_QNRES=ON) 67 FPX_METH=(-DFPX_METHD="INTEG;INTEG;LAZYR") 68 EP_METH=(-DEP_MIXED=ON -DEP_PLAIN=OFF -DEP_ENDOM=ON -DEP_SUPER=OFF\ 69 -DEP_CTMAP=ON -DEP_METHD="JACOB;LWNAF;COMBS;INTER") 70 PP_METH=(-DPP_METHD="LAZYR;OATEP") 71 72 # run cmake 73 cmake "${COMP[@]}" "${GENERAL[@]}" \ 74 "${LIBS[@]}" "${RAND[@]}" \ 75 "${BN_REP[@]}" "${ARITH[@]}" \ 76 "${PRIME[@]}" "${PRIMES[@]}" \ 77 "${EP_METH[@]}" \ 78 "${BN_METH[@]}" \ 79 "${FP_METH[@]}" \ 80 "${FPX_METH[@]}" \ 81 "${PP_METH[@]}" .. 82 83 84 # Compile the static library 85 make clean 86 make relic_s -j8 87 rm -f CMakeCache.txt 88 89 popd 90 popd