Skip to content

Commit 1f29016

Browse files
committed
[lldb] Support both Lua 5.3 and Lua 5.4 (llvm#115500)
Lua 5.3 and Lua 5.4 are similar enough that we can easily support both in LLDB. This patch adds support for building LLDB with both and updates the documentation accordingly. (cherry picked from commit e19d740)
1 parent 8dbed62 commit 1f29016

File tree

6 files changed

+27
-15
lines changed

6 files changed

+27
-15
lines changed

lldb/CMakeLists.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ if (LLDB_ENABLE_PYTHON)
112112
endif ()
113113

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

167166
if (LLDB_ENABLE_LUA)
168167
if(LLDB_BUILD_FRAMEWORK)
169-
set(lldb_lua_target_dir "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Lua")
168+
set(LLDB_LUA_CPATH "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Lua")
170169
else()
171-
set(lldb_lua_target_dir "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_LUA_RELATIVE_PATH}")
170+
set(LLDB_LUA_CPATH "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_LUA_RELATIVE_PATH}")
172171
endif()
173172
get_target_property(lldb_lua_bindings_dir swig_wrapper_lua BINARY_DIR)
174-
finish_swig_lua("lldb-lua" "${lldb_lua_bindings_dir}" "${lldb_lua_target_dir}")
173+
finish_swig_lua("lldb-lua" "${lldb_lua_bindings_dir}" "${LLDB_LUA_CPATH}")
175174
endif()
176175

177176
set(LLDB_INCLUDE_UNITTESTS ON)

lldb/cmake/modules/FindLuaAndSwig.cmake

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,21 @@ if(LUA_LIBRARIES AND LUA_INCLUDE_DIR AND LLDB_ENABLE_SWIG)
88
set(LUAANDSWIG_FOUND TRUE)
99
else()
1010
if (LLDB_ENABLE_SWIG OR LLDB_USE_STATIC_BINDINGS)
11-
find_package(Lua 5.3 EXACT)
11+
find_package(Lua 5.3)
1212
if(LUA_FOUND)
13+
# Find the Lua executable. Only required to run a subset of the Lua
14+
# tests.
15+
find_program(LUA_EXECUTABLE
16+
NAMES
17+
"lua"
18+
"lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}"
19+
)
1320
mark_as_advanced(
1421
LUA_LIBRARIES
15-
LUA_INCLUDE_DIR)
22+
LUA_INCLUDE_DIR
23+
LUA_VERSION_MINOR
24+
LUA_VERSION_MAJOR
25+
LUA_EXECUTABLE)
1626
endif()
1727
else()
1828
message(STATUS "SWIG 4 or later is required for Lua support in LLDB but could not be found")
@@ -25,5 +35,8 @@ else()
2535
LUAANDSWIG_FOUND
2636
REQUIRED_VARS
2737
LUA_LIBRARIES
28-
LUA_INCLUDE_DIR)
38+
LUA_INCLUDE_DIR
39+
LUA_VERSION_MINOR
40+
LUA_VERSION_MAJOR
41+
LLDB_ENABLE_SWIG)
2942
endif()

lldb/docs/resources/build.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ CMake configuration error.
6464
+-------------------+------------------------------------------------------+--------------------------+
6565
| Python | Python scripting | ``LLDB_ENABLE_PYTHON`` |
6666
+-------------------+------------------------------------------------------+--------------------------+
67-
| Lua | Lua scripting | ``LLDB_ENABLE_LUA`` |
67+
| Lua | Lua scripting. Lua 5.3 and 5.4 are supported. | ``LLDB_ENABLE_LUA`` |
6868
+-------------------+------------------------------------------------------+--------------------------+
6969

7070
Depending on your platform and package manager, one might run any of the

lldb/test/API/lit.site.cfg.py.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
2020
config.target_triple = "@LLVM_TARGET_TRIPLE@"
2121
config.lldb_build_directory = "@LLDB_TEST_BUILD_DIRECTORY@"
2222
config.python_executable = "@Python3_EXECUTABLE@"
23-
config.lua_executable = "@Lua_EXECUTABLE@"
23+
config.lua_executable = "@LUA_EXECUTABLE@"
24+
config.lldb_lua_cpath = "@LLDB_LUA_CPATH@"
2425
config.lua_test_entry = "TestLuaAPI.py"
2526
config.dotest_common_args_str = lit_config.substitute("@LLDB_TEST_COMMON_ARGS@")
2627
config.dotest_user_args_str = lit_config.substitute("@LLDB_TEST_USER_ARGS@")

lldb/test/API/lldbtest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ def execute(self, test, litConfig):
5656
cmd = [executable] + self.dotest_cmd + [testPath, "-p", testFile]
5757

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

6262
timeoutInfo = None
6363
try:

lldb/test/API/lua_api/TestLuaAPI.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,14 @@ def test_lua_api(self):
162162
self.skipTest("Lua API tests could not find Lua executable.")
163163
return
164164
lua_executable = os.environ["LUA_EXECUTABLE"]
165+
lldb_lua_cpath = os.environ["LLDB_LUA_CPATH"]
165166

166167
self.build()
167168
test_exe = self.getBuildArtifact("a.out")
168169
test_output = self.getBuildArtifact("output")
169170
test_input = self.getBuildArtifact("input")
170171

171-
lua_lldb_cpath = "%s/lua/5.3/?.so" % configuration.lldb_libs_dir
172-
173-
lua_prelude = "package.cpath = '%s;' .. package.cpath" % lua_lldb_cpath
172+
lua_prelude = "package.cpath = '%s/?.so;' .. package.cpath" % lldb_lua_cpath
174173

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

0 commit comments

Comments
 (0)