mirror of
https://github.com/valkey-io/valkey.git
synced 2026-05-06 05:26:42 -04:00
0327c27131
Add a build option to compile the Lua scripting engine as a static module and wire the server to load it directly at startup when enabled. The module load path now resolves on-load and on-unload entry points from the main binary, and the module lifecycle keeps those callbacks so unload works without a shared library handle. The Lua module build was updated to support both static and shared variants, with the static path exporting visible wrapper symbols and linking the server with the module archive. While touching the Lua code, a few internal symbols were renamed for consistency and the monotonic time helper was clarified. Note that this PR addresses the LUA module, but it can be applied to other "core" modules (like: Bloom, Json, Search and others). With this change, it will be easier to ship Valkey bundle with modules. Areas touched: * CMake * Makefile * Lua scripting module * Core module loading **Generated by CodeLite** --------- Signed-off-by: Eran Ifrah <eifrah@amazon.com>
78 lines
2.5 KiB
CMake
78 lines
2.5 KiB
CMake
cmake_minimum_required(VERSION 3.10)
|
|
|
|
# Must be done first
|
|
if (APPLE)
|
|
# Force clang compiler on macOS
|
|
find_program(CLANGPP "clang++")
|
|
find_program(CLANG "clang")
|
|
if (CLANG AND CLANGPP)
|
|
message(STATUS "Found ${CLANGPP}, ${CLANG}")
|
|
set(CMAKE_CXX_COMPILER ${CLANGPP})
|
|
set(CMAKE_C_COMPILER ${CLANG})
|
|
endif ()
|
|
endif ()
|
|
|
|
# Options
|
|
set(BUILD_LUA "static" CACHE STRING "Build Valkey Lua scripting engine: static (default), module, no")
|
|
option(BUILD_UNIT_GTESTS "Build valkey-unit-gtests" OFF)
|
|
option(BUILD_TEST_MODULES "Build all test modules" OFF)
|
|
option(BUILD_EXAMPLE_MODULES "Build example modules" OFF)
|
|
|
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
|
|
project("valkey")
|
|
add_compile_options(-Wundef)
|
|
|
|
set(CMAKE_C_STANDARD 11)
|
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
|
set(CMAKE_C_EXTENSIONS ON)
|
|
|
|
include(ValkeySetup)
|
|
add_subdirectory(src)
|
|
add_subdirectory(tests)
|
|
|
|
# Include the packaging module
|
|
include(Packaging)
|
|
|
|
# Clear cached variables from the cache
|
|
unset(BUILD_LUA CACHE)
|
|
unset(BUILD_TESTS CACHE)
|
|
unset(CLANGPP CACHE)
|
|
unset(CLANG CACHE)
|
|
unset(BUILD_RDMA_MODULE CACHE)
|
|
unset(BUILD_TLS_MODULE CACHE)
|
|
unset(BUILD_UNIT_GTESTS CACHE)
|
|
unset(BUILD_TEST_MODULES CACHE)
|
|
unset(BUILD_EXAMPLE_MODULES CACHE)
|
|
unset(USE_TLS CACHE)
|
|
unset(DEBUG_FORCE_DEFRAG CACHE)
|
|
|
|
# Helper to copy runtest scripts to allow running tests with CMake built binaries
|
|
function(copy_runtest_script script_name)
|
|
set(src "${CMAKE_SOURCE_DIR}/${script_name}")
|
|
set(dst "${CMAKE_BINARY_DIR}/${script_name}")
|
|
file(READ "${src}" contents)
|
|
|
|
# Split at the first newline (after shebang #!/bin/sh)
|
|
string(FIND "${contents}" "\n" index_of_first_newline_char)
|
|
math(EXPR first_index_script_body "${index_of_first_newline_char} + 1")
|
|
|
|
string(SUBSTRING "${contents}" 0 ${first_index_script_body} shebang_line)
|
|
string(SUBSTRING "${contents}" ${first_index_script_body} -1 script_body)
|
|
|
|
# Insert our environment variable lines
|
|
set(insert_content
|
|
"# Most tests assume running from the project root
|
|
cd ${CMAKE_SOURCE_DIR}
|
|
export VALKEY_BIN_DIR=\"${CMAKE_BINARY_DIR}/bin\"
|
|
")
|
|
# Reconstruct the full script
|
|
set(new_contents "${shebang_line}${insert_content}${script_body}")
|
|
file(WRITE "${dst}" "${new_contents}")
|
|
file(CHMOD "${dst}" PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
|
|
endfunction()
|
|
|
|
copy_runtest_script("runtest")
|
|
copy_runtest_script("runtest-cluster")
|
|
copy_runtest_script("runtest-moduleapi")
|
|
copy_runtest_script("runtest-rdma")
|
|
copy_runtest_script("runtest-sentinel") |