Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into lw/remove_circuits_…
Browse files Browse the repository at this point in the history
…wasm
  • Loading branch information
LeilaWang committed Nov 27, 2023
2 parents f32e464 + 63173c4 commit 0293f19
Show file tree
Hide file tree
Showing 278 changed files with 13,651 additions and 657 deletions.
15 changes: 14 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ jobs:
name: "Create ECR manifest"
command: create_ecr_manifest noir x86_64,arm64

noir-packages:
docker:
- image: aztecprotocol/alpine-build-image
resource_class: small
steps:
- *checkout
- *setup_env
- run:
name: "Build"
command: cond_spot_run_build noir-packages 32

# Barretenberg
barretenberg-wasm-linux-clang:
docker:
Expand Down Expand Up @@ -980,6 +991,7 @@ workflows:
- noir-x86_64
- noir-arm64
<<: *defaults
- noir-packages: *defaults

# Barretenberg
- barretenberg-x86_64-linux-gcc: *defaults
Expand Down Expand Up @@ -1021,6 +1033,8 @@ workflows:
requires:
- l1-contracts
- bb-js
- noir-ecr-manifest
- noir-packages
<<: *defaults
- yarn-project:
requires:
Expand Down Expand Up @@ -1099,7 +1113,6 @@ workflows:
- end:
requires:
- mainnet-fork
- noir-ecr-manifest
- e2e-2-pxes
- e2e-deploy-contract
- e2e-lending-contract
Expand Down
5 changes: 2 additions & 3 deletions barretenberg/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/bin/bash
set -eu

# Navigate to script folder
cd "$(dirname "$0")"

(cd cpp && ./bootstrap.sh)
(cd ts && yarn install --immutable && yarn build && npm link)
(cd cpp && ./bootstrap.sh $@)
(cd ts && ./bootstrap.sh $@)
37 changes: 24 additions & 13 deletions barretenberg/cpp/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,32 @@ set -eu
# Navigate to script folder
cd "$(dirname "$0")"

# Clean.
rm -rf ./build
rm -rf ./build-wasm
CMD=${1:-}

if [ -n "$CMD" ]; then
if [ "$CMD" = "clean" ]; then
git clean -ffdx
exit 0
else
echo "Unknown command: $CMD"
exit 1
fi
fi

# Determine system.
if [[ "$OSTYPE" == "darwin"* ]]; then
OS=macos
elif [[ "$OSTYPE" == "linux-gnu" ]]; then
OS=linux
elif [[ "$OSTYPE" == "linux-musl" ]]; then
OS=linux
else
echo "Unknown OS: $OSTYPE"
exit 1
fi

# Download ignition transcripts.
(cd ./srs_db && ./download_ignition.sh 3)
(cd ./srs_db && ./download_ignition.sh 0)

# Pick native toolchain file.
ARCH=$(uname -m)
Expand All @@ -33,22 +43,23 @@ else
fi
fi

# Remove cmake cache files.
rm -f {build,build-wasm,build-wasm-threads}/CMakeCache.txt

echo "#################################"
echo "# Building with preset: $PRESET"
echo "# When running cmake directly, remember to use: --build --preset $PRESET"
echo "#################################"

