Skip to content

Commit

Permalink
feat: parallelize noir compilation (#1197)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maddiaa0 authored Jul 26, 2023
1 parent abd5f3a commit fd3a204
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions yarn-project/noir-contracts/src/scripts/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,32 @@ usage() {
exit 1
}

build() {
CONTRACT_NAME=$1
CONTRACT_FOLDER="${CONTRACT_NAME}_contract"
echo "Compiling $CONTRACT_NAME..."
cd src/contracts/$CONTRACT_FOLDER
rm -f target/*

# If VERBOSE is not set, compile with 'nargo' and redirect standard error (stderr) to /dev/null and standard output (stdout) to /dev/null.
# If the compilation fails, rerun the compilation with 'nargo' and show the compiler output.
if [[ -z "${VERBOSE:-}" ]]; then
"$NARGO_COMMAND" compile main --contracts 2> /dev/null > /dev/null || (echo "Error compiling contract. Re-running as verbose to show compiler output:"; "$NARGO_COMMAND" compile main --contracts);
else
"$NARGO_COMMAND" compile main --contracts
fi

cd $ROOT
echo "Copying output for $CONTRACT_NAME"
NODE_OPTIONS=--no-warnings yarn ts-node --esm src/scripts/copy_output.ts $CONTRACT_NAME
}

format(){
echo "Formatting contract folders"
yarn run -T prettier -w ./src/artifacts/*.json ../aztec.js/src/abis/*.json ./src/types/*.ts
echo -e "Done\n"
}

# Parse command-line arguments
for arg in "$@"; do
case $arg in
Expand Down Expand Up @@ -58,29 +84,13 @@ echo "Using $($NARGO_COMMAND --version)"

# Build contracts
for CONTRACT_NAME in "$@"; do
CONTRACT_FOLDER="${CONTRACT_NAME}_contract"
echo "Compiling $CONTRACT_NAME..."
cd src/contracts/$CONTRACT_FOLDER
rm -f target/*

# If VERBOSE is not set, compile with 'nargo' and redirect standard error (stderr) to /dev/null and standard output (stdout) to /dev/null.
# If the compilation fails, rerun the compilation with 'nargo' and show the compiler output.
if [[ -z "${VERBOSE:-}" ]]; then
"$NARGO_COMMAND" compile main --contracts 2> /dev/null > /dev/null || (echo "Error compiling contract. Re-running as verbose to show compiler output:"; "$NARGO_COMMAND" compile main --contracts);
else
"$NARGO_COMMAND" compile main --contracts
fi

cd $ROOT
echo "Copying output for $CONTRACT_NAME"
NODE_OPTIONS=--no-warnings yarn ts-node --esm src/scripts/copy_output.ts $CONTRACT_NAME

echo "Formatting contract folders"
yarn run -T prettier -w ./src/artifacts/$CONTRACT_FOLDER.json ../aztec.js/src/abis/*.json ./src/types/*.ts
echo -e "Done\n"

build $CONTRACT_NAME &
done

# Format contracts once all background processes have finished
wait
format

# Check for stale artifacts
for json_path in src/artifacts/*.json; do
json_file="$(basename "$json_path")";
Expand Down

0 comments on commit fd3a204

Please sign in to comment.