Skip to content

Commit 21fe122

Browse files
Luciusdnotestein
authored andcommitted
Detect preinstalled RocksDB by submodule commit hash
1 parent 1808043 commit 21fe122

6 files changed

Lines changed: 114 additions & 9 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ARG IMAGE_TAG_PREFIX
99
# CI base image for build stage - must be at top level for FROM to see it
1010
# Using commit hash instead of tag to pin to a specific docker image for build repeatability.
1111
# Tags can be moved/overwritten, but commit hashes are immutable. May switch to tags in future.
12-
ARG CI_BASE_IMAGE=registry.gitlab.syncad.com/hive/common-ci-configuration/ci-base-image:02189cf63f0c9af1cd29136e299d9622048fdee8
12+
ARG CI_BASE_IMAGE=registry.gitlab.syncad.com/hive/common-ci-configuration/ci-base-image:463736e3915caa64573af655583a040408fbd02b
1313

1414
FROM phusion/baseimage:noble-1.0.1 AS runtime
1515

libraries/plugins/account_history_rocksdb/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ add_library( account_history_rocksdb_plugin
77
)
88

99
target_link_libraries( account_history_rocksdb_plugin
10-
rocksdb chain_plugin hive_chain hive_protocol json_rpc_plugin rocksdb
10+
rocksdb chain_plugin hive_chain hive_protocol json_rpc_plugin
1111
)
1212

1313
target_include_directories( account_history_rocksdb_plugin
1414
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include"
15-
"${CMAKE_CURRENT_SOURCE_DIR}/../../vendor/rocksdb/include"
16-
1715
)
1816

1917
install( TARGETS

libraries/plugins/state_snapshot/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ target_link_libraries( state_snapshot_plugin
1111

1212
target_include_directories( state_snapshot_plugin
1313
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include"
14-
"${CMAKE_CURRENT_SOURCE_DIR}/../../vendor/rocksdb/include"
1514
)
1615

1716
install( TARGETS

libraries/vendor/CMakeLists.txt

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ SET(WITH_TRACE_TOOLS OFF CACHE BOOL "build with trace tools")
1717
SET(WITH_GFLAGS OFF CACHE BOOL "build with GFlags")
1818
SET(USE_RTTI ON CACHE BOOL "build with RTTI")
1919
SET(PORTABLE ON CACHE BOOL "build a portable binary")
20+
SET(WITH_LIBURING ON CACHE BOOL "build with io_uring support")
2021
SET(WITH_TESTS OFF CACHE BOOL "build with tests")
2122
SET(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).
5051
set(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

54143
GET_TARGET_PROPERTY( prop Snappy::snappy IMPORTED_LOCATION_RELWITHDEBINFO )
55144

scripts/build.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,26 @@ if [[ -d "$HIVED_INSTALLATION_DIR" ]]; then
175175

176176
sudo rm -rf "$HIVED_INSTALLATION_DIR/CMakeFiles" "$HIVED_INSTALLATION_DIR/cmake_install.cmake"
177177

178+
# Copy sst_dump tools - check build directory first, then preinstalled path
179+
_sst_dump_found=false
180+
181+
# Source build path (current behavior)
178182
if [[ -n "$(shopt -s nullglob; echo "$abs_build_dir/${HAF_BUILD:+"hive/"}libraries/vendor/rocksdb/tools/sst_dum"*)" ]]; then
179183
sudo mv "$abs_build_dir/${HAF_BUILD:+"hive/"}libraries/vendor/rocksdb/tools/sst_dum"* \
180184
"$HIVED_INSTALLATION_DIR/"
185+
_sst_dump_found=true
186+
fi
187+
188+
# Preinstalled path fallback (when using preinstalled RocksDB)
189+
if [[ "$_sst_dump_found" == "false" ]]; then
190+
_tools_dir_file="$abs_build_dir/${HAF_BUILD:+"hive/"}rocksdb_tools_dir.txt"
191+
if [[ -f "$_tools_dir_file" ]]; then
192+
_preinstalled_tools=$(cat "$_tools_dir_file")
193+
if [[ -n "$_preinstalled_tools" && -n "$(shopt -s nullglob; echo "$_preinstalled_tools/sst_dum"*)" ]]; then
194+
# Use cp, not mv — do not modify the preinstalled directory
195+
sudo cp "$_preinstalled_tools/sst_dum"* "$HIVED_INSTALLATION_DIR/"
196+
fi
197+
fi
181198
fi
182199

183-
fi
200+
fi
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
variables:
2-
# Using tag to pin to a specific ci-base-image version.
3-
CI_BASE_IMAGE_TAG: ":pypa_2_28-4"
2+
# Using commit hash instead of tag to pin to a specific ci-base-image version.
3+
# This ensures build repeatability - tags can be moved/overwritten, but commit hashes are immutable.
4+
# In future we may switch to tags once our tagging workflow is stable.
5+
CI_BASE_IMAGE_TAG: ":463736e3915caa64573af655583a040408fbd02b"
46
CI_BASE_IMAGE: "registry.gitlab.syncad.com/hive/common-ci-configuration/ci-base-image${CI_BASE_IMAGE_TAG}"
57
# Legacy variable for backwards compatibility (deprecated - use CI_BASE_IMAGE instead)
68
TEST_IMAGE_TAG: "${CI_BASE_IMAGE_TAG}"

0 commit comments

Comments
 (0)