Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add installation targets for libbarretenberg, wasm & headers #185

Merged
merged 5 commits into from
Mar 6, 2023
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ cd cpp
./bootstrap.sh
```

### Installing

After the project has been built, such as with `./bootstrap.sh`, you can install the library on your system:

```sh
cmake --install build
```

### Formatting

Code is formatted using `clang-format` and the `./cpp/format.sh` script which is called via a git pre-commit hook.
Expand Down
1 change: 1 addition & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ option(FUZZING "Build fuzzing harnesses" OFF)
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)
option(INSTALL_BARRETENBERG "Enable installation of barretenberg. (Projects embedding barretenberg may want to turn this OFF.)" ON)

if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "arm64")
message(STATUS "Compiling for ARM.")
Expand Down
1 change: 1 addition & 0 deletions cpp/cmake/benchmark.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ if(BENCHMARKS)
)

set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Benchmark tests off")
set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "Benchmark installation off")

FetchContent_MakeAvailable(benchmark)
if(NOT benchmark_FOUND)
Expand Down
1 change: 1 addition & 0 deletions cpp/cmake/gtest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ if(TESTING)
)

set(BUILD_GMOCK OFF CACHE BOOL "Build with gMock disabled")
set(INSTALL_GTEST OFF CACHE BOOL "gTest installation disabled")

FetchContent_MakeAvailable(GTest)

Expand Down
20 changes: 19 additions & 1 deletion cpp/cmake/module.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,29 @@
# Then we declare executables/libraries that are to be built from these object files.
# These assets will only be linked as their dependencies complete, but we can parallelise the compilation at least.

# This is an interface library that can be used as an install target to include all header files
# encountered by the `barretenberg_module` function. There is probably a better way to do this,
# especially if we want to exclude some of the header files being installed
add_library(barretenberg_headers INTERFACE)
target_sources(
barretenberg_headers
INTERFACE
FILE_SET HEADERS
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src
)

function(barretenberg_module MODULE_NAME)
file(GLOB_RECURSE SOURCE_FILES *.cpp)
file(GLOB_RECURSE HEADER_FILES *.hpp)
file(GLOB_RECURSE HEADER_FILES *.hpp *.tcc)
list(FILTER SOURCE_FILES EXCLUDE REGEX ".*\.(fuzzer|test|bench).cpp$")

target_sources(
barretenberg_headers
INTERFACE
FILE_SET HEADERS
FILES ${HEADER_FILES}
)

if(SOURCE_FILES)
add_library(
${MODULE_NAME}_objects
Expand Down
19 changes: 17 additions & 2 deletions cpp/src/aztec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ else()
message(STATUS "Using optimized assembly for field arithmetic.")
endif()

add_subdirectory(common)
add_subdirectory(env)
add_subdirectory(numeric)
add_subdirectory(srs)
Expand All @@ -55,6 +56,8 @@ if(BENCHMARKS)
add_subdirectory(benchmark)
endif()

include(GNUInstallDirs)

if(WASM)
# Well, this is awkward. We can't build a wasm module by just linking to the libraries as that produces, nothing.
# There are a couple of other ways to avoiding listing all the object files here and leveraging the dependency
Expand Down Expand Up @@ -105,6 +108,10 @@ if(WASM)
VERBATIM
)

if(INSTALL_BARRETENBERG)
install(TARGETS barretenberg.wasm DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()

# For use when compiling dependent cpp projects for WASM
message(STATUS "Compiling all-in-one barretenberg WASM archive")
add_library(
Expand All @@ -131,7 +138,6 @@ if(WASM)
$<TARGET_OBJECTS:stdlib_aes128_objects>
$<TARGET_OBJECTS:stdlib_merkle_tree_objects>
)

else()
# For use when compiling dependent cpp projects
message(STATUS "Compiling all-in-one barretenberg archive")
Expand Down Expand Up @@ -160,4 +166,13 @@ else()
$<TARGET_OBJECTS:stdlib_merkle_tree_objects>
$<TARGET_OBJECTS:env_objects>
)
endif()

if(INSTALL_BARRETENBERG)
install(
TARGETS barretenberg barretenberg_headers
EXPORT barretenbergTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
FILE_SET HEADERS DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment explaining what this is doing (especially for EXPORT and each DESTINATION arg). I had to look it up and I'm sure others will too. Still not 100% sure I know what this command is doing after doing a bit of digging.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do in a follow up PR.

endif()
endif()
8 changes: 8 additions & 0 deletions cpp/src/aztec/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Collect our common/*.hpp files and include in installation
file(GLOB_RECURSE HEADER_FILES *.hpp)
target_sources(
barretenberg_headers
INTERFACE
FILE_SET HEADERS
FILES ${HEADER_FILES}
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this only necessary here because common is not a barretenberg_module?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct!