|
1 | 1 | #!/usr/bin/env bash |
2 | | -# This is a wrapper script for nargo. |
3 | | -# Pass any args that you'd normally pass to nargo. |
4 | | -# If the first arg is "compile", |
5 | | -# run nargo and then postprocess any created artifacts. |
| 2 | +# This script performs postprocessing on compiled Noir contracts. |
| 3 | +# It expects to find compiled artifacts and transforms them via |
| 4 | +# transpilation and verification key generation. |
6 | 5 | # |
7 | | -# Usage: compile_then_postprocess.sh [nargo args] |
| 6 | +# Usage: compile-contract [artifact_path ...] |
| 7 | +# If no paths provided, searches for artifacts in target/ directories |
8 | 8 | set -euo pipefail |
9 | 9 |
|
10 | 10 | dir=$(dirname $0) |
11 | | -NARGO=${NARGO:-"$dir/../noir/noir-repo/target/release/nargo"} |
12 | 11 | TRANSPILER=${TRANSPILER:-"$dir/../avm-transpiler/target/release/avm-transpiler"} |
13 | 12 | BB=${BB:-"$dir/../barretenberg/cpp/build/bin/bb"} |
14 | 13 |
|
15 | | - |
16 | | -if [ "${1:-}" != "compile" ]; then |
17 | | - # if not compiling, just pass through to nargo verbatim |
18 | | - $NARGO $@ |
19 | | - exit $? |
20 | | -fi |
21 | | -shift # remove the compile arg so we can inject --show-artifact-paths |
22 | | - |
23 | 14 | # bb --version returns 00000000.00000000.00000000, so we compute |
24 | 15 | # the binary hash to ensure we invalidate vk cache artifacts when bb changes |
25 | 16 | bb_hash=$(sha256sum "$BB" | cut -d' ' -f1) |
26 | 17 |
|
27 | | -# Forward all arguments to nargo, tee output to console. |
28 | | -# Nargo should be outputting errors to stderr, but it doesn't. Use tee to duplicate stdout to stderr to display errors. |
29 | | -artifacts_to_process=$($NARGO compile --pedantic-solving --inliner-aggressiveness 0 --show-artifact-paths $@ | tee >(cat >&2) | grep -oP 'Saved contract artifact to: \K.*') |
| 18 | +# If artifact paths are provided as arguments, use those |
| 19 | +# Otherwise, search for contract artifacts in target directories |
| 20 | +if [ $# -gt 0 ]; then |
| 21 | + artifacts_to_process="$@" |
| 22 | +else |
| 23 | + # Find all contract artifacts in target directories |
| 24 | + artifacts_to_process=$(find . -name "*.json" -path "*/target/*" | grep -v "/cache/" | grep -v ".function_artifact_" || true) |
| 25 | + |
| 26 | + if [ -z "$artifacts_to_process" ]; then |
| 27 | + echo "No contract artifacts found. Please compile your contracts first with 'nargo compile'." |
| 28 | + exit 1 |
| 29 | + fi |
| 30 | +fi |
30 | 31 |
|
31 | 32 | # Postprocess each artifact |
32 | 33 | # `$artifacts_to_process` needs to be unquoted here, otherwise it will break if there are multiple artifacts |
@@ -82,3 +83,5 @@ for artifact in $artifacts_to_process; do |
82 | 83 | mv "$artifact.tmp" "$artifact" |
83 | 84 | done |
84 | 85 | done |
| 86 | + |
| 87 | +echo "Contract postprocessing complete!" |
0 commit comments