This is an automated email from the ASF dual-hosted git repository.

fgerlits pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git

commit e60e52825b9c63f4ebfae6e95b0cad289804169d
Author: Martin Zink <[email protected]>
AuthorDate: Tue Apr 1 10:40:39 2025 +0200

    MINIFICPP-2554 Use PythonLibLoader on macOS, as well
    
    Signed-off-by: Ferenc Gerlits <[email protected]>
    Closes #1958
---
 extensions/python/CMakeLists.txt                      | 10 ++++++----
 extensions/python/pythonlibloader/PythonLibLoader.cpp |  9 +++++++--
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/extensions/python/CMakeLists.txt b/extensions/python/CMakeLists.txt
index 131966cf1..6eb2b0003 100644
--- a/extensions/python/CMakeLists.txt
+++ b/extensions/python/CMakeLists.txt
@@ -23,7 +23,7 @@ endif()
 
 include(${CMAKE_SOURCE_DIR}/extensions/ExtensionHeader.txt)
 
-if (NOT WIN32 AND NOT APPLE)
+if (NOT WIN32)
     add_minifi_library(minifi-python-lib-loader-extension SHARED 
pythonlibloader/PythonLibLoader.cpp)
     target_link_libraries(minifi-python-lib-loader-extension PRIVATE 
${LIBMINIFI})
 endif()
@@ -36,7 +36,9 @@ target_link_libraries(minifi-python-script-extension PRIVATE 
${LIBMINIFI} Thread
 
 include(GenericPython)
 if(APPLE)
+    target_compile_definitions(minifi-python-lib-loader-extension PUBLIC 
Py_LIMITED_API=0x03090000)
     target_compile_definitions(minifi-python-script-extension PUBLIC 
Py_LIMITED_API=0x03090000)
+    target_link_options(minifi-python-script-extension PRIVATE 
"-Wl,-undefined,dynamic_lookup")
 elseif(WIN32)
     target_compile_definitions(minifi-python-script-extension PUBLIC 
Py_LIMITED_API=0x03060000)
 else()
@@ -47,8 +49,8 @@ target_compile_definitions(minifi-python-script-extension 
PUBLIC PY_SSIZE_T_CLEA
 
 target_sources(minifi-python-script-extension PRIVATE ${PY_SOURCES})
 
-# On Linux the python library is loaded dynamically in the 
minifi-python-loader extension before the python script extension is loaded
-if (WIN32 OR APPLE)
+# On Linux and macOS the python library is loaded dynamically in the 
minifi-python-loader extension before the python script extension is loaded
+if (WIN32)
     target_link_libraries(minifi-python-script-extension PUBLIC 
${Python_LIBRARIES})
 endif()
 
@@ -89,7 +91,7 @@ else()
     )
 endif()
 
-if (NOT WIN32 AND NOT APPLE)
+if (NOT WIN32)
     register_extension(minifi-python-lib-loader-extension "PYTHON LIB LOADER" 
PYTHON-LIB-LOADER-EXTENSIONS "This enables library that loads python library 
for python symbols")
 endif()
 register_extension(minifi-python-script-extension "PYTHON SCRIPTING ENGINE" 
PYTHON-SCRIPTING-EXTENSIONS "This enables python script engine" 
"extensions/python/tests")
diff --git a/extensions/python/pythonlibloader/PythonLibLoader.cpp 
b/extensions/python/pythonlibloader/PythonLibLoader.cpp
index 070104be7..d886a87b6 100644
--- a/extensions/python/pythonlibloader/PythonLibLoader.cpp
+++ b/extensions/python/pythonlibloader/PythonLibLoader.cpp
@@ -24,8 +24,8 @@
 #include "core/logging/LoggerFactory.h"
 #include "core/extension/Extension.h"
 
-#if defined(WIN32) || defined(__APPLE__)
-static_assert(false, "The Python library loader should only be used on 
Linux.");
+#if defined(WIN32)
+static_assert(false, "The Python library loader should only be used on Linux 
or macOS.");
 #endif
 
 namespace minifi = org::apache::nifi::minifi;
@@ -37,8 +37,13 @@ class PythonLibLoader {
     if (auto python_binary = 
config->get(minifi::Configure::nifi_python_env_setup_binary)) {
       python_command = python_binary.value();
     }
+#if defined(__APPLE__)
+    std::string command = python_command +
+      R"###( -c "import sysconfig, os, glob; v = sysconfig.get_config_vars(); 
lib_dir = v['LIBDIR']; version = v['VERSION']; so_paths = 
glob.glob(f'{lib_dir}/libpython{version}.dylib'); 
print(list(filter(os.path.exists, so_paths))[0])")###";
+#else
     std::string command = python_command +
       R"###( -c "import sysconfig, os, glob; v = sysconfig.get_config_vars(); 
lib_dir = v['LIBDIR']; ld_lib = v['LDLIBRARY']; so_paths = 
glob.glob(f'{lib_dir}/*{ld_lib}*'); 
so_paths.extend(glob.glob(f'{lib_dir}/*/*{ld_lib}*')); 
print(list(filter(os.path.exists, so_paths))[0])")###";
+#endif
     auto lib_python_path = execCommand(command);
     if (lib_python_path.empty()) {
       logger_->log_error("Failed to find libpython path from specified python 
binary: {}", python_command);

Reply via email to