Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
26fe874
Add Static Module Support
eifrah-aws Mar 22, 2026
df6c34f
Fix Remove Cached Eval Scripts On Engine Unregister
eifrah-aws Mar 25, 2026
aacd575
Fix Lua Monotonic Time Handling For Static Builds
eifrah-aws Mar 25, 2026
114c783
Update server startup with LUA & Refactor Lua Build Modes
eifrah-aws Mar 25, 2026
2be8ea9
Fix Lua Module Build Flag Propagation
eifrah-aws Mar 25, 2026
2010ad6
Fix Shutdown Hook Log Assertion
eifrah-aws Mar 29, 2026
4b7ff25
Removed extra log line during shutdown
eifrah-aws Mar 29, 2026
412e8c8
Use weak attributes on duplicate symbols
eifrah-aws Mar 30, 2026
08553b6
Mark `sha1hex` as a weak symbol
eifrah-aws Mar 30, 2026
e2cfc88
Merge branch 'unstable' into static-lua
eifrah-aws Apr 5, 2026
ec69dd1
Fixed loading on FreeBSD
eifrah-aws Apr 7, 2026
686fde1
Refactor Static Module Loading Documentation
eifrah-aws Apr 7, 2026
4c548f0
Merge branch 'unstable' into static-lua
eifrah-aws Apr 7, 2026
6e25514
Lua Makefile: Use a Variable to Declare the Target
eifrah-aws Apr 7, 2026
eadeb47
Merge branch 'unstable' into static-lua
eifrah-aws Apr 12, 2026
c1ad9c5
Removed un-needed attributes
eifrah-aws Apr 12, 2026
09d0891
Merge branch 'unstable' into static-lua
eifrah-aws Apr 13, 2026
cf5a994
Refine module lifecycle and cleanup logic
eifrah-aws Apr 13, 2026
83c258f
Remove always_inline attribute from `getClientType`
eifrah-aws Apr 13, 2026
f0886db
Refactor Module Loading to Eliminate Code Duplication
eifrah-aws Apr 14, 2026
251f2fe
Addressed comments
eifrah-aws Apr 14, 2026
17c0128
When possible, use engine's time helpers
eifrah-aws Apr 14, 2026
68a09c7
Merge branch 'unstable' into static-lua
eifrah-aws Apr 16, 2026
8125f2c
Merge branch 'unstable' into static-lua
eifrah-aws Apr 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if (APPLE)
endif ()

# Options
option(BUILD_LUA "Build Valkey Lua scripting engine" ON)
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)
Expand Down
39 changes: 24 additions & 15 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,34 @@ add_dependencies(valkey-server generate_commands_def)
add_dependencies(valkey-server generate_fmtargs_h)
add_dependencies(valkey-server release_header)

if (BUILD_LUA)
if (NOT BUILD_LUA STREQUAL "no")
message(STATUS "Build Lua scripting engine module")
if (BUILD_LUA STREQUAL "static")
add_compile_definitions(STATIC_LUA=1)
message(STATUS "Building LUA as a STATIC module")
else ()
add_compile_definitions(STATIC_LUA=0)
message(STATUS "Building LUA as a DYNAMIC module")
endif ()
add_subdirectory(modules/lua)
add_dependencies(valkey-server valkeylua)
if (BUILD_LUA STREQUAL "static")
target_link_libraries(valkey-server $<LINK_LIBRARY:WHOLE_ARCHIVE,valkeylua>)
else ()
add_dependencies(valkey-server valkeylua)
endif ()
target_compile_definitions(valkey-server PRIVATE LUA_ENABLED)
if (UNIX AND NOT APPLE)
target_compile_definitions(valkey-server PRIVATE LUA_LIB=libvalkeylua.so)
target_link_options(valkey-server PRIVATE -Wl,--disable-new-dtags)
else ()
target_compile_definitions(valkey-server PRIVATE LUA_LIB=libvalkeylua.dylib)
endif ()
set(VALKEY_INSTALL_RPATH "")
set_target_properties(valkey-server PROPERTIES
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR};${CMAKE_LIBRARY_OUTPUT_DIRECTORY}"
INSTALL_RPATH_USE_LINK_PATH TRUE
BUILD_WITH_INSTALL_RPATH TRUE
)
endif()
set_target_properties(
valkey-server
PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR};${CMAKE_LIBRARY_OUTPUT_DIRECTORY}"
INSTALL_RPATH_USE_LINK_PATH TRUE
BUILD_WITH_INSTALL_RPATH TRUE)
endif ()
unset(BUILD_LUA CACHE)

if (VALKEY_RELEASE_BUILD)
Expand All @@ -49,9 +59,8 @@ if (DEBUG_FORCE_DEFRAG)
endif ()

if (BUILD_SANITIZER)
# 'BUILD_SANITIZER' is defined in ValkeySetup module (based on user input)
# If defined, the variables 'VALKEY_SANITAIZER_CFLAGS' and 'VALKEY_SANITAIZER_LDFLAGS'
# are set with the link & compile flags required
# 'BUILD_SANITIZER' is defined in ValkeySetup module (based on user input) If defined, the variables
# 'VALKEY_SANITAIZER_CFLAGS' and 'VALKEY_SANITAIZER_LDFLAGS' are set with the link & compile flags required
message(STATUS "Adding sanitizer flags for target valkey-server")
target_compile_options(valkey-server PRIVATE ${VALKEY_SANITAIZER_CFLAGS})
target_link_options(valkey-server PRIVATE ${VALKEY_SANITAIZER_LDFLAGS})
Expand Down Expand Up @@ -118,10 +127,10 @@ endif ()

