Skip to content

Commit

Permalink
Add barretenberg submodule.
Browse files Browse the repository at this point in the history
Change to `aztec3` branch.

Compilation fixes 1.

Fixes 2.

More fixes.

More fixes.

Some more fixes.
  • Loading branch information
suyash67 committed Feb 16, 2023
1 parent 25cdc7a commit 136a9f4
Show file tree
Hide file tree
Showing 55 changed files with 760 additions and 437 deletions.
28 changes: 28 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
PointerAlignment: Left
ColumnLimit: 120
BreakBeforeBraces: Allman
IndentWidth: 4
BinPackArguments: false
BinPackParameters: false
AllowShortFunctionsOnASingleLine: None
Cpp11BracedListStyle: false
AlwaysBreakAfterReturnType: None
AlwaysBreakAfterDefinitionReturnType: None
PenaltyReturnTypeOnItsOwnLine: 1000000
BreakConstructorInitializers: BeforeComma
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: false
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
AllowShortFunctionsOnASingleLine : Inline
SortIncludes: false
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.cache/
build*/
src/wasi-sdk-*
src/aztec/proof_system/proving_key/fixtures
src/aztec/rollup/proofs/*/fixtures
srs_db/ignition/transcript*
srs_db/lagrange
srs_db/coset_lagrange
srs_db/modified_lagrange
# to be unignored when we agree on clang-tidy rules
.clangd
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "barretenberg"]
path = barretenberg
url = [email protected]:AztecProtocol/barretenberg.git
branch = aztec3
54 changes: 54 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# aztec-connect-cpp
# copyright 2019 Spilsbury Holdings Ltd

cmake_minimum_required(VERSION 3.16)

# Get the full path to barretenberg. This is helpful because the required
# relative path changes based on where in cmake the path is used.
# `BBERG_DIR` must be set before toolchain.cmake is imported because
# `BBERG_DIR` is used in toolchain.cmake to determine `WASI_SDK_PREFIX`
get_filename_component(BBERG_DIR ../barretenberg/cpp
REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")

include(cmake/toolchain.cmake)

set(PROJECT_VERSION 0.1.0)
project(Aztec3Circuits
DESCRIPTION "Project containing Aztec3 Circuits Infrastucture in C++."
LANGUAGES CXX C)

# include barretenberg as ExternalProject
include(cmake/barretenberg.cmake)

option(DISABLE_ASM "Disable custom assembly" OFF)
option(DISABLE_ADX "Disable ADX assembly variant" OFF)
option(MULTITHREADING "Enable multi-threading" ON)
option(TESTING "Build tests" ON)

if(ARM)
message(STATUS "Compiling for ARM.")
set(DISABLE_ASM ON)
set(DISABLE_ADX ON)
set(RUN_HAVE_STD_REGEX 0)
set(RUN_HAVE_POSIX_REGEX 0)
endif()

if(WASM)
message(STATUS "Compiling for WebAssembly.")
set(DISABLE_ASM ON)
set(MULTITHREADING OFF)
endif()

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_EXTENSIONS ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_EXTENSIONS ON)

include(cmake/build.cmake)
include(cmake/arch.cmake)
include(cmake/threading.cmake)
include(cmake/gtest.cmake)
include(cmake/module.cmake)

add_subdirectory(src)
1 change: 1 addition & 0 deletions barretenberg
Submodule barretenberg added at e98e16
57 changes: 57 additions & 0 deletions bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash
set -e

# Update the submodule
git submodule update --init --recursive --remote

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

# Clean barretenberg.
rm -rf ../barretenberg/cpp/build
rm -rf ../barretenberg/cpp/build-wasm
rm -rf ../barretenberg/cpp/src/wasi-sdk-*

# Install formatting git hook.
HOOKS_DIR=$(git rev-parse --git-path hooks)
echo "cd \$(git rev-parse --show-toplevel) && ./format.sh staged" > $HOOKS_DIR/pre-commit
chmod +x $HOOKS_DIR/pre-commit

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

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

# Pick native toolchain file.
if [ "$OS" == "macos" ]; then
export BREW_PREFIX=$(brew --prefix)
# Ensure we have toolchain.
if [ ! "$?" -eq 0 ] || [ ! -f "$BREW_PREFIX/opt/llvm/bin/clang++" ]; then
echo "Default clang not sufficient. Install homebrew, and then: brew install llvm libomp clang-format"
exit 1
fi
ARCH=$(uname -m)
if [ "$ARCH" = "arm64" ]; then
TOOLCHAIN=arm-apple-clang
else
TOOLCHAIN=x86_64-apple-clang
fi
else
TOOLCHAIN=x86_64-linux-clang
fi

# Build native.
mkdir -p build && cd build
cmake -DCMAKE_BUILD_TYPE=RelWithAssert -DTOOLCHAIN=$TOOLCHAIN ..
cmake --build . --parallel ${@/#/--target }
cd ..
10 changes: 10 additions & 0 deletions cmake/arch.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if(WASM)
# Disable SLP vectorization on WASM as it's brokenly slow. To give an idea, with this off it still takes
# 2m:18s to compile scalar_multiplication.cpp, and with it on I estimate it's 50-100 times longer. I never
# had the patience to wait it out...
add_compile_options(-fno-exceptions -fno-slp-vectorize)
endif()

if(NOT WASM AND NOT APPLE)
add_compile_options(-march=skylake-avx512)
endif()
57 changes: 57 additions & 0 deletions cmake/barretenberg.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Here we Set up barretenberg as an ExternalProject
# - Point to its source and build directories
# - Construct its `configure` and `build` command lines
# - include its `src/` in `search path for includes
# - Depend on specific libraries from barretenberg
#
# If barretenberg's cmake files change, its configure and build are triggered
# If barretenberg's source files change, build is triggered

include(ExternalProject)

if (WASM)
set(BBERG_BUILD_DIR ${BBERG_DIR}/build-wasm)
else()
set(BBERG_BUILD_DIR ${BBERG_DIR}/build)
endif()

# If the OpenMP library is included via this option, propogate to ExternalProject configure
if (OpenMP_omp_LIBRARY)
set(LIB_OMP_OPTION -DOpenMP_omp_LIBRARY=${OpenMP_omp_LIBRARY})
endif()

# Make sure barretenberg doesn't set its own WASI_SDK_PREFIX
if (WASI_SDK_PREFIX)
set(WASI_SDK_OPTION -DWASI_SDK_PREFIX=${WASI_SDK_PREFIX})
endif()

# cmake configure cli args for ExternalProject
set(BBERG_CONFIGURE_ARGS -DTOOLCHAIN=${TOOLCHAIN} ${WASI_SDK_OPTION} ${LIB_OMP_OPTION} -DCI=${CI})

# Naming: Project: Barretenberg, Libraries: barretenberg, env
# Need BUILD_ALWAYS to ensure that barretenberg is automatically reconfigured when its CMake files change
# "Enabling this option forces the build step to always be run. This can be the easiest way to robustly
# ensure that the external project's own build dependencies are evaluated rather than relying on the
# default success timestamp-based method." - https://cmake.org/cmake/help/latest/module/ExternalProject.html
ExternalProject_Add(Barretenberg
SOURCE_DIR ${BBERG_DIR}
BINARY_DIR ${BBERG_BUILD_DIR} # build directory
BUILD_ALWAYS TRUE
UPDATE_COMMAND ""
INSTALL_COMMAND ""
CONFIGURE_COMMAND ${CMAKE_COMMAND} ${BBERG_CONFIGURE_ARGS} ..
BUILD_COMMAND ${CMAKE_COMMAND} --build . --parallel --target barretenberg --target env)

include_directories(${BBERG_DIR}/src/aztec)

# Add the imported barretenberg and env libraries, point to their library archives,
# and add a dependency of these libraries on the imported project
add_library(barretenberg STATIC IMPORTED)
set_target_properties(barretenberg PROPERTIES IMPORTED_LOCATION ${BBERG_BUILD_DIR}/lib/libbarretenberg.a)
add_dependencies(barretenberg Barretenberg)

# env is needed for logstr in native executables and wasm tests
# It is otherwise omitted from wasm to prevent use of C++ logstr instead of imported/Typescript
add_library(env STATIC IMPORTED)
set_target_properties(env PROPERTIES IMPORTED_LOCATION ${BBERG_BUILD_DIR}/lib/libenv.a)
add_dependencies(env Barretenberg)
20 changes: 20 additions & 0 deletions cmake/benchmark.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
if(NOT TESTING)
set(BENCHMARKS OFF)
endif()

if(BENCHMARKS)
include(FetchContent)

FetchContent_Declare(
benchmark
GIT_REPOSITORY https://github.com/google/benchmark
GIT_TAG v1.6.1
)

FetchContent_GetProperties(benchmark)
if(NOT benchmark_POPULATED)
fetchcontent_populate(benchmark)
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Benchmark tests off")
add_subdirectory(${benchmark_SOURCE_DIR} ${benchmark_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
endif()
9 changes: 9 additions & 0 deletions cmake/build.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")

if(CMAKE_BUILD_TYPE STREQUAL "RelWithAssert")
add_compile_options(-O3)
remove_definitions(-DNDEBUG)
endif()
32 changes: 32 additions & 0 deletions cmake/gtest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
if(TESTING)
include(GoogleTest)
include(FetchContent)

FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.10.0
)

FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
FetchContent_Populate(googletest)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()

if(WASM)
target_compile_definitions(
gtest
PRIVATE
-DGTEST_HAS_EXCEPTIONS=0
-DGTEST_HAS_STREAM_REDIRECTION=0)
endif()

mark_as_advanced(
BUILD_GMOCK BUILD_GTEST BUILD_SHARED_LIBS
gmock_build_tests gtest_build_samples gtest_build_tests
gtest_disable_pthreads gtest_force_shared_crt gtest_hide_internal_symbols
)

enable_testing()
endif()
Loading

0 comments on commit 136a9f4

Please sign in to comment.