-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ci): build noir artifacts in ci (#1251)
# Description closes: #1248 - Adds a build step before yarn project base that compiles the noir contracts using the nightly compiler version. - Adds an ephemeral layer to yarn project base to process the noir artifacts. ## Dependencies Uses the following build system pr in order to use multi stage builds of yarn project base. AztecProtocol/build-system#16 # Checklist: - [x] I have reviewed my diff in github, line by line. - [x] Every change is related to the PR description. - [x] I have [linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) this pull request to the issue(s) that it resolves. - [x] There are no unexpected formatting changes, superfluous debug logs, or commented-out code. - [ ] The branch has been merged or rebased against the head of its merge target. - [ ] I'm happy for the PR to be merged at the reviewer's next convenience. --------- Co-authored-by: ludamad <[email protected]>
- Loading branch information
Showing
49 changed files
with
265 additions
and
4,003 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
src/artifacts/* | ||
src/types/* | ||
Dockerfile.build | ||
Dockerfile.lint | ||
Dockerfile.types | ||
README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
artifacts/ | ||
target/ | ||
proofs/ | ||
types/ | ||
Prover.toml | ||
Verifier.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/yarn-project-base AS builder | ||
# Running on ubuntu until noir supports an alpine build | ||
|
||
# Builder stage to build the noir artifacts | ||
FROM ubuntu:kinetic | ||
|
||
RUN apt-get update && apt-get install -y \ | ||
curl \ | ||
git \ | ||
sed | ||
|
||
WORKDIR /usr/src/yarn-project | ||
COPY . . | ||
|
||
WORKDIR /usr/src/yarn-project/noir-contracts | ||
RUN yarn build && yarn formatting && yarn test | ||
WORKDIR /usr/src/yarn-project/noir-contracts | ||
|
||
# Prune dev dependencies. See comment in base image. | ||
RUN yarn cache clean | ||
RUN yarn workspaces focus --production > /dev/null | ||
# Download and extract nargo | ||
RUN ./scripts/install_noir.sh | ||
ENV PATH="/usr/src/yarn-project/noir-contracts/.nargo/bin:${PATH}" | ||
|
||
FROM node:18-alpine | ||
COPY --from=builder /usr/src/yarn-project/noir-contracts /usr/src/yarn-project/noir-contracts | ||
WORKDIR /usr/src/yarn-project/noir-contracts | ||
ENTRYPOINT ["yarn"] | ||
RUN ./scripts/compile_ci.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
# Install noir if it is not installed already | ||
if ! command -v nargo &> /dev/null | ||
then | ||
echo "Installing noir" | ||
./scripts/install_noir.sh | ||
fi | ||
|
||
|
||
# Use yarn script to compile and create types | ||
yarn | ||
yarn noir:build:all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/bin/bash | ||
|
||
# Compiles noir contracts in parallel, bubbling any compilation errors | ||
|
||
ROOT=$(pwd) | ||
|
||
# Error flag file | ||
error_file="/tmp/error.$$" | ||
# Array of child PIDs | ||
pids=() | ||
|
||
# Handler for SIGCHLD, cleanup if child exit with error | ||
handle_sigchld() { | ||
for pid in "${pids[@]}"; do | ||
# If process is no longer running | ||
if ! kill -0 "$pid" 2>/dev/null; then | ||
# Wait for the process and get exit status | ||
wait "$pid" | ||
status=$? | ||
|
||
# If exit status is error | ||
if [ $status -ne 0 ]; then | ||
# Create error file | ||
touch "$error_file" | ||
fi | ||
fi | ||
done | ||
} | ||
|
||
# Set SIGCHLD handler | ||
trap handle_sigchld SIGCHLD # Trap any ERR signal and call the custom error handler | ||
|
||
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. | ||
nargo compile main --contracts; | ||
} | ||
|
||
process() { | ||
CONTRACT_NAME=$1 | ||
|
||
cd $ROOT | ||
echo "Copying output for $CONTRACT_NAME" | ||
NODE_OPTIONS=--no-warnings yarn ts-node --esm src/scripts/copy_output.ts $CONTRACT_NAME | ||
} | ||
|
||
echo "Using $(nargo --version)" | ||
|
||
# Build contracts | ||
for CONTRACT_NAME in "$@"; do | ||
build $CONTRACT_NAME & | ||
pids+=($!) | ||
done | ||
|
||
# Wait for all background processes to finish | ||
wait | ||
|
||
# If error file exists, exit with error | ||
if [ -f "$error_file" ]; then | ||
rm "$error_file" | ||
echo "Error occurred in one or more child processes. Exiting..." | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
# Runs the compile scripts for all contracts. | ||
|
||
./scripts/compile.sh $(./scripts/get_all_contracts.sh) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
# Utility to get the names of all contracts | ||
echo $(ls -d src/contracts/*_contract/Nargo.toml | sed -r "s/src\\/contracts\\/(.+)_contract\\/Nargo.toml/\\1/") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
# Script to install noirup and the latest nargo | ||
set -eu | ||
|
||
VERSION="nightly" | ||
|
||
export NARGO_HOME="$(pwd)/.nargo" | ||
NARGO_BIN_DIR="$NARGO_HOME/bin" | ||
BIN_URL="https://raw.githubusercontent.com/noir-lang/noirup/master/noirup" | ||
BIN_PATH="$NARGO_BIN_DIR/noirup" | ||
NARGO_MAN_DIR="$NARGO_HOME/share/man/man1" | ||
|
||
# Clean | ||
rm -rf $NARGO_HOME | ||
|
||
# Install noirup. | ||
mkdir -p $NARGO_BIN_DIR | ||
mkdir -p $NARGO_MAN_DIR | ||
|
||
curl -# -L $BIN_URL -o $BIN_PATH | ||
chmod +x $BIN_PATH | ||
export PATH=$NARGO_BIN_DIR:$PATH | ||
|
||
# Install nargo | ||
noirup -v $VERSION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
|
||
#!/bin/bash | ||
|
||
# Example: | ||
# - this script will automatically be run when running `yarn noir:build` | ||
# - it exists on its own to allow ci to compile and format in different contexts, as the noir compiler is not available in yarn project base ( by choice ) | ||
# - you can run `yarn noir:types:all` to create all noir artifacts and types consumed by aztec packages. | ||
|
||
# Enable strict mode: | ||
# Exit on error (set -e), treat unset variables as an error (set -u), | ||
set -eu; | ||
|
||
artifacts_dir="src/artifacts" | ||
types_dir="src/types" | ||
|
||
# Create output directories | ||
mkdir -p $types_dir | ||
mkdir -p $artifacts_dir | ||
|
||
|
||
ROOT=$(pwd) | ||
|
||
write_import() { | ||
CONTRACT_NAME=$1 | ||
NAME=`echo $CONTRACT_NAME | sed -r 's/(^|_)(.)/\U\2/g'` | ||
echo "import ${NAME}Json from './${CONTRACT_NAME}_contract.json' assert { type: 'json' };" >> "$artifacts_dir/index.ts"; | ||
} | ||
|
||
write_export() { | ||
CONTRACT_NAME=$1 | ||
NAME=`echo $CONTRACT_NAME | sed -r 's/(^|_)(.)/\U\2/g'` | ||
|
||
# artifacts | ||
echo "export const ${NAME}ContractAbi = ${NAME}Json as ContractAbi;" >> "$artifacts_dir/index.ts"; | ||
echo "Written typescript for $NAME" | ||
|
||
# types | ||
echo "export * from './${CONTRACT_NAME}.js';" >> "$types_dir/index.ts"; | ||
} | ||
|
||
|
||
process() { | ||
CONTRACT=$1 | ||
|
||
cd $ROOT | ||
echo "Creating types for $CONTRACT" | ||
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 ../aztec.js/src/abis/*.json ./$types_dir/*.ts | ||
echo -e "Done\n" | ||
} | ||
|
||
# Make type files | ||
for CONTRACT_NAME in "$@"; do | ||
process $CONTRACT_NAME & | ||
done | ||
|
||
# Wait for all background processes to finish | ||
wait | ||
|
||
# Write the index ts stuff | ||
# Remove the output file | ||
rm $artifacts_dir/index.ts || true | ||
|
||
# Generate artifacts package index.ts | ||
echo "// Auto generated module\n" > "$artifacts_dir/index.ts"; | ||
echo "import { ContractAbi } from '@aztec/foundation/abi';" >> "$artifacts_dir/index.ts"; | ||
|
||
# Generate types package index.ts | ||
echo "// Auto generated module\n" > "$types_dir/index.ts"; | ||
for CONTRACT_NAME in "$@"; do | ||
write_import $CONTRACT_NAME | ||
write_export $CONTRACT_NAME | ||
done | ||
|
||
# only run the rest when the full flag is set | ||
format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
# Run the types script for all files | ||
./scripts/types.sh $(./scripts/get_all_contracts.sh) |
Oops, something went wrong.