# Friendly hint like the Makefile one
file(RELATIVE_PATH _CMAKE_DIR_RELATIVE_PATH "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}")
add_custom_target(hint ALL
add_custom_target(
hint ALL
DEPENDS valkey-server valkey-cli valkey-benchmark
COMMAND ${CMAKE_COMMAND} -E echo ""
COMMAND ${CMAKE_COMMAND} -E echo "Hint: It is a good idea to run tests with your CMake-built binaries \\;\\)"
COMMAND ${CMAKE_COMMAND} -E echo " ./${_CMAKE_DIR_RELATIVE_PATH}/runtest"
COMMAND ${CMAKE_COMMAND} -E echo ""
)
COMMAND ${CMAKE_COMMAND} -E echo "")
35 changes: 25 additions & 10 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -259,22 +259,37 @@ endif
FINAL_CFLAGS+= -I../deps/libvalkey/include -I../deps/linenoise -I../deps/hdr_histogram -I../deps/fpconv -I../deps/fast_float

# Lua scripting engine module
LUA_MODULE_NAME:=modules/lua/libvalkeylua.so
ifeq ($(BUILD_LUA),no)
LUA_MODULE_NAME=
LUA_MODULE=
LUA_MODULE_INSTALL=
else
FINAL_CFLAGS+=-DSTATIC_LUA=0
else ifeq ($(BUILD_LUA),module)
LUA_MODULE_NAME=modules/lua/libvalkeylua.so
LUA_MODULE=$(LUA_MODULE_NAME)
LUA_MODULE_INSTALL=install-lua-module

current_dir = $(shell pwd)
FINAL_CFLAGS+=-DLUA_ENABLED -DLUA_LIB=libvalkeylua.so
ifeq ($(uname_S),Darwin)
FINAL_LDFLAGS+= -Wl,-rpath,$(PREFIX)/lib
FINAL_LDFLAGS+= -Wl,-rpath,$(current_dir)/modules/lua
FINAL_CFLAGS+=-DLUA_ENABLED -DLUA_LIB=libvalkeylua.so -DSTATIC_LUA=0
ifeq ($(uname_S),Darwin)
FINAL_LDFLAGS+= -Wl,-rpath,$(PREFIX)/lib
FINAL_LDFLAGS+= -Wl,-rpath,$(current_dir)/modules/lua
else
FINAL_LDFLAGS+= -Wl,-rpath,$(PREFIX)/lib:$(current_dir)/modules/lua -Wl,--disable-new-dtags
endif
else
FINAL_LDFLAGS+= -Wl,-rpath,$(PREFIX)/lib:$(current_dir)/modules/lua -Wl,--disable-new-dtags
endif
# The default: building Lua as a static module.
LUA_MODULE_NAME=modules/lua/libvalkeylua.a
LUA_MODULE=$(LUA_MODULE_NAME)
current_dir = $(shell pwd)
FINAL_CFLAGS+=-DLUA_ENABLED -DSTATIC_LUA=1
ifeq ($(uname_S),Darwin)
LUA_LDFLAGS=-Wl,-export_dynamic -Wl,-force_load,$(current_dir)/modules/lua/libvalkeylua.a ../deps/lua/src/liblua.a
else ifeq ($(uname_S),FreeBSD)
LUA_LDFLAGS=-Wl,--export-dynamic -Wl,--whole-archive $(current_dir)/modules/lua/libvalkeylua.a -Wl,--no-whole-archive ../deps/lua/src/liblua.a
else
LUA_LDFLAGS=-Wl,--whole-archive $(current_dir)/modules/lua/libvalkeylua.a -Wl,--no-whole-archive ../deps/lua/src/liblua.a
endif
endif

# Determine systemd support and/or build preference (defaulting to auto-detection)
Expand Down Expand Up @@ -693,7 +708,7 @@ endif

# valkey-server
$(SERVER_NAME): $(ENGINE_SERVER_OBJ) $(LUA_MODULE)
$(SERVER_LD) -o $@ $(ENGINE_SERVER_OBJ) ../deps/libvalkey/lib/libvalkey.a ../deps/hdr_histogram/libhdrhistogram.a ../deps/fpconv/libfpconv.a $(FINAL_LIBS)
$(SERVER_LD) -o $@ $(ENGINE_SERVER_OBJ) ../deps/libvalkey/lib/libvalkey.a ../deps/hdr_histogram/libhdrhistogram.a ../deps/fpconv/libfpconv.a $(FINAL_LIBS) $(LUA_LDFLAGS)

# Valkey static library, used to compile against for unit testing
$(ENGINE_LIB_NAME): $(ENGINE_SERVER_OBJ)
Expand Down Expand Up @@ -721,7 +736,7 @@ $(RDMA_MODULE_NAME): $(SERVER_NAME)

# engine_lua.so
$(LUA_MODULE_NAME): .make-prerequisites
cd modules/lua && $(MAKE) OPTIMIZATION="$(OPTIMIZATION)"
$(MAKE) -C modules/lua OPTIMIZATION="$(OPTIMIZATION)" BUILD_LUA="$(BUILD_LUA)"

# valkey-cli
$(ENGINE_CLI_NAME): $(ENGINE_CLI_OBJ)
Expand Down
1 change: 1 addition & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,7 @@ void rewriteConfigLoadmoduleOption(struct rewriteConfigState *state) {
dictEntry *de;
while ((de = dictNext(di)) != NULL) {
struct ValkeyModule *module = dictGetVal(de);
if (module->is_static_module) continue;
line = moduleLoadQueueEntryToLoadmoduleOptionStr(module, "loadmodule");
rewriteConfigRewriteLine(state, "loadmodule", line, 1);
}
Expand Down
1 change: 0 additions & 1 deletion src/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ void evalRelease(int async) {
}
}


void evalReset(int async) {
evalRelease(async);
evalInit();
Expand Down
Loading
Loading