From 2e817bec914caba182cb406b034dc5c43a919e71 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Tue, 11 Mar 2025 14:15:38 +0000 Subject: [PATCH 01/10] Makefile to generate C++ bindings for protobuf --- barretenberg/cpp/.gitignore | 1 + .../cpp/src/barretenberg/dsl/Makefile | 33 ++++++++++++++++++ .../cpp/src/barretenberg/dsl/README.md | 34 ++++++++++++++++++- 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 barretenberg/cpp/src/barretenberg/dsl/Makefile diff --git a/barretenberg/cpp/.gitignore b/barretenberg/cpp/.gitignore index 89bbad4d6b0f..7ce106f42be3 100644 --- a/barretenberg/cpp/.gitignore +++ b/barretenberg/cpp/.gitignore @@ -13,4 +13,5 @@ go*.tar.gz barretenberg_modules.dot barretenberg_modules.png src/barretenberg/bb/config.hpp +src/barretenberg/dsl/acir_format/proto bench-out diff --git a/barretenberg/cpp/src/barretenberg/dsl/Makefile b/barretenberg/cpp/src/barretenberg/dsl/Makefile new file mode 100644 index 000000000000..d41126720f72 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/dsl/Makefile @@ -0,0 +1,33 @@ +PROTO_SRC_DIR := ../../../../../noir/noir-repo/acvm-repo/acir/src/proto +PROTO_DST_DIR := ./acir_format/proto + +# Using acir/program.proto instead of the top level program.proto so that we don't deserialize the Brillig part. +PROTO_SCHEMAS += \ + acir/program.proto \ + acir/witness.proto \ + acir/circuit.proto \ + acir/native.proto + +PROTO_CPP := $(PROTO_SCHEMAS:.proto=.pb.h) +PROTO_DST := $(patsubst %, $(PROTO_DST_DIR)/%, $(PROTO_CPP)) + +.PHONY: all +all: $(PROTO_DST) + + +test: + @echo $(PROTO_DST) + +# Compile an ACIR protobuf schema to C++ +$(PROTO_DST_DIR)/%.pb.h: $(PROTO_SRC_DIR)/%.proto $(PROTO_DST_DIR) | .protoc + protoc --cpp_out $(PROTO_DST_DIR) -I $(PROTO_SRC_DIR) $< + +$(PROTO_DST_DIR): + mkdir -p $@ + +.PHONY: .protoc +.protoc: + @if [ -z "$$(which protoc)" ]; then \ + echo "Please install the protobuf compiler"; \ + exit 1; \ + fi diff --git a/barretenberg/cpp/src/barretenberg/dsl/README.md b/barretenberg/cpp/src/barretenberg/dsl/README.md index 61fc0d4d05ae..9ee7d56af00e 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/README.md +++ b/barretenberg/cpp/src/barretenberg/dsl/README.md @@ -6,11 +6,17 @@ This package adds support to use [ACIR](https://github.com/noir-lang/noir/tree/m There are two types of breaking serialization changes. One that alters the internal ACIR structure passed to barretenberg, and one that changes how we serialize the buffer passed to barretenberg. +### `serde` + +We use `serde` to generate C++ code the domain classes used in Noir. These can be serialized using `bincode`, however this for format is generally +not backwards or forwards compatible, which is why we use `protobuf` as well (see further below). + 1. Internal Structure Change Go to the ACVM `acir` crate and re-run the [serde reflection test](../../../../../noir/noir-repo/acvm-repo/acir/src/lib.rs#L51). Remember to comment out the hash check to write the updated C++ serde file. Copy that file into the `dsl` package's [serde folder](./acir_format/serde/) where you will see an `acir.hpp` file. You will have to update a couple things in the new `acir.hpp`: + - Replace all `throw serde::deserialization_error` with `throw_or_abort` - The top-level struct (such as `Program`) will still use its own namespace for its internal fields. This extra `Program::` can be removed from the top-level `struct Program { .. }` object. @@ -28,7 +34,33 @@ In the context of Aztec we need to regenerate all the artifacts in [noir-project The Aztec artifacts can be individually regenerated as well using `yarn test -u`. You can also run the command on the relevant workspaces, which at the time are the following: -``` + +```shell yarn workspace @aztec/stdlib test -u yarn workspace @aztec/protocol-contracts test -u ``` + +### `protobuf` + +To combat the problems with breaking changes described under `serde` above, we can use [protobuf](https://protobuf.dev) to serialize the ACIR program +and witness stack. The schemas are [defined](https://github.com/noir-lang/noir/tree/master/acvm-repo/acir/src/proto) in the Noir repository, +and the C++ code is generated for them here by running the following command: + +```shell +make -C barretenberg/cpp/src/barretenberg/dsl --no-print-directory +``` + +The resulting `.pb.c` and `.pb.h` files are written to `./acir_format/proto/acir` but aren't checked into source control. + +For example: + +```console +% make -C barretenberg/cpp/src/barretenberg/dsl --no-print-directory ~/aztec-packages af/bb-dsl-acir-proto+ akosh-box +mkdir -p acir_format/proto +protoc --cpp_out ./acir_format/proto -I ../../../../../noir/noir-repo/acvm-repo/acir/src/proto ../../../../../noir/noir-repo/acvm-repo/acir/src/proto/acir/program.proto +protoc --cpp_out ./acir_format/proto -I ../../../../../noir/noir-repo/acvm-repo/acir/src/proto ../../../../../noir/noir-repo/acvm-repo/acir/src/proto/acir/witness.proto +protoc --cpp_out ./acir_format/proto -I ../../../../../noir/noir-repo/acvm-repo/acir/src/proto ../../../../../noir/noir-repo/acvm-repo/acir/src/proto/acir/circuit.proto +protoc --cpp_out ./acir_format/proto -I ../../../../../noir/noir-repo/acvm-repo/acir/src/proto ../../../../../noir/noir-repo/acvm-repo/acir/src/proto/acir/native.proto +% ls barretenberg/cpp/src/barretenberg/dsl/acir_format/proto/acir +circuit.pb.cc circuit.pb.h native.pb.cc native.pb.h program.pb.cc program.pb.h witness.pb.cc witness.pb.h +``` From b9f5008673588f42677a9926d8d060809cca62af Mon Sep 17 00:00:00 2001 From: aakoshh Date: Tue, 11 Mar 2025 14:15:54 +0000 Subject: [PATCH 02/10] Check that the user has protoc --- bootstrap.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap.sh b/bootstrap.sh index 99ddacf810e9..177b96706603 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -24,7 +24,7 @@ function encourage_dev_container { # Developers should probably use the dev container in /build-images to ensure the smoothest experience. function check_toolchains { # Check for various required utilities. - for util in jq parallel awk git curl; do + for util in jq parallel awk git curl protoc; do if ! command -v $util > /dev/null; then encourage_dev_container echo "Utility $util not found." From 906c69092148868addcf56d852ae7407807c5309 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Tue, 11 Mar 2025 14:39:27 +0000 Subject: [PATCH 03/10] Add codegen_dsl.sh --- barretenberg/cpp/scripts/codegen_dsl.sh | 6 ++++++ barretenberg/cpp/src/barretenberg/dsl/README.md | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100755 barretenberg/cpp/scripts/codegen_dsl.sh diff --git a/barretenberg/cpp/scripts/codegen_dsl.sh b/barretenberg/cpp/scripts/codegen_dsl.sh new file mode 100755 index 000000000000..d683f447dce2 --- /dev/null +++ b/barretenberg/cpp/scripts/codegen_dsl.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -eu + +cd $(dirname $0)/.. + +make -C src/barretenberg/dsl --no-print-directory diff --git a/barretenberg/cpp/src/barretenberg/dsl/README.md b/barretenberg/cpp/src/barretenberg/dsl/README.md index 9ee7d56af00e..5d61127f3128 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/README.md +++ b/barretenberg/cpp/src/barretenberg/dsl/README.md @@ -47,7 +47,7 @@ and witness stack. The schemas are [defined](https://github.com/noir-lang/noir/t and the C++ code is generated for them here by running the following command: ```shell -make -C barretenberg/cpp/src/barretenberg/dsl --no-print-directory +barretenberg/cpp/scripts/codegen_dsl.sh ``` The resulting `.pb.c` and `.pb.h` files are written to `./acir_format/proto/acir` but aren't checked into source control. @@ -55,7 +55,7 @@ The resulting `.pb.c` and `.pb.h` files are written to `./acir_format/proto/acir For example: ```console -% make -C barretenberg/cpp/src/barretenberg/dsl --no-print-directory ~/aztec-packages af/bb-dsl-acir-proto+ akosh-box +% barretenberg/cpp/scripts/codegen_dsl.sh mkdir -p acir_format/proto protoc --cpp_out ./acir_format/proto -I ../../../../../noir/noir-repo/acvm-repo/acir/src/proto ../../../../../noir/noir-repo/acvm-repo/acir/src/proto/acir/program.proto protoc --cpp_out ./acir_format/proto -I ../../../../../noir/noir-repo/acvm-repo/acir/src/proto ../../../../../noir/noir-repo/acvm-repo/acir/src/proto/acir/witness.proto From 5628cb82273cf96cd45794cec763ac29f94caf6f Mon Sep 17 00:00:00 2001 From: aakoshh Date: Tue, 11 Mar 2025 14:54:40 +0000 Subject: [PATCH 04/10] Generate protobuf bindings during C++ build --- barretenberg/cpp/bootstrap.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/barretenberg/cpp/bootstrap.sh b/barretenberg/cpp/bootstrap.sh index d0286daccd77..807793a71bf2 100755 --- a/barretenberg/cpp/bootstrap.sh +++ b/barretenberg/cpp/bootstrap.sh @@ -143,6 +143,9 @@ export -f build_native build_darwin build_nodejs_module build_wasm build_wasm_th function build { echo_header "bb cpp build" + + ./scripts/codegen_dsl.sh + builds=( build_native build_nodejs_module From 290e36c96b687a77f3a56c76197e2380e82e3d1a Mon Sep 17 00:00:00 2001 From: aakoshh Date: Tue, 11 Mar 2025 15:01:57 +0000 Subject: [PATCH 05/10] Remove test from Makefile --- barretenberg/cpp/src/barretenberg/dsl/Makefile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/Makefile b/barretenberg/cpp/src/barretenberg/dsl/Makefile index d41126720f72..c623b96b1747 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/Makefile +++ b/barretenberg/cpp/src/barretenberg/dsl/Makefile @@ -14,10 +14,6 @@ PROTO_DST := $(patsubst %, $(PROTO_DST_DIR)/%, $(PROTO_CPP)) .PHONY: all all: $(PROTO_DST) - -test: - @echo $(PROTO_DST) - # Compile an ACIR protobuf schema to C++ $(PROTO_DST_DIR)/%.pb.h: $(PROTO_SRC_DIR)/%.proto $(PROTO_DST_DIR) | .protoc protoc --cpp_out $(PROTO_DST_DIR) -I $(PROTO_SRC_DIR) $< From 6148f6ba46caa8cac9e33ac4f99270e487020b3f Mon Sep 17 00:00:00 2001 From: aakoshh Date: Tue, 11 Mar 2025 16:33:29 +0000 Subject: [PATCH 06/10] Try to include the generated files int the compilation --- .../barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp | 3 ++- .../barretenberg/dsl/acir_format/convert/proto_to_serde.cpp | 0 .../barretenberg/dsl/acir_format/convert/proto_to_serde.hpp | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 barretenberg/cpp/src/barretenberg/dsl/acir_format/convert/proto_to_serde.cpp create mode 100644 barretenberg/cpp/src/barretenberg/dsl/acir_format/convert/proto_to_serde.hpp diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp index 4560c8245445..b916d3bd8609 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp @@ -1,5 +1,6 @@ #pragma once #include "acir_format.hpp" +#include "convert/proto_to_serde.hpp" #include "serde/index.hpp" namespace acir_format { @@ -25,4 +26,4 @@ AcirProgramStack get_acir_program_stack(std::string const& bytecode_path, std::string const& witness_path, uint32_t honk_recursion); #endif -} // namespace acir_format \ No newline at end of file +} // namespace acir_format diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/convert/proto_to_serde.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/convert/proto_to_serde.cpp new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/convert/proto_to_serde.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/convert/proto_to_serde.hpp new file mode 100644 index 000000000000..16fc17b6ca5d --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/convert/proto_to_serde.hpp @@ -0,0 +1,5 @@ +#include "../proto/acir/circuit.pb.h" +#include "../proto/acir/native.pb.h" +#include "../proto/acir/program.pb.h" +#include "../proto/acir/witness.pb.h" +#include "../serde/index.hpp" From 8a998a95987a220c8fed2191fe746045478a5f32 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Wed, 12 Mar 2025 09:25:29 +0000 Subject: [PATCH 07/10] Trying to add protobuf to cmake --- barretenberg/cpp/CMakeLists.txt | 1 + barretenberg/cpp/cmake/protobuf.cmake | 15 +++++++++++++++ barretenberg/cpp/src/CMakeLists.txt | 5 +++++ .../cpp/src/barretenberg/bb/CMakeLists.txt | 1 + 4 files changed, 22 insertions(+) create mode 100644 barretenberg/cpp/cmake/protobuf.cmake diff --git a/barretenberg/cpp/CMakeLists.txt b/barretenberg/cpp/CMakeLists.txt index 109269b3f578..e5bd81fa6e0c 100644 --- a/barretenberg/cpp/CMakeLists.txt +++ b/barretenberg/cpp/CMakeLists.txt @@ -161,6 +161,7 @@ include(cmake/benchmark.cmake) include(cmake/module.cmake) include(cmake/msgpack.cmake) include(cmake/lmdb.cmake) +include(cmake/protobuf.cmake) # We do not need to bloat barretenberg.wasm with gzip functionality in a browser context as the browser can do this if (NOT WASM) diff --git a/barretenberg/cpp/cmake/protobuf.cmake b/barretenberg/cpp/cmake/protobuf.cmake new file mode 100644 index 000000000000..a81126f0c902 --- /dev/null +++ b/barretenberg/cpp/cmake/protobuf.cmake @@ -0,0 +1,15 @@ +# The protobuf compiler should be installed on the builder machine; +# the job here is to find where its C libraries are located, e.g. +# under /usr/include/google/protobuf, so that we can include their headers. +# See docs at https://cmake.org/cmake/help/latest/module/FindProtobuf.html +# See source at https://fossies.org/linux/cmake/Modules/FindProtobuf.cmake or /usr/share/cmake-3.28/Modules/FindProtobuf.cmake + +include(FindProtobuf) +find_package(Protobuf REQUIRED) +include_directories(${Protobuf_INCLUDE_DIRS}) + +# Add this to what needs to use protobuf: +# target_link_libraries( ${Protobuf_LIBRARIES}) + +# TODO: We should be able to generate .pb.h and .pb.cc files from the .proto files +# using the `protobuf_generate_cpp` command, instead of using `cpp/scripts/codegen_dsl.sh` diff --git a/barretenberg/cpp/src/CMakeLists.txt b/barretenberg/cpp/src/CMakeLists.txt index 1020ddd61eb3..69780d6538a5 100644 --- a/barretenberg/cpp/src/CMakeLists.txt +++ b/barretenberg/cpp/src/CMakeLists.txt @@ -259,4 +259,9 @@ if(WASM) -ldw -lelf ) endif() + + target_link_libraries( + barretenberg.wasm, + ${Protobuf_LIBRARIES} + ) endif() diff --git a/barretenberg/cpp/src/barretenberg/bb/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/bb/CMakeLists.txt index c5fd884120c8..b7b5cc4ba17f 100644 --- a/barretenberg/cpp/src/barretenberg/bb/CMakeLists.txt +++ b/barretenberg/cpp/src/barretenberg/bb/CMakeLists.txt @@ -12,6 +12,7 @@ if (NOT(FUZZING) AND NOT(WASM)) circuit_checker ${TRACY_LIBS} libdeflate::libdeflate_static + ${Protobuf_LIBRARIES} ) if(CHECK_CIRCUIT_STACKTRACES) target_link_libraries( From 55e9a478d0e523f8a57cfda110773130c1d8c88e Mon Sep 17 00:00:00 2001 From: aakoshh Date: Wed, 12 Mar 2025 12:29:15 +0000 Subject: [PATCH 08/10] Replace acir imports with path from the root --- barretenberg/cpp/src/barretenberg/dsl/Makefile | 1 + barretenberg/cpp/src/barretenberg/dsl/README.md | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/dsl/Makefile b/barretenberg/cpp/src/barretenberg/dsl/Makefile index c623b96b1747..825ef5c179bf 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/Makefile +++ b/barretenberg/cpp/src/barretenberg/dsl/Makefile @@ -17,6 +17,7 @@ all: $(PROTO_DST) # Compile an ACIR protobuf schema to C++ $(PROTO_DST_DIR)/%.pb.h: $(PROTO_SRC_DIR)/%.proto $(PROTO_DST_DIR) | .protoc protoc --cpp_out $(PROTO_DST_DIR) -I $(PROTO_SRC_DIR) $< + sed -i 's/#include "acir\//#include "barretenberg\/dsl\/acir_format\/proto\/acir\//g' $(PROTO_DST_DIR)/$*.pb.* $(PROTO_DST_DIR): mkdir -p $@ diff --git a/barretenberg/cpp/src/barretenberg/dsl/README.md b/barretenberg/cpp/src/barretenberg/dsl/README.md index 5d61127f3128..209d16f2b5e1 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/README.md +++ b/barretenberg/cpp/src/barretenberg/dsl/README.md @@ -64,3 +64,19 @@ protoc --cpp_out ./acir_format/proto -I ../../../../../noir/noir-repo/acvm-repo/ % ls barretenberg/cpp/src/barretenberg/dsl/acir_format/proto/acir circuit.pb.cc circuit.pb.h native.pb.cc native.pb.h program.pb.cc program.pb.h witness.pb.cc witness.pb.h ``` + +#### Installing Protobuf + +We need to install protobuf from source to work well with `cmake`: + +``` +# instead of `apt install libprotobuf-dev protobuf-compiler` +# https://github.com/protocolbuffers/protobuf/blob/v29.3/cmake/README.md +# using the same version as the Rust build +git clone --branch v29.3 https://github.com/protocolbuffers/protobuf.git +cd protobuf +git submodule update --init --recursive +cmake . +cmake --build . --parallel 10 +sudo cmake --install . +``` From 7d8a470dcac826ac513e77bc56dc467d7b7b2a95 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Wed, 12 Mar 2025 12:34:35 +0000 Subject: [PATCH 09/10] Native build seems to work --- barretenberg/cpp/CMakeLists.txt | 2 +- barretenberg/cpp/cmake/protobuf.cmake | 18 ++++++++++++++++-- barretenberg/cpp/src/CMakeLists.txt | 5 ----- .../cpp/src/barretenberg/bb/CMakeLists.txt | 1 - 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/barretenberg/cpp/CMakeLists.txt b/barretenberg/cpp/CMakeLists.txt index e5bd81fa6e0c..9c427024e4c2 100644 --- a/barretenberg/cpp/CMakeLists.txt +++ b/barretenberg/cpp/CMakeLists.txt @@ -161,7 +161,7 @@ include(cmake/benchmark.cmake) include(cmake/module.cmake) include(cmake/msgpack.cmake) include(cmake/lmdb.cmake) -include(cmake/protobuf.cmake) +#include(cmake/protobuf.cmake) # We do not need to bloat barretenberg.wasm with gzip functionality in a browser context as the browser can do this if (NOT WASM) diff --git a/barretenberg/cpp/cmake/protobuf.cmake b/barretenberg/cpp/cmake/protobuf.cmake index a81126f0c902..5eedf40c39b8 100644 --- a/barretenberg/cpp/cmake/protobuf.cmake +++ b/barretenberg/cpp/cmake/protobuf.cmake @@ -4,8 +4,22 @@ # See docs at https://cmake.org/cmake/help/latest/module/FindProtobuf.html # See source at https://fossies.org/linux/cmake/Modules/FindProtobuf.cmake or /usr/share/cmake-3.28/Modules/FindProtobuf.cmake -include(FindProtobuf) -find_package(Protobuf REQUIRED) +# include(FindProtobuf) + +#list(APPEND CMAKE_PREFIX_PATH "/usr/local/lib/cmake/protobuf") +set(Protobuf_DIR "/usr/local/lib/cmake/protobuf") + +# TODO: This errors saying it cannot find `Protobuf_INCLUDE_DIR`, unless we build protobuf from source. +# find_package(Protobuf REQUIRED) +find_package(Protobuf CONFIG REQUIRED) + +message(" --> PROTOBUF Found: ${Protobuf_FOUND}") +message(" --> PROTOBUF VERSION: ${Protobuf_VERSION}") +message(" --> PROTOBUF LIB: ${PROTOBUF_LIBRARIES}") +message(" --> PROTOBUF INCLUDE: ${PROTOBUF_INCLUDE_DIRS}") + +# set(Protobuf_INCLUDE_DIR "/usr/include/google/protobuf") +# set(Protobuf_INCLUDE_DIRS "/usr/include/google/protobuf") include_directories(${Protobuf_INCLUDE_DIRS}) # Add this to what needs to use protobuf: diff --git a/barretenberg/cpp/src/CMakeLists.txt b/barretenberg/cpp/src/CMakeLists.txt index 69780d6538a5..1020ddd61eb3 100644 --- a/barretenberg/cpp/src/CMakeLists.txt +++ b/barretenberg/cpp/src/CMakeLists.txt @@ -259,9 +259,4 @@ if(WASM) -ldw -lelf ) endif() - - target_link_libraries( - barretenberg.wasm, - ${Protobuf_LIBRARIES} - ) endif() diff --git a/barretenberg/cpp/src/barretenberg/bb/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/bb/CMakeLists.txt index b7b5cc4ba17f..c5fd884120c8 100644 --- a/barretenberg/cpp/src/barretenberg/bb/CMakeLists.txt +++ b/barretenberg/cpp/src/barretenberg/bb/CMakeLists.txt @@ -12,7 +12,6 @@ if (NOT(FUZZING) AND NOT(WASM)) circuit_checker ${TRACY_LIBS} libdeflate::libdeflate_static - ${Protobuf_LIBRARIES} ) if(CHECK_CIRCUIT_STACKTRACES) target_link_libraries( From 6ed370074373dad1de44671200917c89dcea4601 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Wed, 12 Mar 2025 14:48:24 +0000 Subject: [PATCH 10/10] Try to download as part of the build --- barretenberg/cpp/CMakeLists.txt | 2 +- barretenberg/cpp/cmake/protobuf.cmake | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/barretenberg/cpp/CMakeLists.txt b/barretenberg/cpp/CMakeLists.txt index 9c427024e4c2..e5bd81fa6e0c 100644 --- a/barretenberg/cpp/CMakeLists.txt +++ b/barretenberg/cpp/CMakeLists.txt @@ -161,7 +161,7 @@ include(cmake/benchmark.cmake) include(cmake/module.cmake) include(cmake/msgpack.cmake) include(cmake/lmdb.cmake) -#include(cmake/protobuf.cmake) +include(cmake/protobuf.cmake) # We do not need to bloat barretenberg.wasm with gzip functionality in a browser context as the browser can do this if (NOT WASM) diff --git a/barretenberg/cpp/cmake/protobuf.cmake b/barretenberg/cpp/cmake/protobuf.cmake index 5eedf40c39b8..5ea6b9a3f848 100644 --- a/barretenberg/cpp/cmake/protobuf.cmake +++ b/barretenberg/cpp/cmake/protobuf.cmake @@ -4,10 +4,19 @@ # See docs at https://cmake.org/cmake/help/latest/module/FindProtobuf.html # See source at https://fossies.org/linux/cmake/Modules/FindProtobuf.cmake or /usr/share/cmake-3.28/Modules/FindProtobuf.cmake -# include(FindProtobuf) + +FetchContent_Declare(protobuf + GIT_REPOSITORY https://github.com/protocolbuffers/protobuf.git + GIT_TAG v29.3 + SOURCE_SUBDIR cmake + FIND_PACKAGE_ARGS NAMES protobuf +) +FetchContent_MakeAvailable(protobuf) + +include(FindProtobuf) #list(APPEND CMAKE_PREFIX_PATH "/usr/local/lib/cmake/protobuf") -set(Protobuf_DIR "/usr/local/lib/cmake/protobuf") +#set(Protobuf_DIR "/usr/local/lib/cmake/protobuf") # TODO: This errors saying it cannot find `Protobuf_INCLUDE_DIR`, unless we build protobuf from source. # find_package(Protobuf REQUIRED) @@ -22,6 +31,11 @@ message(" --> PROTOBUF INCLUDE: ${PROTOBUF_INCLUDE_DIRS}") # set(Protobuf_INCLUDE_DIRS "/usr/include/google/protobuf") include_directories(${Protobuf_INCLUDE_DIRS}) +#include_directories("/usr/local/include") +#include_directories("/usr/local/include/absl") +#include_directories("/usr/include") + + # Add this to what needs to use protobuf: # target_link_libraries( ${Protobuf_LIBRARIES})