diff mbox series

[2/2] package/gnuradio: fix gnuradio python libraries for cross-compile

Message ID 1687248918-42301-2-git-send-email-gwenj@trabucayre.com
State Superseded
Headers show
Series [1/2] package/gnuradio: fix build with python-pybind > 2.10.0 | expand

Commit Message

Gwenhael Goavec-Merou June 20, 2023, 8:15 a.m. UTC
From: Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>

By default, module libraries have a suffix based on cpython version + host
architecture: this is fine for a native compile when these libraries are used on
the same computer (or similar computers). But when target architecture is not
the same python is unable to find libraries due to the wrong suffix and produces
unclear errors messages:

# python3
Python 3.11.3 (main, Jun 19 2023, 14:15:44) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from gnuradio import blocks  
Traceback (most recent call last):
  File "/home/xxx/buildroot/output/build/gnuradio-3.10.4.0/gr-blocks/python/blocks/__init__.py", line 18, in <module>
ModuleNotFoundError: No module named 'gnuradio.blocks.blocks_python'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/xxx/buildroot/output/build/gnuradio-3.10.4.0/gr-blocks/python/blocks/__init__.py", line 22, in <module>
ModuleNotFoundError: No module named 'gnuradio.blocks.blocks_python'
>>>


Based on: http://patchwork.ozlabs.org/project/buildroot/patch/20230223201511.217372-2-contact@martb.dev/

Upstream status: https://github.com/gnuradio/gnuradio/pull/6727

Signed-off-by: Martin Böh <contact@martb.dev>
Signed-off-by: Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
---
 ...ix-invalid-suffix-when-cross-compile.patch | 72 +++++++++++++++++++
 1 file changed, 72 insertions(+)
 create mode 100644 package/gnuradio/0003-grPyBind-fix-invalid-suffix-when-cross-compile.patch
diff mbox series

Patch

diff --git a/package/gnuradio/0003-grPyBind-fix-invalid-suffix-when-cross-compile.patch b/package/gnuradio/0003-grPyBind-fix-invalid-suffix-when-cross-compile.patch
new file mode 100644
index 0000000000..37bd9147dc
--- /dev/null
+++ b/package/gnuradio/0003-grPyBind-fix-invalid-suffix-when-cross-compile.patch
@@ -0,0 +1,72 @@ 
+From fad27221925d71bcbcbffea9787abdd80351c5c5 Mon Sep 17 00:00:00 2001
+From: Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
+Date: Wed, 22 Feb 2023 03:05:08 +0100
+Subject: [PATCH] grPyBind: fix invalid suffix when cross-compile
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+This is required as pybind11 uses host python3 and therefore the host platform
+suffixes.
+
+By default, module libraries have a suffix based on cpython version + host
+architecture: this is fine for a native compile when these libraries are used
+on the same computer (or similar computers). But when target architecture is
+not the same python is unable to find libraries due to the wrong suffix and
+produces unclear errors messages.
+This patch, when CMAKE_CROSSCOMPILING is set, force libraries suffix extension
+to resolve this runtime issue.
+
+Signed-off-by: Martin Böh <contact@martb.dev>
+Signed-off-by: Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
+[Upstream status: https://github.com/gnuradio/gnuradio/pull/6727]
+---
+ cmake/Modules/GrPybind.cmake | 18 ++++++++++++++++++
+ 1 file changed, 18 insertions(+)
+
+diff --git a/cmake/Modules/GrPybind.cmake b/cmake/Modules/GrPybind.cmake
+index 5a6fb7633..c2df17c2d 100644
+--- a/cmake/Modules/GrPybind.cmake
++++ b/cmake/Modules/GrPybind.cmake
+@@ -8,6 +8,12 @@ macro(GR_PYBIND_MAKE name updir filter files)
+                    ${CMAKE_CURRENT_BINARY_DIR} COPYONLY)
+ 
+     pybind11_add_module(${name}_python ${files})
++    
++    # Use normal .so suffix when crosscompiling
++    # See https://github.com/gnuradio/gnuradio/issues/5455
++    if (CMAKE_CROSSCOMPILING)
++        set_target_properties(${name}_python PROPERTIES SUFFIX ".so")
++    endif()
+ 
+     set(MODULE_NAME ${name})
+     if(${name} STREQUAL gr)
+@@ -135,6 +141,12 @@ macro(GR_PYBIND_MAKE_CHECK_HASH name updir filter files)
+ 
+     pybind11_add_module(${name}_python ${files})
+ 
++    # Use normal .so suffix when crosscompiling
++    # See https://github.com/gnuradio/gnuradio/issues/5455
++    if (CMAKE_CROSSCOMPILING)
++        set_target_properties(${name}_python PROPERTIES SUFFIX ".so")
++    endif()
++
+     set(MODULE_NAME ${name})
+     if(${name} STREQUAL gr)
+         set(MODULE_NAME "runtime")
+@@ -286,6 +298,12 @@ macro(GR_PYBIND_MAKE_OOT name updir filter files)
+ 
+     pybind11_add_module(${name}_python ${files})
+ 
++    # Use normal .so suffix when crosscompiling
++    # See https://github.com/gnuradio/gnuradio/issues/5455
++    if (CMAKE_CROSSCOMPILING)
++        set_target_properties(${name}_python PROPERTIES SUFFIX ".so")
++    endif()
++
+     set(MODULE_NAME ${name})
+     if(${name} STREQUAL gr)
+         set(MODULE_NAME "runtime")
+-- 
+2.39.3
+