@@ -17,6 +17,7 @@ SET(WITH_TRACE_TOOLS OFF CACHE BOOL "build with trace tools")
1717SET (WITH_GFLAGS OFF CACHE BOOL "build with GFlags" )
1818SET (USE_RTTI ON CACHE BOOL "build with RTTI" )
1919SET (PORTABLE ON CACHE BOOL "build a portable binary" )
20+ SET (WITH_LIBURING ON CACHE BOOL "build with io_uring support" )
2021SET (WITH_TESTS OFF CACHE BOOL "build with tests" )
2122SET (WITH_TOOLS OFF CACHE BOOL "build with tools" )
2223
@@ -49,7 +50,95 @@ find_package( Snappy CONFIG )
4950# RocksDB's approach conflicts with that (double-wrapping the compiler).
5051set (CCACHE_FOUND "CCACHE_FOUND-NOTFOUND" CACHE FILEPATH "Disabled: compiler caching handled at top level" FORCE )
5152
52- add_subdirectory (rocksdb )
53+ # --- Preinstalled RocksDB detection ---
54+ set (HIVE_VENDOR_PREINSTALLED_DIR "/opt/hive/vendor" CACHE PATH
55+ "Base directory for preinstalled vendor libraries" )
56+ option (HIVE_USE_PREINSTALLED_VENDOR
57+ "Use preinstalled vendor libraries if available (OFF to always build from source)" ON )
58+
59+ # Verify submodule is initialized
60+ if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR } /rocksdb/.git" )
61+ message (FATAL_ERROR
62+ "RocksDB submodule not initialized. Run: git submodule update --init --recursive" )
63+ endif ()
64+
65+ # Read the submodule commit hash
66+ execute_process (
67+ COMMAND git rev-parse HEAD
68+ WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR } /rocksdb"
69+ OUTPUT_VARIABLE _rocksdb_commit
70+ OUTPUT_STRIP_TRAILING_WHITESPACE
71+ RESULT_VARIABLE _rocksdb_git_result
72+ )
73+
74+ set (_rocksdb_preinstalled_dir
75+ "${HIVE_VENDOR_PREINSTALLED_DIR} /rocksdb/${_rocksdb_commit} " )
76+
77+ set (_use_preinstalled OFF )
78+ if (HIVE_USE_PREINSTALLED_VENDOR
79+ AND _rocksdb_git_result EQUAL 0
80+ AND EXISTS "${_rocksdb_preinstalled_dir} /lib/librocksdb.a"
81+ AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug" )
82+
83+ # Ensure uring::uring is available before find_package(RocksDB).
84+ # RocksDBConfig.cmake does NOT call find_dependency(uring), but
85+ # RocksDBTargets.cmake references uring::uring in INTERFACE_LINK_LIBRARIES.
86+ # The main CMakeLists.txt includes Finduring.cmake (line 158) before
87+ # add_subdirectory(libraries), so uring::uring should already exist.
88+ # As a safety net, add the RocksDB cmake/modules to MODULE_PATH so that
89+ # Finduring.cmake can be found if needed by any transitive resolution.
90+ list (APPEND CMAKE_MODULE_PATH
91+ "${CMAKE_CURRENT_SOURCE_DIR } /rocksdb/cmake/modules"
92+ "${_rocksdb_preinstalled_dir} /lib/cmake/rocksdb/modules" )
93+
94+ # Use find_package with NO_DEFAULT_PATH to prevent finding a system-installed
95+ # RocksDB instead of our commit-matched preinstalled version.
96+ find_package (RocksDB CONFIG QUIET
97+ PATHS "${_rocksdb_preinstalled_dir} "
98+ NO_DEFAULT_PATH )
99+
100+ if (RocksDB_FOUND)
101+ message (STATUS "Using preinstalled RocksDB (commit: ${_rocksdb_commit} )" )
102+ message (STATUS " Path: ${_rocksdb_preinstalled_dir} " )
103+
104+ # Diagnostic: check what the exported target provides
105+ get_target_property (_rdb_inc RocksDB::rocksdb INTERFACE_INCLUDE_DIRECTORIES )
106+ message (STATUS " RocksDB::rocksdb INTERFACE_INCLUDE_DIRECTORIES: ${_rdb_inc} " )
107+
108+ # Create an INTERFACE library wrapping the IMPORTED target.
109+ # Using INTERFACE instead of ALIAS ensures include directories are always
110+ # propagated correctly, regardless of how the exported target was configured.
111+ # The rest of the hive codebase links against the bare name "rocksdb".
112+ add_library (rocksdb INTERFACE )
113+ target_link_libraries (rocksdb INTERFACE RocksDB::rocksdb )
114+ target_include_directories (rocksdb SYSTEM INTERFACE
115+ "${_rocksdb_preinstalled_dir} /include" )
116+
117+ set (_use_preinstalled ON )
118+
119+ # Expose sst_dump path for build.sh.
120+ # Use PROJECT_BINARY_DIR (not CMAKE_BINARY_DIR) so the file lands in the
121+ # hive subdirectory of the build tree when built from HAF via add_subdirectory(hive).
122+ file (WRITE "${PROJECT_BINARY_DIR } /rocksdb_tools_dir.txt"
123+ "${_rocksdb_preinstalled_dir} /bin" )
124+ else ()
125+ message (STATUS "Preinstalled RocksDB found but find_package failed, building from source" )
126+ endif ()
127+ endif ()
128+
129+ if (NOT _use_preinstalled)
130+ if (_rocksdb_git_result EQUAL 0 AND HIVE_USE_PREINSTALLED_VENDOR)
131+ message (STATUS "No preinstalled RocksDB for commit ${_rocksdb_commit} "
132+ "(or Debug build), building from source" )
133+ elseif (NOT HIVE_USE_PREINSTALLED_VENDOR)
134+ message (STATUS "Preinstalled vendor libraries disabled, building RocksDB from source" )
135+ else ()
136+ message (STATUS "Cannot read RocksDB submodule commit, building from source" )
137+ endif ()
138+
139+ # Current behavior — build from source
140+ add_subdirectory (rocksdb )
141+ endif ()
53142
54143GET_TARGET_PROPERTY ( prop Snappy::snappy IMPORTED_LOCATION_RELWITHDEBINFO )
55144
0 commit comments