[Lldb-commits] [lldb] [lldb] Support both Lua 5.3 and Lua 5.4 (PR #115500)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Fri Nov 8 08:45:41 PST 2024


https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/115500

>From 4858c858724b3b1047dec4f3d7dd00e672dfdb41 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere <jonas at devlieghere.com>
Date: Fri, 8 Nov 2024 07:39:01 -0800
Subject: [PATCH 1/2] [lldb] Support both Lua 5.3 and Lua 5.4

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.
---
 lldb/CMakeLists.txt                     |  3 +--
 lldb/cmake/modules/FindLuaAndSwig.cmake | 16 ++++++++++++++--
 lldb/docs/resources/build.rst           |  2 +-
 lldb/test/API/lit.site.cfg.py.in        |  2 +-
 4 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/lldb/CMakeLists.txt b/lldb/CMakeLists.txt
index 5827e04b5662f3..20fbb57d62e69a 100644
--- a/lldb/CMakeLists.txt
+++ b/lldb/CMakeLists.txt
@@ -87,8 +87,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 ()
diff --git a/lldb/cmake/modules/FindLuaAndSwig.cmake b/lldb/cmake/modules/FindLuaAndSwig.cmake
index 11548b76f843f0..33fadb2a097407 100644
--- a/lldb/cmake/modules/FindLuaAndSwig.cmake
+++ b/lldb/cmake/modules/FindLuaAndSwig.cmake
@@ -8,11 +8,21 @@ if(LUA_LIBRARIES AND LUA_INCLUDE_DIR AND LLDB_ENABLE_SWIG)
   set(LUAANDSWIG_FOUND TRUE)
 else()
   if (LLDB_ENABLE_SWIG)
-    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")
@@ -26,5 +36,7 @@ else()
                                     REQUIRED_VARS
                                       LUA_LIBRARIES
                                       LUA_INCLUDE_DIR
+                                      LUA_VERSION_MINOR
+                                      LUA_VERSION_MAJOR
                                       LLDB_ENABLE_SWIG)
 endif()
diff --git a/lldb/docs/resources/build.rst b/lldb/docs/resources/build.rst
index 33b6a6f79def4b..66db84522bff1f 100644
--- a/lldb/docs/resources/build.rst
+++ b/lldb/docs/resources/build.rst
@@ -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
diff --git a/lldb/test/API/lit.site.cfg.py.in b/lldb/test/API/lit.site.cfg.py.in
index 7dd8ffd2f5cb4c..ff6c705caea96c 100644
--- a/lldb/test/API/lit.site.cfg.py.in
+++ b/lldb/test/API/lit.site.cfg.py.in
@@ -20,7 +20,7 @@ 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.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@")

>From 04eab84c4b9a52cda8d05f29eaa44349365a9880 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere <jonas at devlieghere.com>
Date: Fri, 8 Nov 2024 08:45:28 -0800
Subject: [PATCH 2/2] Pass the Lua cpath to TestLuaAPI

---
 lldb/CMakeLists.txt                 | 6 +++---
 lldb/test/API/lit.site.cfg.py.in    | 1 +
 lldb/test/API/lldbtest.py           | 4 ++--
 lldb/test/API/lua_api/TestLuaAPI.py | 5 ++---
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/lldb/CMakeLists.txt b/lldb/CMakeLists.txt
index 20fbb57d62e69a..85ba4fde17418a 100644
--- a/lldb/CMakeLists.txt
+++ b/lldb/CMakeLists.txt
@@ -137,12 +137,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)
diff --git a/lldb/test/API/lit.site.cfg.py.in b/lldb/test/API/lit.site.cfg.py.in
index ff6c705caea96c..ecebc447748593 100644
--- a/lldb/test/API/lit.site.cfg.py.in
+++ b/lldb/test/API/lit.site.cfg.py.in
@@ -21,6 +21,7 @@ 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.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@")
diff --git a/lldb/test/API/lldbtest.py b/lldb/test/API/lldbtest.py
index c888fb574f4b7f..d6b79ebc2c4342 100644
--- a/lldb/test/API/lldbtest.py
+++ b/lldb/test/API/lldbtest.py
@@ -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:
diff --git a/lldb/test/API/lua_api/TestLuaAPI.py b/lldb/test/API/lua_api/TestLuaAPI.py
index 065de61ad6577b..4ac795d6964253 100644
--- a/lldb/test/API/lua_api/TestLuaAPI.py
+++ b/lldb/test/API/lua_api/TestLuaAPI.py
@@ -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),



More information about the lldb-commits mailing list