# Build native.
cmake --preset $PRESET -DCMAKE_BUILD_TYPE=RelWithAssert
cmake --build --preset $PRESET ${@/#/--target }

cd ./build
# The Grumpkin SRS is generated manually at the moment, only up to a large enough size for tests
# If tests require more points, the parameter can be increased here.
cmake --build . --parallel --target grumpkin_srs_gen
./bin/grumpkin_srs_gen 8192
echo "Generated Grumpkin SRS successfully"
cd ../
cmake --build --preset $PRESET --target bb

if [ ! -d ./srs_db/grumpkin ]; then
# The Grumpkin SRS is generated manually at the moment, only up to a large enough size for tests
# If tests require more points, the parameter can be increased here.
(cd ./build && cmake --build . --parallel --target grumpkin_srs_gen && ./bin/grumpkin_srs_gen 8192)
fi

# Install wasi-sdk.
./scripts/install-wasi-sdk.sh
Expand Down
13 changes: 9 additions & 4 deletions barretenberg/cpp/scripts/install-wasi-sdk.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/bin/bash
set -eu

if [[ -d ./src/wasi-sdk-20.0 && -d ./src/wasi-sdk-20.0+threads ]]; then
echo "WASI already installed. Skipping."
exit 0
fi

# Clean.
rm -rf ./src/wasi-sdk-*

Expand All @@ -17,15 +22,15 @@ fi
# Install the webassembly toolchain.
mkdir -p src
cd ./src
curl -s -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-$OS.tar.gz | tar zxfv -
curl -s -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-$OS.tar.gz | tar zxf -
if [ "$OS" == "linux" ]; then
# Exceptional linux case that provides an llvm build that works on Ubuntu 20.
curl -s -L https://wasi-sdk.s3.eu-west-2.amazonaws.com/yamt-wasi-sdk-20.0.threads.tgz | tar zxfv -
curl -s -L https://wasi-sdk.s3.eu-west-2.amazonaws.com/yamt-wasi-sdk-20.0.threads.tgz | tar zxf -
else
# For other operating systems, first download the standard release (this is to get the llvm build).
curl -s -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20%2Bthreads/wasi-sdk-20.0.threads-$OS.tar.gz | tar zxfv -
curl -s -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20%2Bthreads/wasi-sdk-20.0.threads-$OS.tar.gz | tar zxf -
# Replace wasi-sysroot in wasi-sdk-20.0+threads with our custom build.
# It contains libc++ and a patch by yamt to improve thread join stability.
# Can remove once future releases are more stable.
curl -s -L https://wasi-sdk.s3.eu-west-2.amazonaws.com/yamt-wasi-sysroot-20.0.threads.tgz | tar zxfv -
curl -s -L https://wasi-sdk.s3.eu-west-2.amazonaws.com/yamt-wasi-sysroot-20.0.threads.tgz | tar zxf -
fi
4 changes: 0 additions & 4 deletions barretenberg/cpp/yarn.lock

This file was deleted.

22 changes: 22 additions & 0 deletions barretenberg/ts/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
set -eu

cd "$(dirname "$0")"

CMD=${1:-}

if [ -n "$CMD" ]; then
if [ "$CMD" = "clean" ]; then
git clean -fdx
exit 0
else
echo "Unknown command: $CMD"
exit 1
fi
fi

yarn install --immutable
yarn build

# Make bin globally available.
npm link
4 changes: 1 addition & 3 deletions barretenberg/ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
"default": "./dest/node/index.js"
}
},
"bin": {
"bb.js": "./dest/node/main.js"
},
"bin": "./dest/node/main.js",
"files": [
"src/",
"dest/",
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/ts/scripts/cjs_postprocess.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ DIR="./dest/node-cjs"
# Iterate over all .js files in the directory
for FILE in $(find "$DIR" -name "*.js"); do
# Use sed to replace 'import.meta.url' with '""'
sed -i 's/import\.meta\.url/""/g' "$FILE"
sed -i.bak 's/import\.meta\.url/""/g' "$FILE" && rm "$FILE.bak"
done
61 changes: 28 additions & 33 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@
# ./bootstrap.sh clean
set -eu

export CMD=${1:-}

cd "$(dirname "$0")"

# Bump this number to force a full bootstrap.
VERSION=1
CMD=${1:-}

# Remove all untracked files and directories.
if [ -n "$CMD" ]; then
if [ "$CMD" = "clean" ]; then
echo "WARNING: This will erase *all* untracked files, including hooks and submodules."
Expand All @@ -24,50 +20,49 @@ if [ -n "$CMD" ]; then
if [ "$user_input" != "y" ] && [ "$user_input" != "Y" ]; then
exit 1
fi
rm -f .bootstrapped

# Remove hooks and submodules.
rm -rf .git/hooks/*
rm -rf .git/modules/*
git clean -fd
for SUBMODULE in $(git config --file .gitmodules --get-regexp path | awk '{print $2}'); do
rm -rf $SUBMODULE
done

# Remove all untracked files, directories, nested repos, and .gitignore files.
git clean -ffdx

exit 0
else
echo "Unknown command: $CLEAN"
echo "Unknown command: $CMD"
exit 1
fi
fi

if [ ! -f ~/.nvm/nvm.sh ]; then
echo "Nvm not found at ~/.nvm"
exit 1
fi
# if [ ! -f ~/.nvm/nvm.sh ]; then
# echo "Nvm not found at ~/.nvm"
# exit 1
# fi

# Install pre-commit git hooks.
HOOKS_DIR=$(git rev-parse --git-path hooks)
echo "(cd barretenberg/cpp && ./format.sh staged)" > $HOOKS_DIR/pre-commit
# TODO: Call cci_gen to ensure .circleci/config.yml is up-to-date!
chmod +x $HOOKS_DIR/pre-commit

git submodule update --init --recursive

# Lightweight bootstrap. Run `./bootstrap.sh clean` to bypass.
# TODO: We shouldn't do this here. We should call each projects bootstrap script and it should decide between light/heavy.
if [[ -f .bootstrapped && $(cat .bootstrapped) -eq "$VERSION" ]]; then
echo -e '\033[1mRebuild L1 contracts...\033[0m'
(cd l1-contracts && .foundry/bin/forge build)
PROJECTS=(
barretenberg
noir
l1-contracts
yarn-project
)

echo -e '\n\033[1mUpdate npm deps...\033[0m'
(cd yarn-project && yarn install)

echo -e '\n\033[1mRebuild Noir contracts...\033[0m'
(cd yarn-project/noir-contracts && yarn noir:build:all 2> /dev/null)

echo -e '\n\033[1mRebuild barretenberg wasm...\033[0m'
(cd barretenberg/cpp && cmake --build --preset default && cmake --build --preset wasm && cmake --build --preset wasm-threads)
else
# Heavy bootstrap.
barretenberg/bootstrap.sh
yarn-project/bootstrap.sh

echo $VERSION > .bootstrapped
fi
for P in "${PROJECTS[@]}"; do
echo "**************************************"
echo -e "\033[1mBootstrapping $P...\033[0m"
echo "**************************************"
echo
$P/bootstrap.sh
echo
echo
done
25 changes: 25 additions & 0 deletions bootstrap/Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# At present this doesn't work, as we don't have an alpine wasm toolchain we can use (or it's not directly obvious).
# Keeping this around though, as it would be nice to resolve this in the future.
FROM alpine:latest
RUN apk update && apk add --no-cache \
build-base \
curl \
git \
cmake \
lsb-release \
wget \
gnupg \
ninja \
npm \
pkgconf \
openssl-dev \
jq \
llvm \
clang \
rust \
cargo \
bash
RUN npm install -g yarn
WORKDIR /usr/src
COPY . .
RUN ./bootstrap.sh
23 changes: 23 additions & 0 deletions bootstrap/Dockerfile.lunar
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM ubuntu:lunar
ENV DEBIAN_FRONTEND=noninteractive
RUN apt update && apt install -y \
build-essential \
curl \
git \
cmake \
lsb-release \
wget \
software-properties-common \
gnupg \
ninja-build \
npm \
pkg-config \
libssl-dev \
jq
RUN wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && ./llvm.sh 16
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
RUN npm install -g yarn
WORKDIR /usr/src
COPY . .
RUN ./bootstrap.sh
31 changes: 31 additions & 0 deletions bootstrap/bootstrap_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
# This script takes the state of your current repository, and clones it inside of a docker container.
# You likely don't have a fresh clone, and it's paramount that to test bootstrapping, we don't have any
# intermediate build state in the context.
# To achieve this we mount your working directory into the container, and then perform the clone into the container.
# After cloning the repo we build the relevant dockerfile to bootstrap.
# "docker-in-docker" is achieved by mounting the host systems docker socket into the container.

DOCKERFILE=${1:-Dockerfile.lunar}

docker build -t bootstrap-build - <<EOF
FROM ubuntu:latest
RUN apt update && apt install -y git rsync docker.io
EOF

docker run -ti --rm -v/run/user/$UID/docker.sock:/var/run/docker.sock -v$(git rev-parse --show-toplevel):/repo:ro bootstrap-build /bin/bash -c "
# Checkout head.
mkdir /project && cd /project
git init
git remote add origin /repo
git fetch --depth 1 origin HEAD
git checkout FETCH_HEAD
# Copy untracked and modified files, and remove deleted files, from our current repo.
cd /repo
{ git ls-files --others --exclude-standard ; git diff --name-only --diff-filter=TMAR HEAD ; } | rsync -a --files-from=- . /project
for F in \$(git ls-files --deleted); do rm /project/\$F > /dev/null 2>&1; done
cd /project
docker build -f bootstrap/$DOCKERFILE .
"
Loading

0 comments on commit 0293f19

Please sign in to comment.