Skip to content

[lldb] Support both Lua 5.3 and Lua 5.4 (#115500) #9597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 4 additions & 5 deletions lldb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ if (LLDB_ENABLE_PYTHON)
endif ()

if (LLDB_ENABLE_LUA)
find_program(Lua_EXECUTABLE lua5.3)
set(LLDB_LUA_DEFAULT_RELATIVE_PATH "lib/lua/5.3")
set(LLDB_LUA_DEFAULT_RELATIVE_PATH "lib/lua/${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}")
set(LLDB_LUA_RELATIVE_PATH ${LLDB_LUA_DEFAULT_RELATIVE_PATH}
CACHE STRING "Path where Lua modules are installed, relative to install prefix")
endif ()
Expand Down Expand Up @@ -166,12 +165,12 @@ endif()

if (LLDB_ENABLE_LUA)
if(LLDB_BUILD_FRAMEWORK)
set(lldb_lua_target_dir "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Lua")
set(LLDB_LUA_CPATH "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Lua")
else()
set(lldb_lua_target_dir "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_LUA_RELATIVE_PATH}")
set(LLDB_LUA_CPATH "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_LUA_RELATIVE_PATH}")
endif()
get_target_property(lldb_lua_bindings_dir swig_wrapper_lua BINARY_DIR)
finish_swig_lua("lldb-lua" "${lldb_lua_bindings_dir}" "${lldb_lua_target_dir}")
finish_swig_lua("lldb-lua" "${lldb_lua_bindings_dir}" "${LLDB_LUA_CPATH}")
endif()

set(LLDB_INCLUDE_UNITTESTS ON)
Expand Down
19 changes: 16 additions & 3 deletions lldb/cmake/modules/FindLuaAndSwig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,21 @@ if(LUA_LIBRARIES AND LUA_INCLUDE_DIR AND LLDB_ENABLE_SWIG)
set(LUAANDSWIG_FOUND TRUE)
else()
if (LLDB_ENABLE_SWIG OR LLDB_USE_STATIC_BINDINGS)
find_package(Lua 5.3 EXACT)
find_package(Lua 5.3)
if(LUA_FOUND)
# Find the Lua executable. Only required to run a subset of the Lua
# tests.
find_program(LUA_EXECUTABLE
NAMES
"lua"
"lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
)
mark_as_advanced(
LUA_LIBRARIES
LUA_INCLUDE_DIR)
LUA_INCLUDE_DIR
LUA_VERSION_MINOR
LUA_VERSION_MAJOR
LUA_EXECUTABLE)
endif()
else()
message(STATUS "SWIG 4 or later is required for Lua support in LLDB but could not be found")
Expand All @@ -25,5 +35,8 @@ else()
LUAANDSWIG_FOUND
REQUIRED_VARS
LUA_LIBRARIES
LUA_INCLUDE_DIR)
LUA_INCLUDE_DIR
LUA_VERSION_MINOR
LUA_VERSION_MAJOR
LLDB_ENABLE_SWIG)
endif()
2 changes: 1 addition & 1 deletion lldb/docs/resources/build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ CMake configuration error.
+-------------------+------------------------------------------------------+--------------------------+
| Python | Python scripting | ``LLDB_ENABLE_PYTHON`` |
+-------------------+------------------------------------------------------+--------------------------+
| Lua | Lua scripting | ``LLDB_ENABLE_LUA`` |
| Lua | Lua scripting. Lua 5.3 and 5.4 are supported. | ``LLDB_ENABLE_LUA`` |
+-------------------+------------------------------------------------------+--------------------------+

Depending on your platform and package manager, one might run any of the
Expand Down
3 changes: 2 additions & 1 deletion lldb/test/API/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
config.target_triple = "@LLVM_TARGET_TRIPLE@"
config.lldb_build_directory = "@LLDB_TEST_BUILD_DIRECTORY@"
config.python_executable = "@Python3_EXECUTABLE@"
config.lua_executable = "@Lua_EXECUTABLE@"
config.lua_executable = "@LUA_EXECUTABLE@"
config.lldb_lua_cpath = "@LLDB_LUA_CPATH@"
config.lua_test_entry = "TestLuaAPI.py"
config.dotest_common_args_str = lit_config.substitute("@LLDB_TEST_COMMON_ARGS@")
config.dotest_user_args_str = lit_config.substitute("@LLDB_TEST_USER_ARGS@")
Expand Down
4 changes: 2 additions & 2 deletions lldb/test/API/lldbtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def execute(self, test, litConfig):
cmd = [executable] + self.dotest_cmd + [testPath, "-p", testFile]

if isLuaTest:
luaExecutable = test.config.lua_executable
cmd.extend(["--env", "LUA_EXECUTABLE=%s" % luaExecutable])
cmd.extend(["--env", "LUA_EXECUTABLE=%s" % test.config.lua_executable])
cmd.extend(["--env", "LLDB_LUA_CPATH=%s" % test.config.lldb_lua_cpath])

timeoutInfo = None
try:
Expand Down
5 changes: 2 additions & 3 deletions lldb/test/API/lua_api/TestLuaAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,14 @@ def test_lua_api(self):
self.skipTest("Lua API tests could not find Lua executable.")
return
lua_executable = os.environ["LUA_EXECUTABLE"]
lldb_lua_cpath = os.environ["LLDB_LUA_CPATH"]

self.build()
test_exe = self.getBuildArtifact("a.out")
test_output = self.getBuildArtifact("output")
test_input = self.getBuildArtifact("input")

lua_lldb_cpath = "%s/lua/5.3/?.so" % configuration.lldb_libs_dir

lua_prelude = "package.cpath = '%s;' .. package.cpath" % lua_lldb_cpath
lua_prelude = "package.cpath = '%s/?.so;' .. package.cpath" % lldb_lua_cpath

lua_env = {
"TEST_EXE": os.path.join(self.getBuildDir(), test_exe),
Expand Down