1- # Standalone build for lmdblib — the LMDB C++ wrapper.
1+ # lmdblib — a small C++ wrapper around LMDB .
22#
3- # This package owns the lmdb wrapper that barretenberg no longer needs (the
4- # in-memory merkle core is lmdb-free). It builds two static archives that the
5- # kvdb NAPI addon and the wsdb service link against:
6- # - liblmdb.a : the upstream LMDB C library (pinned to bb's commit)
7- # - liblmdblib.a : the bb::lmdblib C++ wrapper objects
3+ # Builds two static archives that the kvdb NAPI addon and the wsdb service link:
4+ # - liblmdb.a : the LMDB C library (built from source, pinned commit)
5+ # - liblmdblib.a : the lmdblib C++ wrapper objects
86#
9- # It is barretenberg-free: it includes no bb headers and links no bb archives. It
10- # vendors its own msgpack-c + lmdb (commits pinned to barretenberg/cpp/cmake/*) and
11- # defines the shared DBStats POD locally (src/lmdblib/types.hpp).
7+ # It is self-contained: it vendors LMDB and msgpack-c (header-only) via FetchContent.
128
139cmake_minimum_required (VERSION 3.24 )
14- # C is enabled so CMAKE_C_COMPILER is populated for lmdb's ExternalProject build .
10+ # C is enabled to compile the LMDB C sources .
1511project (aztec_lmdblib CXX C )
1612
1713set (CMAKE_CXX_STANDARD 20)
@@ -21,66 +17,54 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
2117
2218# Default to Release (-O3 -DNDEBUG). lmdblib's templated/inline headers (serialise_key,
2319# value_cmp, the msgpack adaptors) are compiled into both liblmdblib.a and into every
24- # consumer that includes them (the kvdb .node , the wsdb service). Matching the consumers'
20+ # consumer that includes them (the kvdb addon , the wsdb service); matching the consumers'
2521# Release build keeps that inline codegen identical and avoids ODR divergence.
2622if (NOT CMAKE_BUILD_TYPE )
2723 set (CMAKE_BUILD_TYPE Release)
2824endif ()
2925
3026# ---------------------------------------------------------------------------
31- # Third-party deps (own copies; commits must match barretenberg/cpp/cmake/* ).
27+ # Third-party dependencies (fetched at configure time ).
3228# ---------------------------------------------------------------------------
33- set (DEPS_PREFIX "${CMAKE_BINARY_DIR } /_deps" )
34- include (ExternalProject )
29+ include (FetchContent )
3530
36- # lmdb: build our own liblmdb.a (pinned to bb's commit in cmake/lmdb.cmake).
37- set (LMDB_PREFIX "${DEPS_PREFIX} /lmdb" )
38- set (LMDB_INCLUDE "${LMDB_PREFIX} /src/lmdb_repo/libraries/liblmdb" )
39- set (LMDB_LIB "${LMDB_INCLUDE} /liblmdb.a" )
40- ExternalProject_Add (
41- lmdb_repo
42- PREFIX ${LMDB_PREFIX}
43- DOWNLOAD_COMMAND
44- sh -c "mkdir -p ${LMDB_PREFIX} /src/lmdb_repo && cd ${LMDB_PREFIX} /src/lmdb_repo && git init --quiet && (git remote add origin https://github.com/LMDB/lmdb.git 2>/dev/null || true) && git fetch --depth 1 origin --quiet ddd0a773e2f44d38e4e31ec9ed81af81f4e4ccbb && git reset --quiet --hard FETCH_HEAD"
45- SOURCE_DIR ${LMDB_PREFIX} /src/lmdb_repo
46- BUILD_IN_SOURCE YES
47- CONFIGURE_COMMAND ""
48- BUILD_COMMAND ${CMAKE_COMMAND } -E env --unset=CFLAGS --unset=CXXFLAGS CC=${CMAKE_C_COMPILER }${CMAKE_C_COMPILER_ARG1} AR=${CMAKE_AR } make -e -C libraries/liblmdb XCFLAGS=-fPIC liblmdb.a
49- INSTALL_COMMAND ""
50- UPDATE_COMMAND ""
51- BUILD_BYPRODUCTS ${LMDB_LIB}
31+ # LMDB: a plain-Makefile C library (no CMake). Fetch the source and compile the two
32+ # translation units ourselves so they use this project's toolchain and flags.
33+ FetchContent_Declare (
34+ lmdb
35+ GIT_REPOSITORY https://github.com/LMDB/lmdb.git
36+ GIT_TAG ddd0a773e2f44d38e4e31ec9ed81af81f4e4ccbb
5237)
53- add_library (lmdb STATIC IMPORTED GLOBAL )
54- add_dependencies (lmdb lmdb_repo )
55- set_target_properties (lmdb PROPERTIES IMPORTED_LOCATION ${LMDB_LIB} )
38+ FetchContent_MakeAvailable (lmdb)
39+ set (LMDB_DIR ${lmdb_SOURCE_DIR } /libraries/liblmdb)
40+ add_library (lmdb STATIC ${LMDB_DIR} /mdb.c ${LMDB_DIR} /midl.c )
41+ target_include_directories (lmdb PUBLIC ${LMDB_DIR} )
5642
57- # msgpack-c: header-only; fetch for includes (pinned to bb's commit in cmake/msgpack.cmake).
58- set (MSGPACK_PREFIX "${DEPS_PREFIX} /msgpack-c" )
59- set (MSGPACK_INCLUDE "${MSGPACK_PREFIX} /src/msgpack-c/include" )
60- ExternalProject_Add (
61- msgpack-c
62- PREFIX ${MSGPACK_PREFIX}
63- DOWNLOAD_COMMAND
64- sh -c "mkdir -p ${MSGPACK_PREFIX} /src/msgpack-c && cd ${MSGPACK_PREFIX} /src/msgpack-c && git init --quiet && (git remote add origin https://github.com/AztecProtocol/msgpack-c.git 2>/dev/null || true) && git fetch --depth 1 origin --quiet c0334576ed657fb3b3c49e8e61402989fb84146d && git reset --quiet --hard FETCH_HEAD"
65- SOURCE_DIR ${MSGPACK_PREFIX} /src/msgpack-c
66- CONFIGURE_COMMAND ""
67- BUILD_COMMAND ""
68- INSTALL_COMMAND ""
69- UPDATE_COMMAND ""
43+ # msgpack-c: header-only. Fetch the source and use its include directory directly
44+ # (we don't build msgpack-c's own CMake targets/tests).
45+ FetchContent_Declare (
46+ msgpack
47+ GIT_REPOSITORY https://github.com/msgpack/msgpack-c.git
48+ GIT_TAG cpp-7.0.0
7049)
50+ FetchContent_GetProperties (msgpack)
51+ if (NOT msgpack_POPULATED)
52+ FetchContent_Populate (msgpack)
53+ endif ()
54+ set (MSGPACK_INCLUDE ${msgpack_SOURCE_DIR } /include)
7155
72- # lmdblib is barretenberg-free: it links no bb archives and includes no bb headers.
73- # It is still compiled with libc++ and -march=skylake so its objects are ABI- and
74- # arch-compatible when linked into consumers (wsdb, kvdb) alongside bb's archives .
75- add_compile_definitions (MSGPACK_NO_BOOST MSGPACK_USE_STD_VARIANT_ADAPTOR NO_PAR_ALGOS )
56+ # msgpack-c is used header-only with exceptions ( no boost). Compiled with libc++ and
57+ # -march=skylake so lmdblib's objects are ABI- and arch-compatible with the consumers
58+ # (kvdb, wsdb) they are linked into .
59+ add_compile_definitions (MSGPACK_NO_BOOST NO_PAR_ALGOS )
7660add_compile_options (-march=skylake -fconstexpr-steps=100000000 -fbracket-depth=1024 )
7761add_compile_options (-Wno-deprecated-declarations -Wno-missing-field-initializers )
7862add_compile_options (-stdlib=libc++ )
7963
8064include_directories (
8165 ${CMAKE_CURRENT_SOURCE_DIR } /src
8266 ${MSGPACK_INCLUDE}
83- ${LMDB_INCLUDE }
67+ ${LMDB_DIR }
8468)
8569
8670# ---------------------------------------------------------------------------
@@ -100,4 +84,24 @@ set(LMDBLIB_SOURCES
10084 src/lmdblib/queries.cpp
10185)
10286add_library (lmdblib STATIC ${LMDBLIB_SOURCES} )
103- add_dependencies (lmdblib lmdb_repo msgpack-c )
87+ add_dependencies (lmdblib lmdb )
88+
89+ # ---------------------------------------------------------------------------
90+ # Tests (vendored googletest; self-contained, no external dependencies).
91+ # ---------------------------------------------------------------------------
92+ option (LMDBLIB_BUILD_TESTS "Build lmdblib C++ tests" ON )
93+ if (LMDBLIB_BUILD_TESTS)
94+ add_link_options (-stdlib=libc++ )
95+ FetchContent_Declare (
96+ googletest
97+ GIT_REPOSITORY https://github.com/google/googletest.git
98+ GIT_TAG v1.13.0
99+ )
100+ set (INSTALL_GTEST OFF CACHE BOOL "" FORCE )
101+ FetchContent_MakeAvailable (googletest)
102+ add_executable (lmdblib_tests
103+ src/lmdblib/lmdb_store.test.cpp
104+ src/lmdblib/lmdb_environment.test.cpp
105+ )
106+ target_link_libraries (lmdblib_tests PRIVATE lmdblib lmdb GTest::gtest_main pthread )
107+ endif ()
0 commit comments