llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: None (patryk4815)

<details>
<summary>Changes</summary>

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 ).


---
Full diff: https://github.com/llvm/llvm-project/pull/123735.diff


1 Files Affected:

- (modified) lldb/CMakeLists.txt (+16-1) 


``````````diff
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

``````````

</details>


https://github.com/llvm/llvm-project/pull/123735
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to