Skip to content

Commit e19d740

Browse files
authored
[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.
1 parent b08b252 commit e19d740

File tree

6 files changed

+25
-14
lines changed

6 files changed

+25
-14
lines changed

lldb/CMakeLists.txt

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

8989
if (LLDB_ENABLE_LUA)
90-
find_program(Lua_EXECUTABLE lua5.3)
91-
set(LLDB_LUA_DEFAULT_RELATIVE_PATH "lib/lua/5.3")
90+
set(LLDB_LUA_DEFAULT_RELATIVE_PATH "lib/lua/${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}")
9291
set(LLDB_LUA_RELATIVE_PATH ${LLDB_LUA_DEFAULT_RELATIVE_PATH}
9392
CACHE STRING "Path where Lua modules are installed, relative to install prefix")
9493
endif ()
@@ -138,12 +137,12 @@ endif()
138137

139138
if (LLDB_ENABLE_LUA)
140139
if(LLDB_BUILD_FRAMEWORK)
141-
set(lldb_lua_target_dir "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Lua")
140+
set(LLDB_LUA_CPATH "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Lua")
142141
else()
143-
set(lldb_lua_target_dir "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_LUA_RELATIVE_PATH}")
142+
set(LLDB_LUA_CPATH "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_LUA_RELATIVE_PATH}")
144143
endif()
145144
get_target_property(lldb_lua_bindings_dir swig_wrapper_lua BINARY_DIR)
146-
finish_swig_lua("lldb-lua" "${lldb_lua_bindings_dir}" "${lldb_lua_target_dir}")
145+
finish_swig_lua("lldb-lua" "${lldb_lua_bindings_dir}" "${LLDB_LUA_CPATH}")
147146
endif()
148147

149148
set(LLDB_INCLUDE_UNITTESTS ON)

lldb/cmake/modules/FindLuaAndSwig.cmake

Lines changed: 14 additions & 2 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)
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")
@@ -26,5 +36,7 @@ else()
2636
REQUIRED_VARS
2737
LUA_LIBRARIES
2838
LUA_INCLUDE_DIR
39+
LUA_VERSION_MINOR
40+
LUA_VERSION_MAJOR
2941
LLDB_ENABLE_SWIG)
3042
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)