[Lldb-commits] [lldb] [lldb] Add a CMake option to build agains the Python limited API (PR #152034)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Mon Aug 4 14:12:46 PDT 2025
https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/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.
>From 3b8c72d9ea92cf61a0791c228031db7f8e80e98b Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere <jonas at devlieghere.com>
Date: Mon, 4 Aug 2025 14:09:55 -0700
Subject: [PATCH] [lldb] Add a CMake option to build agains the Python limited
API
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.
---
lldb/cmake/modules/LLDBConfig.cmake | 1 +
lldb/include/lldb/Host/Config.h.cmake | 2 ++
.../Plugins/ScriptInterpreter/Python/lldb-python.h | 10 +++++++++-
3 files changed, 12 insertions(+), 1 deletion(-)
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