From ea072b6de8af914efd72d1c3cb41dcadafb155a2 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Thu, 28 Mar 2024 21:14:01 +0000 Subject: [PATCH] chore: build contracts and protocol circuits sequentially if not enough ram (#5499) #5426 but for building noir projects. --- noir-projects/bootstrap.sh | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/noir-projects/bootstrap.sh b/noir-projects/bootstrap.sh index fc265ec76cc..c27610cb8ef 100755 --- a/noir-projects/bootstrap.sh +++ b/noir-projects/bootstrap.sh @@ -22,9 +22,33 @@ g="\033[32m" # Green b="\033[34m" # Blue r="\033[0m" # Reset -((cd "./noir-contracts" && ./bootstrap.sh) > >(awk -v g="$g" -v r="$r" '{print g "contracts: " r $0}')) & -((cd "./noir-protocol-circuits" && ./bootstrap.sh) > >(awk -v b="$b" -v r="$r" '{print b "protocol-circuits: " r $0}')) & +AVAILABLE_MEMORY=0 + +case "$(uname)" in + Linux*) + # Check available memory on Linux + AVAILABLE_MEMORY=$(awk '/MemFree/ { printf $2 }' /proc/meminfo) + ;; + *) + echo "Parallel builds not supported on this operating system" + ;; +esac +# This value may be too low. +# If builds fail with an amount of free memory greater than this value then it should be increased. +MIN_PARALLEL_BUILD_MEMORY=32000000 + +if [[ AVAILABLE_MEMORY -lt MIN_PARALLEL_BUILD_MEMORY ]]; then + echo "System does not have enough memory for parallel builds, falling back to sequential" + ./noir-contracts/bootstrap.sh + ./noir-protocol-circuits/bootstrap.sh +else + ((./noir-contracts/bootstrap.sh) > >(awk -v g="$g" -v r="$r" '{print g "contracts: " r $0}')) & + ((./noir-protocol-circuits/bootstrap.sh) > >(awk -v b="$b" -v r="$r" '{print b "protocol-circuits: " r $0}')) & + + for job in $(jobs -p); do + wait $job || exit 1 + done +fi + + -for job in $(jobs -p); do - wait $job || exit 1 -done