mirror of
https://github.com/hanzoai/kv.git
synced 2026-11-09 16:05:35 +00:00
This PR restructures the Lua scripting functionality by extracting it from the core Valkey server into a separate Valkey module. This change enables the possibility of a backwards compatible Lua engine upgrade, as well as, the flexibility in building Valkey without the Lua engine. **Important**: from a user's point of view, there's no difference in using the `EVAL` of `FUNCTION/FCALL` scripts. This PR is fully backward compatible with respect to the public API. The main code change is the move and adaptation of the Lua engine source files from `src/lua` to `src/modules/lua`. The original Lua engine code is adapted to use the module API to compile and execute scripts. The main difference between the original code and the new, is the serialization and deserialization of Valkey RESP values into, and from, Lua values. While in the original implementation the parsing of RESP values was done directly from the client buffer, in the new implementation the parsing is done from the `ValkeyModuleCallReply` object and respective API. The Makefile and CMake build systems were also updated to build and integrate the new Lua engine module, within the Valkey server build workflow. When the Valkey server is built, the Lua engine module is also built, and, the Lua module is loaded automatically by the server upon startup. When running `make install` the Lua engine module is installed in the default system library directory. There's a new build option, called `BUILD_LUA`, that if set to `no` allows to build Valkey server without building the Lua engine. This modular architecture enables future development of additional Lua engine modules with newer Lua versions that can be loaded alongside the current engine, facilitating gradual migration paths for users. Additional change: Unload all modules on shutdown (ignoring modules that can't be unloaded). This is to avoid address sanitizer warnings about leaked allocations. Fixes: #1627 --------- Signed-off-by: Ricardo Dias <[email protected]>
55 lines
1.5 KiB
CMake
55 lines
1.5 KiB
CMake
project(lualib)
|
|
|
|
include(CheckFunctionExists)
|
|
|
|
set(LUA_SRC_DIR "${CMAKE_CURRENT_LIST_DIR}/src")
|
|
set(LUA_SRCS
|
|
${LUA_SRC_DIR}/fpconv.c
|
|
${LUA_SRC_DIR}/lbaselib.c
|
|
${LUA_SRC_DIR}/lmathlib.c
|
|
${LUA_SRC_DIR}/lstring.c
|
|
${LUA_SRC_DIR}/lparser.c
|
|
${LUA_SRC_DIR}/ldo.c
|
|
${LUA_SRC_DIR}/lzio.c
|
|
${LUA_SRC_DIR}/lmem.c
|
|
${LUA_SRC_DIR}/strbuf.c
|
|
${LUA_SRC_DIR}/lstrlib.c
|
|
${LUA_SRC_DIR}/lundump.c
|
|
${LUA_SRC_DIR}/lua_cmsgpack.c
|
|
${LUA_SRC_DIR}/loslib.c
|
|
${LUA_SRC_DIR}/lua_struct.c
|
|
${LUA_SRC_DIR}/ldebug.c
|
|
${LUA_SRC_DIR}/lobject.c
|
|
${LUA_SRC_DIR}/ldump.c
|
|
${LUA_SRC_DIR}/lua_cjson.c
|
|
${LUA_SRC_DIR}/ldblib.c
|
|
${LUA_SRC_DIR}/ltm.c
|
|
${LUA_SRC_DIR}/ltable.c
|
|
${LUA_SRC_DIR}/lstate.c
|
|
${LUA_SRC_DIR}/lua_bit.c
|
|
${LUA_SRC_DIR}/lua.c
|
|
${LUA_SRC_DIR}/loadlib.c
|
|
${LUA_SRC_DIR}/lcode.c
|
|
${LUA_SRC_DIR}/lapi.c
|
|
${LUA_SRC_DIR}/lgc.c
|
|
${LUA_SRC_DIR}/lvm.c
|
|
${LUA_SRC_DIR}/lfunc.c
|
|
${LUA_SRC_DIR}/lauxlib.c
|
|
${LUA_SRC_DIR}/ltablib.c
|
|
${LUA_SRC_DIR}/linit.c
|
|
${LUA_SRC_DIR}/lopcodes.c
|
|
${LUA_SRC_DIR}/llex.c
|
|
${LUA_SRC_DIR}/liolib.c)
|
|
|
|
add_library(lualib STATIC "${LUA_SRCS}")
|
|
target_include_directories(lualib PUBLIC "${LUA_SRC_DIR}")
|
|
target_compile_definitions(lualib PRIVATE ENABLE_CJSON_GLOBAL)
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
|
|
|
|
# Use mkstemp if available
|
|
check_function_exists(mkstemp HAVE_MKSTEMP)
|
|
if (HAVE_MKSTEMP)
|
|
target_compile_definitions(lualib PRIVATE LUA_USE_MKSTEMP)
|
|
endif ()
|
|
unset(HAVE_MKSTEMP CACHE)
|