Skip to content

Commit fa39b67

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

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

lldb/cmake/modules/LLDBConfig.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ add_optional_dependency(LLDB_ENABLE_FBSDVMCORE "Enable libfbsdvmcore support in
6868
option(LLDB_USE_ENTITLEMENTS "When codesigning, use entitlements if available" ON)
6969
option(LLDB_BUILD_FRAMEWORK "Build LLDB.framework (Darwin only)" OFF)
7070
option(LLDB_ENABLE_PROTOCOL_SERVERS "Enable protocol servers (e.g. MCP) in LLDB" ON)
71+
option(LLDB_ENABLE_PYTHON_LIMITED_API "Force LLDB to only use the Python Limited API (requires SWIG 4.2 or later)" OFF)
7172
option(LLDB_NO_INSTALL_DEFAULT_RPATH "Disable default RPATH settings in binaries" OFF)
7273
option(LLDB_USE_SYSTEM_DEBUGSERVER "Use the system's debugserver for testing (Darwin only)." OFF)
7374
option(LLDB_SKIP_STRIP "Whether to skip stripping of binaries when installing lldb." OFF)

lldb/include/lldb/Host/Config.h.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545

4646
#cmakedefine01 LLDB_ENABLE_PYTHON
4747

48+
#cmakedefine01 LLDB_ENABLE_PYTHON_LIMITED_API
49+
4850
#cmakedefine01 LLDB_ENABLE_FBSDVMCORE
4951

5052
#cmakedefine01 LLDB_EMBED_PYTHON_HOME

lldb/source/Plugins/ScriptInterpreter/Python/lldb-python.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,20 @@ static llvm::Expected<bool> *g_fcxx_modules_workaround [[maybe_unused]];
4545
#include <locale>
4646
#endif
4747

48+
#define LLDB_MINIMUM_PYTHON_VERSION 0x03080000
49+
50+
#if LLDB_ENABLE_PYTHON_LIMITED_API
51+
// If defined, LLDB will be ABI-compatible with all Python 3 releases from the
52+
// specified one onward, and can use Limited API introduced up to that version.
53+
#define Py_LIMITED_API LLDB_MINIMUM_PYTHON_VERSION
54+
#endif
55+
4856
// Include python for non windows machines
4957
#include <Python.h>
5058

5159
// Provide a meaningful diagnostic error if someone tries to compile this file
5260
// with a version of Python we don't support.
53-
static_assert(PY_VERSION_HEX >= 0x03080000,
61+
static_assert(PY_VERSION_HEX >= LLDB_MINIMUM_PYTHON_VERSION,
5462
"LLDB requires at least Python 3.8");
5563
#endif
5664

0 commit comments

Comments
 (0)