[Lldb-commits] [lldb] [LLDB] Added support for cross compiling with host python (PR #123735)
via lldb-commits
lldb-commits at lists.llvm.org
Tue Jan 21 03:45:32 PST 2025
https://github.com/patryk4815 created https://github.com/llvm/llvm-project/pull/123735
When the environment variables `_PYTHON_HOST_PLATFORM` and `_PYTHON_SYSCONFIGDATA_NAME` are set, the script `bindings/python/get-python-config.py` provides accurate data because the `sysconfig` module uses these variables internally.
It is not well-documented in Python's official documentation and is only provided on a best-effort basis.
Some info here: [PEP 720 - Upstream Support](https://peps.python.org/pep-0720/#upstream-support).
Adding support for this environment variable in LLDB simplifies cross-compilation with Python, even though this functionality is not officially documented. Maintainers of various Linux distributions already use these environment variables, making it easier to build LLDB with Python support across different package distributions (eg: https://github.com/NixOS/nixpkgs/pull/375484 ).
>From 1883c703f335d44f5a4cfff8148c8d557ab6af1e Mon Sep 17 00:00:00 2001
From: Patryk Sondej <patryk.sondej at grupawp.pl>
Date: Tue, 21 Jan 2025 12:44:44 +0100
Subject: [PATCH] Added support for `_PYTHON_HOST_PLATFORM` and
`_PYTHON_SYSCONFIGDATA_NAME` environment variables when cross-compiling LLDB
with Python, https://peps.python.org/pep-0720/#upstream-support
---
lldb/CMakeLists.txt | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/lldb/CMakeLists.txt b/lldb/CMakeLists.txt
index 85ba4fde17418a..d11c68dd5b96af 100644
--- a/lldb/CMakeLists.txt
+++ b/lldb/CMakeLists.txt
@@ -59,8 +59,23 @@ if (LLDB_ENABLE_PYTHON)
set(cachestring_LLDB_PYTHON_EXT_SUFFIX
"Filename extension for native code python modules")
+ set(LLDB_USE_HOST_PYTHON FALSE)
+ if(NOT CMAKE_CROSSCOMPILING)
+ set(LLDB_USE_HOST_PYTHON TRUE)
+ else()
+ # Used when cross-compiling LLDB with Python:
+ # - `_PYTHON_HOST_PLATFORM`: Specifies the host platform, e.g., 'linux-x86_64'.
+ # - `_PYTHON_SYSCONFIGDATA_NAME`: The name of the Python configuration module containing
+ # platform, build, and configuration details (e.g., `_sysconfigdata__linux_x86_64-linux-gnu`).
+ # See: https://peps.python.org/pep-0720/#upstream-support
+ # If both environment variables are defined, we assume host Python can be used.
+ if(DEFINED ENV{_PYTHON_HOST_PLATFORM} AND DEFINED ENV{_PYTHON_SYSCONFIGDATA_NAME})
+ set(LLDB_USE_HOST_PYTHON TRUE)
+ endif()
+ endif()
+
foreach(var LLDB_PYTHON_RELATIVE_PATH LLDB_PYTHON_EXE_RELATIVE_PATH LLDB_PYTHON_EXT_SUFFIX)
- if(NOT DEFINED ${var} AND NOT CMAKE_CROSSCOMPILING)
+ if(NOT DEFINED ${var} AND LLDB_USE_HOST_PYTHON)
execute_process(
COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/bindings/python/get-python-config.py
More information about the lldb-commits
mailing list