diff --git a/README.md b/README.md index 5fa9ef762f..382a0bc0a4 100644 --- a/README.md +++ b/README.md @@ -30,10 +30,6 @@ cd cpp ./bootstrap.sh ``` -### Parallelise the build - -Use the `--parallel` option to `cmake --build ` to parallelize builds. This is roughly equivalent to `make -j$(nproc)` but is more portable. - ### Formatting Code is formatted using `clang-format` and the `./cpp/format.sh` script which is called via a git pre-commit hook. @@ -43,21 +39,24 @@ If you've installed the C++ Vscode extension you should configure it to format o Each module has its own tests. e.g. To build and run `ecc` tests: -``` -cmake --build . --parallel --target ecc_tests +```bash +# Replace the `default` preset with whichever preset you want to use +cmake --build --preset default --target ecc_tests +cd build ./bin/ecc_tests ``` A shorthand for the above is: -``` -cmake --build . --parallel --target run_ecc_tests +```bash +# Replace the `default` preset with whichever preset you want to use +cmake --build --preset default --target run_ecc_tests ``` Running the entire suite of tests using `ctest`: -``` -cmake --build . --parallel --target test +```bash +cmake --build --preset default --target test ``` You can run specific tests, e.g. @@ -70,15 +69,18 @@ You can run specific tests, e.g. Some modules have benchmarks. The build targets are named `_bench`. To build and run, for example `ecc` benchmarks. -``` -cmake --build . --parallel --target ecc_bench -./src/aztec/ecc/ecc_bench +```bash +# Replace the `default` preset with whichever preset you want to use +cmake --build --preset default --target ecc_bench +cd build +./bin/ecc_bench ``` A shorthand for the above is: -``` -cmake --build . --parallel --target run_ecc_bench +```bash +# Replace the `default` preset with whichever preset you want to use +cmake --build --preset default --target run_ecc_bench ``` ### CMake Build Options @@ -91,17 +93,19 @@ CMake can be passed various build options on its command line: - `-DMULTITHREADING=ON | OFF`: Enable/disable multithreading using OpenMP. - `-DTESTING=ON | OFF`: Enable/disable building of tests. - `-DBENCHMARK=ON | OFF`: Enable/disable building of benchmarks. -- `-DTOOLCHAIN=`: Use one of the preconfigured toolchains. - `-DFUZZING=ON | OFF`: Enable building various fuzzers. +If you are cross-compiling, you can use a preconfigured toolchain file: + +- `-DCMAKE_TOOLCHAIN_FILE=`: Use one of the preconfigured toolchains. + ### WASM build To build: -``` -mkdir build-wasm && cd build-wasm -cmake -DTOOLCHAIN=wasm-linux-clang .. -cmake --build . --parallel --target barretenberg.wasm +```bash +cmake --preset wasm +cmake --build --preset wasm --target barretenberg.wasm ``` The resulting wasm binary will be at `./build-wasm/bin/barretenberg.wasm`. @@ -114,8 +118,8 @@ curl https://wasmtime.dev/install.sh -sSf | bash Tests can be built and run like: -``` -cmake --build . --parallel --target ecc_tests +```bash +cmake --build --preset wasm --target ecc_tests wasmtime --dir=.. ./bin/ecc_tests ``` @@ -124,11 +128,12 @@ wasmtime --dir=.. ./bin/ecc_tests For detailed instructions look in cpp/docs/Fuzzing.md To build: + +```bash +cmake --preset fuzzing +cmake --build --preset fuzzing ``` -mkdir build-fuzzing && cd build-fuzzing -cmake -DTOOLCHAIN=x86_64-linux-clang -DFUZZING=ON .. -cmake --build . --parallel -``` + Fuzzing build turns off building tests and benchmarks, since they are incompatible with libfuzzer interface. To turn on address sanitizer add `-DADDRESS_SANITIZER=ON`. Note that address sanitizer can be used to explore crashes. @@ -139,10 +144,10 @@ Note that the fuzzer can be orders of magnitude slower with ASan (2-3x slower) o ### Test coverage build To build: -``` -mkdir build-coverage && cd build-coverage -cmake -DTOOLCHAIN=x86_64-linux-clang -DCOVERAGE=ON -DCMAKE_BUILD_TYPE=Debug .. -cmake --build . --parallel + +```bash +cmake --preset coverage +cmake --build --preset coverage ``` Then run tests (on the mainframe always use taskset and nice to limit your influence on the server. Profiling instrumentation is very heavy): diff --git a/barretenberg.code-workspace b/barretenberg.code-workspace index f3e74be55e..dc0a3c21f0 100644 --- a/barretenberg.code-workspace +++ b/barretenberg.code-workspace @@ -145,6 +145,11 @@ ], "[cpp]": { "editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd" - } + }, + "cmake.configureArgs": [ + "--preset clang15", + "-G Ninja", + ], + "cmake.useCMakePresets": "auto", }, } \ No newline at end of file diff --git a/cpp/.clangd b/cpp/.clangd index a3746326c9..a082221eec 100644 --- a/cpp/.clangd +++ b/cpp/.clangd @@ -1,3 +1,5 @@ +CompileFlags: # Tweak the parse settings + Remove: -fconstexpr-ops-limit=* --- # Applies all barretenberg source files If: diff --git a/cpp/.gitignore b/cpp/.gitignore index 2ff0b8af65..e34119cce8 100644 --- a/cpp/.gitignore +++ b/cpp/.gitignore @@ -3,4 +3,5 @@ build*/ src/wasi-sdk-* src/aztec/proof_system/proving_key/fixtures src/aztec/rollup/proofs/*/fixtures -srs_db/*/*/transcript* \ No newline at end of file +srs_db/*/*/transcript* +CMakeUserPresets.json diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 562a35698f..fe24d09aa0 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -3,8 +3,6 @@ cmake_minimum_required(VERSION 3.24) -include(cmake/toolchain.cmake) - set(PROJECT_VERSION 0.1.0) project(Barretenberg DESCRIPTION "BN254 elliptic curve library, and PLONK SNARK prover" @@ -20,8 +18,9 @@ option(DISABLE_TBB "Intel Thread Building Blocks" ON) option(COVERAGE "Enable collecting coverage from tests" OFF) option(ENABLE_HEAVY_TESTS "Enable heavy tests when collecting coverage" OFF) -if(ARM) +if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "arm64") message(STATUS "Compiling for ARM.") + set(ARM ON) set(DISABLE_ASM ON) set(DISABLE_ADX ON) set(RUN_HAVE_STD_REGEX 0) @@ -54,12 +53,14 @@ if(FUZZING) set(TESTING OFF) endif() -if(WASM) +if(CMAKE_SYSTEM_PROCESSOR MATCHES "wasm32") message(STATUS "Compiling for WebAssembly.") + set(WASM ON) set(DISABLE_ASM ON) set(MULTITHREADING OFF) set(BENCHMARKS OFF) set(DISABLE_TBB 1) + add_compile_definitions(_WASI_EMULATED_PROCESS_CLOCKS=1) endif() set(CMAKE_C_STANDARD 11) diff --git a/cpp/CMakePresets.json b/cpp/CMakePresets.json new file mode 100644 index 0000000000..0f249a00d7 --- /dev/null +++ b/cpp/CMakePresets.json @@ -0,0 +1,215 @@ +{ + "version": 5, + "cmakeMinimumRequired": { + "major": 3, + "minor": 24, + "patch": 0 + }, + "configurePresets": [ + { + "name": "default", + "displayName": "Build with Clang", + "description": "Build with globally installed Clang", + "binaryDir": "build", + "generator": "Ninja", + "environment": { + "CC": "clang", + "CXX": "clang++", + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" + } + }, + { + "name": "homebrew", + "displayName": "Homebrew + Clang", + "description": "Build with Clang installed via Homebrew", + "inherits": "default", + "environment": { + "CC": "$env{BREW_PREFIX}/opt/llvm/bin/clang", + "CXX": "$env{BREW_PREFIX}/opt/llvm/bin/clang++", + "LDFLAGS": "-L$env{BREW_PREFIX}/opt/libomp/lib", + "CPPFLAGS": "-I$env{BREW_PREFIX}/opt/libomp/include" + } + }, + { + "name": "clang15", + "displayName": "Build with Clang-15", + "description": "Build with globally installed Clang-15", + "inherits": "default", + "environment": { + "CC": "clang-15", + "CXX": "clang++-15" + } + }, + { + "name": "gcc", + "displayName": "Build with GCC", + "description": "Build with globally installed GCC", + "inherits": "default", + "environment": { + "CC": "gcc", + "CXX": "g++" + } + }, + { + "name": "gcc10", + "displayName": "Build with GCC-10", + "description": "Build with globally installed GCC-10", + "inherits": "default", + "environment": { + "CC": "gcc-10", + "CXX": "g++-10" + } + }, + { + "name": "bench", + "displayName": "Build benchmarks", + "description": "Build default preset but with a special benchmark directory", + "inherits": "default", + "binaryDir": "build-bench" + }, + { + "name": "fuzzing", + "displayName": "Build with fuzzing", + "description": "Build default preset but with fuzzing enabled", + "inherits": "default", + "binaryDir": "build-fuzzing", + "cacheVariables": { + "FUZZING": "ON" + } + }, + { + "name": "coverage", + "displayName": "Build with coverage", + "description": "Build default preset but with coverage enabled", + "inherits": "default", + "binaryDir": "build-coverage", + "cacheVariables": { + "COVERAGE": "ON", + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "wasm", + "displayName": "Build for WASM", + "description": "Build with a specific wasm-sdk to create wasm", + "binaryDir": "build-wasm", + "toolchainFile": "cmake/toolchains/wasm32-wasi.cmake", + "environment": { + "WASI_SDK_PREFIX": "${sourceDir}/src/wasi-sdk-12.0", + "CC": "$env{WASI_SDK_PREFIX}/bin/clang", + "CXX": "$env{WASI_SDK_PREFIX}/bin/clang++", + "AR": "$env{WASI_SDK_PREFIX}/bin/llvm-ar", + "RANLIB": "$env{WASI_SDK_PREFIX}/bin/llvm-ranlib" + }, + "cacheVariables": { + "CMAKE_SYSROOT": "$env{WASI_SDK_PREFIX}/share/wasi-sysroot", + "CMAKE_STAGING_PREFIX": "$env{WASI_SDK_PREFIX}/share/wasi-sysroot", + "CMAKE_FIND_ROOT_PATH_MODE_PROGRAM": "NEVER", + "CMAKE_FIND_ROOT_PATH_MODE_LIBRARY": "ONLY", + "CMAKE_FIND_ROOT_PATH_MODE_INCLUDE": "ONLY", + "CMAKE_FIND_ROOT_PATH_MODE_PACKAGE": "ONLY", + "CMAKE_C_COMPILER_WORKS": "ON", + "CMAKE_CXX_COMPILER_WORKS": "ON" + } + } + ], + "buildPresets": [ + { + "name": "default", + "configurePreset": "default", + "inheritConfigureEnvironment": true, + "jobs": 0 + }, + { + "name": "homebrew", + "inherits": "default", + "configurePreset": "homebrew" + }, + { + "name": "clang15", + "inherits": "default", + "configurePreset": "clang15" + }, + { + "name": "gcc", + "inherits": "default", + "configurePreset": "gcc" + }, + { + "name": "gcc10", + "inherits": "default", + "configurePreset": "gcc10" + }, + { + "name": "bench", + "inherits": "default", + "configurePreset": "bench" + }, + { + "name": "fuzzing", + "inherits": "default", + "configurePreset": "fuzzing" + }, + { + "name": "coverage", + "inherits": "default", + "configurePreset": "coverage" + }, + { + "name": "wasm", + "configurePreset": "wasm", + "inheritConfigureEnvironment": true, + "jobs": 0, + "targets": [ + "barretenberg.wasm" + ] + } + ], + "testPresets": [ + { + "name": "default", + "configurePreset": "default", + "inheritConfigureEnvironment": true + }, + { + "name": "homebrew", + "inherits": "default", + "configurePreset": "homebrew" + }, + { + "name": "clang15", + "inherits": "default", + "configurePreset": "clang15" + }, + { + "name": "gcc", + "inherits": "default", + "configurePreset": "gcc" + }, + { + "name": "gcc10", + "inherits": "default", + "configurePreset": "gcc10" + }, + { + "name": "bench", + "inherits": "default", + "configurePreset": "bench" + }, + { + "name": "fuzzing", + "inherits": "default", + "configurePreset": "fuzzing" + }, + { + "name": "coverage", + "inherits": "default", + "configurePreset": "coverage" + }, + { + "name": "wasm", + "configurePreset": "wasm", + "inheritConfigureEnvironment": true + } + ] +} \ No newline at end of file diff --git a/cpp/bootstrap.sh b/cpp/bootstrap.sh index a93a488ac8..5098761bc3 100755 --- a/cpp/bootstrap.sh +++ b/cpp/bootstrap.sh @@ -34,33 +34,35 @@ cd .. # Pick native toolchain file. ARCH=$(uname -m) 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 - if [ "$ARCH" = "arm64" ]; then - TOOLCHAIN=arm-apple-clang + if [ "$(which brew)" != "" ]; 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 + + PRESET=homebrew else - TOOLCHAIN=x86_64-apple-clang + PRESET=default fi - - export LDFLAGS="-L$BREW_PREFIX/opt/libomp/lib" - export CPPFLAGS="-I$BREW_PREFIX/opt/libomp/include" else - if [ "$ARCH" = "aarch64" ]; then - TOOLCHAIN=aarch64-linux-clang + if [ "$(which clang++-15)" != "" ]; then + PRESET=clang15 else - TOOLCHAIN=x86_64-linux-clang + PRESET=default fi fi +echo "#################################" +echo "# Building with preset: $PRESET" +echo "# When running cmake directly, remember to use: --build --preset $PRESET" +echo "#################################" + # Build native. -mkdir -p build && cd build -cmake -DCMAKE_BUILD_TYPE=RelWithAssert -DTOOLCHAIN=$TOOLCHAIN .. -cmake --build . --parallel ${@/#/--target } -cd .. +cmake --preset $PRESET -DCMAKE_BUILD_TYPE=RelWithAssert +cmake --build --preset $PRESET ${@/#/--target } # Install the webassembly toolchain. WASI_VERSION=12 @@ -69,7 +71,5 @@ curl -s -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$W cd .. # Build WASM. -mkdir -p build-wasm && cd build-wasm -cmake -DTOOLCHAIN=wasm-linux-clang .. -cmake --build . --parallel --target barretenberg.wasm -cd .. \ No newline at end of file +cmake --preset wasm +cmake --build --preset wasm diff --git a/cpp/cmake/toolchain.cmake b/cpp/cmake/toolchain.cmake deleted file mode 100644 index 4de860fac4..0000000000 --- a/cpp/cmake/toolchain.cmake +++ /dev/null @@ -1,10 +0,0 @@ -if (CMAKE_C_COMPILER AND CMAKE_CXX_COMPILER) - message(STATUS "Toolchain: manually chosen ${CMAKE_C_COMPILER} and ${CMAKE_CXX_COMPILER}") -else() - if(NOT TOOLCHAIN) - set(TOOLCHAIN "x86_64-linux-clang" CACHE STRING "Build toolchain." FORCE) - endif() - message(STATUS "Toolchain: ${TOOLCHAIN}") - - include("./cmake/toolchains/${TOOLCHAIN}.cmake") -endif() \ No newline at end of file diff --git a/cpp/cmake/toolchains/aarch64-darwin.cmake b/cpp/cmake/toolchains/aarch64-darwin.cmake new file mode 100644 index 0000000000..a3b8d52fa7 --- /dev/null +++ b/cpp/cmake/toolchains/aarch64-darwin.cmake @@ -0,0 +1,2 @@ +set(CMAKE_SYSTEM_NAME Darwin) +set(CMAKE_SYSTEM_PROCESSOR aarch64) diff --git a/cpp/cmake/toolchains/aarch64-linux-clang.cmake b/cpp/cmake/toolchains/aarch64-linux-clang.cmake deleted file mode 100644 index e876c0c038..0000000000 --- a/cpp/cmake/toolchains/aarch64-linux-clang.cmake +++ /dev/null @@ -1,6 +0,0 @@ -set(ARM ON) -set(CMAKE_SYSTEM_NAME Linux) -set(CMAKE_SYSTEM_PROCESSOR aarch64) - -set(CMAKE_C_COMPILER "clang") -set(CMAKE_CXX_COMPILER "clang++") diff --git a/cpp/cmake/toolchains/aarch64-linux.cmake b/cpp/cmake/toolchains/aarch64-linux.cmake new file mode 100644 index 0000000000..d79a26e90f --- /dev/null +++ b/cpp/cmake/toolchains/aarch64-linux.cmake @@ -0,0 +1,2 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR aarch64) diff --git a/cpp/cmake/toolchains/arm-apple-clang.cmake b/cpp/cmake/toolchains/arm-apple-clang.cmake deleted file mode 100644 index 1b451ab08d..0000000000 --- a/cpp/cmake/toolchains/arm-apple-clang.cmake +++ /dev/null @@ -1,4 +0,0 @@ -set(APPLE ON) -set(ARM ON) -set(CMAKE_CXX_COMPILER "$ENV{BREW_PREFIX}/opt/llvm/bin/clang++") -set(CMAKE_C_COMPILER "$ENV{BREW_PREFIX}/opt/llvm/bin/clang") \ No newline at end of file diff --git a/cpp/cmake/toolchains/arm64-linux-gcc.cmake b/cpp/cmake/toolchains/arm64-linux-gcc.cmake deleted file mode 100644 index bc8bd0b802..0000000000 --- a/cpp/cmake/toolchains/arm64-linux-gcc.cmake +++ /dev/null @@ -1,21 +0,0 @@ -set(ARM ON) -set(CMAKE_SYSTEM_NAME Linux) -set(CMAKE_SYSTEM_VERSION 1) -set(CMAKE_SYSTEM_PROCESSOR aarch64) - -set(cross_triple "aarch64-unknown-linux-gnu") -set(cross_root /usr/xcc/${cross_triple}) - -set(CMAKE_C_COMPILER $ENV{CC}) -set(CMAKE_CXX_COMPILER $ENV{CXX}) -set(CMAKE_Fortran_COMPILER $ENV{FC}) - -set(CMAKE_CXX_FLAGS "-I ${cross_root}/include/") - -set(CMAKE_FIND_ROOT_PATH ${cross_root} ${cross_root}/${cross_triple}) -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH) -set(CMAKE_SYSROOT ${cross_root}/${cross_triple}/sysroot) - -set(CMAKE_CROSSCOMPILING_EMULATOR /usr/bin/qemu-aarch64) \ No newline at end of file diff --git a/cpp/cmake/toolchains/i386-linux-clang.cmake b/cpp/cmake/toolchains/i386-linux-clang.cmake deleted file mode 100644 index acbdb3d47e..0000000000 --- a/cpp/cmake/toolchains/i386-linux-clang.cmake +++ /dev/null @@ -1,13 +0,0 @@ -# Sometimes we need to set compilers manually, for example for fuzzing -if(NOT CMAKE_C_COMPILER) - set(CMAKE_C_COMPILER "clang") -endif() - -if(NOT CMAKE_CXX_COMPILER) - set(CMAKE_CXX_COMPILER "clang++") -endif() - -add_compile_options("-m32") -add_link_options("-m32") -set(MULTITHREADING OFF) -add_definitions(-DDISABLE_SHENANIGANS=1) \ No newline at end of file diff --git a/cpp/cmake/toolchains/i386-linux.cmake b/cpp/cmake/toolchains/i386-linux.cmake new file mode 100644 index 0000000000..db424698ee --- /dev/null +++ b/cpp/cmake/toolchains/i386-linux.cmake @@ -0,0 +1,7 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR i386) + +add_compile_options("-m32") +add_link_options("-m32") +set(MULTITHREADING OFF) +add_definitions(-DDISABLE_SHENANIGANS=1) diff --git a/cpp/cmake/toolchains/wasm-linux-clang.cmake b/cpp/cmake/toolchains/wasm-linux-clang.cmake deleted file mode 100644 index d410e8833f..0000000000 --- a/cpp/cmake/toolchains/wasm-linux-clang.cmake +++ /dev/null @@ -1,38 +0,0 @@ -# Cmake toolchain description file for the Makefile - -# This is arbitrary, AFAIK, for now. -cmake_minimum_required(VERSION 3.4.0) - -set(WASM ON) -set(CMAKE_SYSTEM_NAME Generic) -set(CMAKE_SYSTEM_VERSION 1) -set(CMAKE_SYSTEM_PROCESSOR wasm32) -set(triple wasm32-wasi) - -if (NOT WASI_SDK_PREFIX) - # can be set by a dependent project - set(WASI_SDK_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/src/wasi-sdk-12.0") -endif() -set(CMAKE_C_COMPILER ${WASI_SDK_PREFIX}/bin/clang) -set(CMAKE_CXX_COMPILER ${WASI_SDK_PREFIX}/bin/clang++) -set(CMAKE_AR ${WASI_SDK_PREFIX}/bin/llvm-ar CACHE STRING "wasi-sdk build") -set(CMAKE_RANLIB ${WASI_SDK_PREFIX}/bin/llvm-ranlib CACHE STRING "wasi-sdk build") -set(CMAKE_C_COMPILER_TARGET ${triple} CACHE STRING "wasi-sdk build") -set(CMAKE_CXX_COMPILER_TARGET ${triple} CACHE STRING "wasi-sdk build") -#set(CMAKE_EXE_LINKER_FLAGS "-Wl,--no-threads" CACHE STRING "wasi-sdk build") - -set(CMAKE_SYSROOT ${WASI_SDK_PREFIX}/share/wasi-sysroot CACHE STRING "wasi-sdk build") -set(CMAKE_STAGING_PREFIX ${WASI_SDK_PREFIX}/share/wasi-sysroot CACHE STRING "wasi-sdk build") - -# Don't look in the sysroot for executables to run during the build -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) -# Only look in the sysroot (not in the host paths) for the rest -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) - -# Some other hacks -set(CMAKE_C_COMPILER_WORKS ON) -set(CMAKE_CXX_COMPILER_WORKS ON) - -add_definitions(-D_WASI_EMULATED_PROCESS_CLOCKS=1) \ No newline at end of file diff --git a/cpp/cmake/toolchains/wasm32-wasi.cmake b/cpp/cmake/toolchains/wasm32-wasi.cmake new file mode 100644 index 0000000000..17e19376ed --- /dev/null +++ b/cpp/cmake/toolchains/wasm32-wasi.cmake @@ -0,0 +1,3 @@ +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_VERSION 1) +set(CMAKE_SYSTEM_PROCESSOR wasm32) diff --git a/cpp/cmake/toolchains/x86_64-apple-clang.cmake b/cpp/cmake/toolchains/x86_64-apple-clang.cmake deleted file mode 100644 index 35440991b9..0000000000 --- a/cpp/cmake/toolchains/x86_64-apple-clang.cmake +++ /dev/null @@ -1,3 +0,0 @@ -set(APPLE ON) -set(CMAKE_CXX_COMPILER "$ENV{BREW_PREFIX}/opt/llvm/bin/clang++") -set(CMAKE_C_COMPILER "$ENV{BREW_PREFIX}/opt/llvm/bin/clang") \ No newline at end of file diff --git a/cpp/cmake/toolchains/x86_64-darwin.cmake b/cpp/cmake/toolchains/x86_64-darwin.cmake new file mode 100644 index 0000000000..0aa93407fb --- /dev/null +++ b/cpp/cmake/toolchains/x86_64-darwin.cmake @@ -0,0 +1,2 @@ +set(CMAKE_SYSTEM_NAME Darwin) +set(CMAKE_SYSTEM_PROCESSOR x86_64) diff --git a/cpp/cmake/toolchains/x86_64-linux-clang.cmake b/cpp/cmake/toolchains/x86_64-linux-clang.cmake deleted file mode 100644 index 529afc02a4..0000000000 --- a/cpp/cmake/toolchains/x86_64-linux-clang.cmake +++ /dev/null @@ -1,9 +0,0 @@ -# Specifically use clang 15 binaries if available. Otherwise fallback on default version. -find_program(CLANGXX_15 "clang++-15") -if (CLANGXX_15) - set(CMAKE_C_COMPILER "clang-15") - set(CMAKE_CXX_COMPILER "clang++-15") -else() - set(CMAKE_C_COMPILER "clang") - set(CMAKE_CXX_COMPILER "clang++") -endif() \ No newline at end of file diff --git a/cpp/cmake/toolchains/x86_64-linux-gcc.cmake b/cpp/cmake/toolchains/x86_64-linux-gcc.cmake deleted file mode 100644 index d1b2790e88..0000000000 --- a/cpp/cmake/toolchains/x86_64-linux-gcc.cmake +++ /dev/null @@ -1,2 +0,0 @@ -set(CMAKE_C_COMPILER "gcc") -set(CMAKE_CXX_COMPILER "g++") \ No newline at end of file diff --git a/cpp/cmake/toolchains/x86_64-linux-gcc10.cmake b/cpp/cmake/toolchains/x86_64-linux-gcc10.cmake deleted file mode 100644 index 8ce971f493..0000000000 --- a/cpp/cmake/toolchains/x86_64-linux-gcc10.cmake +++ /dev/null @@ -1,2 +0,0 @@ -set(CMAKE_C_COMPILER "gcc-10") -set(CMAKE_CXX_COMPILER "g++-10") \ No newline at end of file diff --git a/cpp/cmake/toolchains/x86_64-linux.cmake b/cpp/cmake/toolchains/x86_64-linux.cmake new file mode 100644 index 0000000000..69c1e6d234 --- /dev/null +++ b/cpp/cmake/toolchains/x86_64-linux.cmake @@ -0,0 +1,2 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR x86_64) diff --git a/cpp/dockerfiles/Dockerfile.arm64-linux-gcc b/cpp/dockerfiles/Dockerfile.arm64-linux-gcc index ccfbe287ef..3b33f7df13 100644 --- a/cpp/dockerfiles/Dockerfile.arm64-linux-gcc +++ b/cpp/dockerfiles/Dockerfile.arm64-linux-gcc @@ -1,6 +1,8 @@ +# Unused & not maintained. This probably won't work without changes. + FROM aztecprotocol/crosstool-ng-arm64:latest WORKDIR /usr/src/barretenberg/cpp COPY . . -RUN mkdir build && cd build && cmake -DTOOLCHAIN=arm64-linux-gcc .. && cmake --build . --parallel +RUN cmake --toolchain ./cmake/toolchains/aarch64-linux.cmake --preset gcc && cmake --build --preset gcc RUN cd build && qemu-aarch64 ./test/barretenberg_tests ENTRYPOINT /bin/bash \ No newline at end of file diff --git a/cpp/dockerfiles/Dockerfile.crosstool-ng b/cpp/dockerfiles/Dockerfile.crosstool-ng index 4fa18b30c4..a6346d3fd6 100644 --- a/cpp/dockerfiles/Dockerfile.crosstool-ng +++ b/cpp/dockerfiles/Dockerfile.crosstool-ng @@ -1,3 +1,5 @@ +# Unused & not maintained. This probably won't work without changes. + FROM ubuntu:latest RUN apt-get update && apt-get install -y autoconf flex texinfo unzip help2man file gawk libtool-bin ncurses-dev bison python-dev diff --git a/cpp/dockerfiles/Dockerfile.crosstool-ng-arm64 b/cpp/dockerfiles/Dockerfile.crosstool-ng-arm64 index ed60507121..58f0402940 100644 --- a/cpp/dockerfiles/Dockerfile.crosstool-ng-arm64 +++ b/cpp/dockerfiles/Dockerfile.crosstool-ng-arm64 @@ -1,3 +1,5 @@ +# Unused & not maintained. This probably won't work without changes. + FROM aztecprotocol/crosstool-ng:1.24.0 # Build toolchain. diff --git a/cpp/dockerfiles/Dockerfile.wasm-linux-clang b/cpp/dockerfiles/Dockerfile.wasm-linux-clang index 82cd3db43a..3282702b98 100644 --- a/cpp/dockerfiles/Dockerfile.wasm-linux-clang +++ b/cpp/dockerfiles/Dockerfile.wasm-linux-clang @@ -7,8 +7,8 @@ WORKDIR /usr/src/barretenberg/cpp COPY . . # Build both honk_tests barretenberg.wasm # This ensures that we aren't using features that would be incompatible with WASM for Honk -RUN mkdir build && cd build && cmake -DTOOLCHAIN=wasm-linux-clang .. && cmake --build . --parallel --target honk_tests --target barretenberg.wasm +RUN cmake --preset wasm && cmake --build --preset wasm --target honk_tests --target barretenberg.wasm FROM alpine:3.17 -COPY --from=builder /usr/src/barretenberg/cpp/build/bin/barretenberg.wasm /usr/src/barretenberg/cpp/build/bin/barretenberg.wasm -COPY --from=builder /usr/src/barretenberg/cpp/build/bin/*_tests /usr/src/barretenberg/cpp/build/bin/ +COPY --from=builder /usr/src/barretenberg/cpp/build-wasm/bin/barretenberg.wasm /usr/src/barretenberg/cpp/build/bin/barretenberg.wasm +COPY --from=builder /usr/src/barretenberg/cpp/build-wasm/bin/*_tests /usr/src/barretenberg/cpp/build/bin/ diff --git a/cpp/dockerfiles/Dockerfile.x86_64-linux-clang b/cpp/dockerfiles/Dockerfile.x86_64-linux-clang index 7abcc376fe..6e0b707b52 100644 --- a/cpp/dockerfiles/Dockerfile.x86_64-linux-clang +++ b/cpp/dockerfiles/Dockerfile.x86_64-linux-clang @@ -6,6 +6,7 @@ RUN apk update \ clang15 \ openmp-dev \ cmake \ + ninja \ git \ curl \ perl @@ -14,7 +15,7 @@ WORKDIR /usr/src/barretenberg/cpp COPY . . # Build the entire project, as we want to check everything builds under clang -RUN mkdir build && cd build && cmake .. && cmake --build . --parallel +RUN cmake --preset default && cmake --build --preset default FROM alpine:3.17 RUN apk update && apk add openmp diff --git a/cpp/dockerfiles/Dockerfile.x86_64-linux-clang-assert b/cpp/dockerfiles/Dockerfile.x86_64-linux-clang-assert index 373c76cbb8..d03fa89cdf 100644 --- a/cpp/dockerfiles/Dockerfile.x86_64-linux-clang-assert +++ b/cpp/dockerfiles/Dockerfile.x86_64-linux-clang-assert @@ -6,6 +6,7 @@ RUN apk update \ clang15 \ openmp-dev \ cmake \ + ninja \ git \ curl \ perl @@ -14,7 +15,7 @@ WORKDIR /usr/src/barretenberg/cpp COPY . . # Build everything to ensure everything builds. All tests will be run from the result of this build. -RUN mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=RelWithAssert -DCI=ON .. && cmake --build . --parallel +RUN cmake --preset default -DCMAKE_BUILD_TYPE=RelWithAssert -DCI=ON && cmake --build --preset default FROM alpine:3.17 RUN apk update && apk add curl openmp diff --git a/cpp/dockerfiles/Dockerfile.x86_64-linux-gcc b/cpp/dockerfiles/Dockerfile.x86_64-linux-gcc index 1d58d18153..53fa5a0fe0 100644 --- a/cpp/dockerfiles/Dockerfile.x86_64-linux-gcc +++ b/cpp/dockerfiles/Dockerfile.x86_64-linux-gcc @@ -4,12 +4,13 @@ RUN apk update \ && apk add --no-cache \ build-base \ cmake \ + ninja \ git \ curl WORKDIR /usr/src/barretenberg/cpp COPY . . # Build the entire project, as we want to check everything builds under gcc. -RUN mkdir build && cd build && cmake -DTOOLCHAIN=x86_64-linux-gcc -DCI=ON .. && cmake --build . --parallel +RUN cmake --preset gcc -DCI=ON && cmake --build --preset gcc FROM alpine:3.17 RUN apk update && apk add libstdc++ libgomp diff --git a/cpp/docs/Fuzzing.md b/cpp/docs/Fuzzing.md index d1a4025a92..7efc814e84 100644 --- a/cpp/docs/Fuzzing.md +++ b/cpp/docs/Fuzzing.md @@ -5,10 +5,9 @@ We are gradually introducing fuzzing of various primitives into barretenberg, fo ## Build To build with standard clang: -``` -mkdir build-fuzzing && cd build-fuzzing -cmake -DFUZZING=ON .. -make +```bash +cmake --preset fuzzing +cmake --build --preset fuzzing ``` Fuzzing build turns off building tests and benchmarks, since they are incompatible with libfuzzer interface. @@ -78,11 +77,9 @@ Also, both bigfield and safeuint fuzzer containt the SHOW_INFORMATION preprocess Build with coverage instrumentation: -```cpp -mkdir build-coverage/ -cd build-coverage/ -cmake -DFUZZING=ON -DCMAKE_CXX_FLAGS="-fprofile-instr-generate -fcoverage-mapping" .. -cmake --build . --parallel +```bash +cmake --preset coverage -DFUZZING=ON -DCMAKE_CXX_FLAGS="-fprofile-instr-generate -fcoverage-mapping" +cmake --build --preset coverage ``` Then run the fuzzer on the corpus and generate the HTML coverage reports: diff --git a/cpp/src/aztec/benchmark/honk_bench/compare_honk_bench.sh b/cpp/src/aztec/benchmark/honk_bench/compare_honk_bench.sh index a618dbf53b..59c3a49e24 100755 --- a/cpp/src/aztec/benchmark/honk_bench/compare_honk_bench.sh +++ b/cpp/src/aztec/benchmark/honk_bench/compare_honk_bench.sh @@ -7,7 +7,7 @@ echo -e '\nComparing Honk benchmarks between master and current branch:' # Set some directories BASE_DIR="$HOME/barretenberg/cpp" -BUILD_DIR="$BASE_DIR/build" +BUILD_DIR="$BASE_DIR/build-bench" BENCH_RESULTS_DIR="$BASE_DIR/tmp_bench_results" BENCH_TOOLS_DIR="$BUILD_DIR/_deps/benchmark-src/tools" @@ -22,8 +22,8 @@ mkdir $BENCH_RESULTS_DIR # Checkout master, run honk_bench, save results in json format echo -e '\nConfiguring and building honk_bench in master branch..' git checkout master > /dev/null -rm -rf $BUILD_DIR && mkdir $BUILD_DIR && cd $BUILD_DIR -cmake .. > /dev/null && make honk_bench > /dev/null +rm -rf $BUILD_DIR +cmake --preset bench > /dev/null && cmake --build --preset bench --target honk_bench > /dev/null MASTER_HONK_BENCH_RESULTS="$BENCH_RESULTS_DIR/honk_bench_results_master.json" echo -e '\nRunning honk_bench in master..' bin/honk_bench --benchmark_format=json > $MASTER_HONK_BENCH_RESULTS @@ -31,8 +31,8 @@ bin/honk_bench --benchmark_format=json > $MASTER_HONK_BENCH_RESULTS # Checkout working branch (-), run honk_bench, save results in json format echo -e '\nConfiguring and building honk_bench in current feature branch..' git checkout - -rm -rf $BUILD_DIR && mkdir $BUILD_DIR && cd $BUILD_DIR -cmake .. > /dev/null && make honk_bench > /dev/null +rm -rf $BUILD_DIR +cmake --preset bench > /dev/null && cmake --build --preset bench --target honk_bench > /dev/null BRANCH_HONK_BENCH_RESULTS="$BENCH_RESULTS_DIR/honk_bench_results_branch.json" echo -e '\nRunning honk_bench in feature branch..' bin/honk_bench --benchmark_format=json > $BRANCH_HONK_BENCH_RESULTS