Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 35 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ cd cpp
./bootstrap.sh
```

### Parallelise the build

Use the `--parallel` option to `cmake --build <path>` 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.
Expand All @@ -42,21 +38,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
Comment thread
dbanks12 marked this conversation as resolved.
```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.
Expand All @@ -69,15 +68,18 @@ You can run specific tests, e.g.

Some modules have benchmarks. The build targets are named `<module_name>_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
Expand All @@ -90,17 +92,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=<filename in ./cmake/toolchains>`: 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=<filename in ./cmake/toolchains>`: 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`.
Expand All @@ -113,8 +117,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
```

Expand All @@ -123,11 +127,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.
Expand All @@ -138,10 +143,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):
Expand Down
7 changes: 6 additions & 1 deletion barretenberg.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@
],
"[cpp]": {
"editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd"
}
},
"cmake.configureArgs": [
"--preset clang15",
"-G Ninja",
],
"cmake.useCMakePresets": "auto",
},
}
2 changes: 2 additions & 0 deletions cpp/.clangd
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
CompileFlags: # Tweak the parse settings
Remove: -fconstexpr-ops-limit=*
---
# Applies all barretenberg source files
If:
Expand Down
3 changes: 2 additions & 1 deletion cpp/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ build*/
src/wasi-sdk-*
src/aztec/proof_system/proving_key/fixtures
src/aztec/rollup/proofs/*/fixtures
srs_db/*/*/transcript*
srs_db/*/*/transcript*
CMakeUserPresets.json
9 changes: 5 additions & 4 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading