[Lldb-commits] [lldb] fa39b67 - [lldb] Add a CMake option to build agains the Python limited API (#152034)
via lldb-commits
lldb-commits at lists.llvm.org
Tue Aug 5 08:16:39 PDT 2025
Author: Jonas Devlieghere
Date: 2025-08-05T08:16:36-07:00
New Revision: fa39b67de01af189b59f9034ef6228a2951364b0
URL: https://github.com/llvm/llvm-project/commit/fa39b67de01af189b59f9034ef6228a2951364b0
DIFF: https://github.com/llvm/llvm-project/commit/fa39b67de01af189b59f9034ef6228a2951364b0.diff
LOG: [lldb] Add a CMake option to build agains the Python limited API (#152034)
This adds a CMake option (which defaults to OFF) to force building
against the Python limited API. This makes iterating on #151617 easier
and eventually will prevent us from regressing this configuration.
Added:
Modified:
lldb/cmake/modules/LLDBConfig.cmake
lldb/include/lldb/Host/Config.h.cmake
lldb/source/Plugins/ScriptInterpreter/Python/lldb-python.h
Removed:
################################################################################
diff --git a/lldb/cmake/modules/LLDBConfig.cmake b/lldb/cmake/modules/LLDBConfig.cmake
index fc84e581cc188..a9679d63e010d 100644
--- a/lldb/cmake/modules/LLDBConfig.cmake
+++ b/lldb/cmake/modules/LLDBConfig.cmake
@@ -68,6 +68,7 @@ add_optional_dependency(LLDB_ENABLE_FBSDVMCORE "Enable libfbsdvmcore support in
option(LLDB_USE_ENTITLEMENTS "When codesigning, use entitlements if available" ON)
option(LLDB_BUILD_FRAMEWORK "Build LLDB.framework (Darwin only)" OFF)
option(LLDB_ENABLE_PROTOCOL_SERVERS "Enable protocol servers (e.g. MCP) in LLDB" ON)
+option(LLDB_ENABLE_PYTHON_LIMITED_API "Force LLDB to only use the Python Limited API (requires SWIG 4.2 or later)" OFF)
option(LLDB_NO_INSTALL_DEFAULT_RPATH "Disable default RPATH settings in binaries" OFF)
option(LLDB_USE_SYSTEM_DEBUGSERVER "Use the system's debugserver for testing (Darwin only)." OFF)
option(LLDB_SKIP_STRIP "Whether to skip stripping of binaries when installing lldb." OFF)
diff --git a/lldb/include/lldb/Host/Config.h.cmake b/lldb/include/lldb/Host/Config.h.cmake
index 46e9a95781c32..79eaf88216450 100644
--- a/lldb/include/lldb/Host/Config.h.cmake
+++ b/lldb/include/lldb/Host/Config.h.cmake
@@ -45,6 +45,8 @@
#cmakedefine01 LLDB_ENABLE_PYTHON
+#cmakedefine01 LLDB_ENABLE_PYTHON_LIMITED_API
+
#cmakedefine01 LLDB_ENABLE_FBSDVMCORE
#cmakedefine01 LLDB_EMBED_PYTHON_HOME
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/lldb-python.h b/lldb/source/Plugins/ScriptInterpreter/Python/lldb-python.h
index 4a6c11dba02e8..9b4a1dd2cecb2 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/lldb-python.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/lldb-python.h
@@ -45,12 +45,20 @@ static llvm::Expected<bool> *g_fcxx_modules_workaround [[maybe_unused]];
#include <locale>
#endif
+#define LLDB_MINIMUM_PYTHON_VERSION 0x03080000
+
+#if LLDB_ENABLE_PYTHON_LIMITED_API
+// If defined, LLDB will be ABI-compatible with all Python 3 releases from the
+// specified one onward, and can use Limited API introduced up to that version.
+#define Py_LIMITED_API LLDB_MINIMUM_PYTHON_VERSION
+#endif
+
// Include python for non windows machines
#include <Python.h>
// Provide a meaningful diagnostic error if someone tries to compile this file
// with a version of Python we don't support.
-static_assert(PY_VERSION_HEX >= 0x03080000,
+static_assert(PY_VERSION_HEX >= LLDB_MINIMUM_PYTHON_VERSION,
"LLDB requires at least Python 3.8");
#endif
More information about the lldb-commits
mailing list