Skip to content

Commit

Permalink
feat: Utilize globally installed leveldb if available (#134)
Browse files Browse the repository at this point in the history
* feat: Utilize globally installed leveldb if available

* chore: Update docs

* chore(docker): Update wasm builder to ubuntu:kinetic for newer cmake

* chore: Cleanup fragile target linking
  • Loading branch information
phated authored Feb 14, 2023
1 parent 515604d commit 255dfb5
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The structured reference string contains monomials up to x^{2^20}. This SRS was

### Dependencies

- cmake >= 3.16
- cmake >= 3.24
- clang >= 10 or gcc >= 10
- clang-format
- libomp (if multithreading is required. Multithreading can be disabled using the compiler flag `-DMULTITHREADING 0`)
Expand Down
2 changes: 1 addition & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# barretenberg
# copyright 2019 Spilsbury Holdings Ltd

cmake_minimum_required(VERSION 3.16)
cmake_minimum_required(VERSION 3.24)

include(cmake/toolchain.cmake)

Expand Down
26 changes: 18 additions & 8 deletions cpp/cmake/module.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function(barretenberg_module MODULE_NAME)
OBJECT
${SOURCE_FILES}
)
list(APPEND lib_targets ${MODULE_NAME}_objects)

add_library(
${MODULE_NAME}
Expand All @@ -36,6 +37,7 @@ function(barretenberg_module MODULE_NAME)
${ARGN}
${TBB_IMPORTED_TARGETS}
)
list(APPEND lib_targets ${MODULE_NAME})

set(MODULE_LINK_NAME ${MODULE_NAME})
endif()
Expand All @@ -47,6 +49,7 @@ function(barretenberg_module MODULE_NAME)
OBJECT
${TEST_SOURCE_FILES}
)
list(APPEND lib_targets ${MODULE_NAME}_test_objects)

target_link_libraries(
${MODULE_NAME}_test_objects
Expand All @@ -59,6 +62,7 @@ function(barretenberg_module MODULE_NAME)
${MODULE_NAME}_tests
$<TARGET_OBJECTS:${MODULE_NAME}_test_objects>
)
list(APPEND exe_targets ${MODULE_NAME}_tests)

if(WASM)
target_link_options(
Expand Down Expand Up @@ -111,22 +115,23 @@ function(barretenberg_module MODULE_NAME)
foreach(FUZZER_SOURCE_FILE ${FUZZERS_SOURCE_FILES})
get_filename_component(FUZZER_NAME_STEM ${FUZZER_SOURCE_FILE} NAME_WE)
add_executable(
${MODULE_NAME}_${FUZZER_NAME_STEM}_fuzzer
${FUZZER_SOURCE_FILE}
${MODULE_NAME}_${FUZZER_NAME_STEM}_fuzzer
${FUZZER_SOURCE_FILE}
)
list(APPEND exe_targets ${MODULE_NAME}_${FUZZER_NAME_STEM}_fuzzer)

target_link_options(
${MODULE_NAME}_${FUZZER_NAME_STEM}_fuzzer
${MODULE_NAME}_${FUZZER_NAME_STEM}_fuzzer
PRIVATE
"-fsanitize=fuzzer"
${SANITIZER_OPTIONS}
)
)

target_link_libraries(
${MODULE_NAME}_${FUZZER_NAME_STEM}_fuzzer
PRIVATE
${MODULE_NAME}_${FUZZER_NAME_STEM}_fuzzer
PRIVATE
${MODULE_LINK_NAME}
)
)
endforeach()
endif()

Expand All @@ -137,6 +142,7 @@ function(barretenberg_module MODULE_NAME)
OBJECT
${BENCH_SOURCE_FILES}
)
list(APPEND lib_targets ${MODULE_NAME}_bench_objects)

target_link_libraries(
${MODULE_NAME}_bench_objects
Expand All @@ -149,6 +155,7 @@ function(barretenberg_module MODULE_NAME)
${MODULE_NAME}_bench
$<TARGET_OBJECTS:${MODULE_NAME}_bench_objects>
)
list(APPEND exe_targets ${MODULE_NAME}_bench)

target_link_libraries(
${MODULE_NAME}_bench
Expand All @@ -165,4 +172,7 @@ function(barretenberg_module MODULE_NAME)
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endif()
endfunction()

set(${MODULE_NAME}_lib_targets ${lib_targets} PARENT_SCOPE)
set(${MODULE_NAME}_exe_targets ${exe_targets} PARENT_SCOPE)
endfunction()
2 changes: 1 addition & 1 deletion cpp/dockerfiles/Dockerfile.wasm-linux-clang
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:focal AS builder
FROM ubuntu:kinetic AS builder
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential wget git libssl-dev cmake curl binaryen
RUN curl https://wasmtime.dev/install.sh -sSf | bash /dev/stdin --version v3.0.1
WORKDIR /usr/src/barretenberg/cpp/src
Expand Down
47 changes: 32 additions & 15 deletions cpp/src/aztec/stdlib/merkle_tree/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,43 @@
barretenberg_module(stdlib_merkle_tree stdlib_primitives stdlib_blake3s stdlib_pedersen)

if(NOT WASM)
include(FetchContent)
FetchContent_Declare(
leveldb
GIT_REPOSITORY https://github.com/google/leveldb.git
GIT_TAG 1.22
FIND_PACKAGE_ARGS
)

FetchContent_GetProperties(leveldb)
if(NOT leveldb_POPULATED)
FetchContent_Populate(leveldb)
set(LEVELDB_BUILD_TESTS OFF CACHE BOOL "LevelDB tests off")
add_subdirectory(${leveldb_SOURCE_DIR} ${leveldb_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
# Disable some leveldb targets before we call FetchContent_MakeAvailable
# so they are configured correctly if it needs to fetch
set(LEVELDB_BUILD_TESTS OFF CACHE BOOL "LevelDB tests off")
set(LEVELDB_BUILD_BENCHMARKS OFF CACHE BOOL "LevelDB benchmarks off")

# Silence all compiler warnings from LevelDB
target_compile_options(
leveldb
PRIVATE
-w
)
FetchContent_MakeAvailable(leveldb)

link_libraries(leveldb)
endif()
if (leveldb_FOUND)
# Globally installed leveldb needs Threads available as Threads::Threads as discovered by `find_package`
find_package(Threads REQUIRED)

barretenberg_module(stdlib_merkle_tree stdlib_primitives stdlib_blake3s stdlib_pedersen)
foreach(target IN LISTS stdlib_merkle_tree_lib_targets stdlib_merkle_tree_exe_targets)
target_link_libraries(${target} PRIVATE leveldb::leveldb)
endforeach()
else()
# FetchContent_MakeAvailable calls FetchContent_Populate if `find_package` is unsuccessful
# so these variables will be available if we reach this case
set_property(DIRECTORY ${leveldb_SOURCE_DIR} PROPERTY EXCLUDE_FROM_ALL)
set_property(DIRECTORY ${leveldb_BINARY_DIR} PROPERTY EXCLUDE_FROM_ALL)

# Silence all compiler warnings from LevelDB
target_compile_options(
leveldb
PRIVATE
-w
)

foreach(target IN LISTS stdlib_merkle_tree_lib_targets stdlib_merkle_tree_exe_targets)
target_link_libraries(${target} PRIVATE leveldb)
endforeach()
endif()
endif()

0 comments on commit 255dfb5

Please sign in to comment.