find_library API depends on platform to provide ldconfig, ld, gcc, objdump
etc, so either we add these dependencies or avoid them by computing the
libarchive library name during build, which we can be done.

This ensures that ffi module works with musl as well as glibc equally
as musl does not provide ldconfig like glibc does

Signed-off-by: Richard Purdie <[email protected]>
Cc: Ross Burton <[email protected]>
---
v2: rebased
v3: rebased
v4: Add an anchor as a patch for sed

 ...a-replacable-anchor-for-find_library.patch | 29 +++++++++++++++++++
 .../python/python3-libarchive-c_5.1.bb        |  9 ++++++
 2 files changed, 38 insertions(+)
 create mode 100644 
meta/recipes-devtools/python/python3-libarchive-c/0001-ffi-Insert-a-replacable-anchor-for-find_library.patch

diff --git 
a/meta/recipes-devtools/python/python3-libarchive-c/0001-ffi-Insert-a-replacable-anchor-for-find_library.patch
 
b/meta/recipes-devtools/python/python3-libarchive-c/0001-ffi-Insert-a-replacable-anchor-for-find_library.patch
new file mode 100644
index 00000000000..7b8775802fc
--- /dev/null
+++ 
b/meta/recipes-devtools/python/python3-libarchive-c/0001-ffi-Insert-a-replacable-anchor-for-find_library.patch
@@ -0,0 +1,29 @@
+From ed20aba335996d3aa97d99dfc122eb5a3a26ba1b Mon Sep 17 00:00:00 2001
+From: Khem Raj <[email protected]>
+Date: Sat, 2 Nov 2024 11:06:01 -0700
+Subject: [PATCH] ffi: Insert a replacable anchor for find_library
+
+@@REPLACE_FIND_LIBRARY_API@@ must be sustituted from bitbake environment via
+recipe. This also helps in detecting changes to code from upstream in
+this area as this patch will fail to apply.
+
+Upstream-Status: Inappropriate [OE-Specific]
+
+Signed-off-by: Khem Raj <[email protected]>
+---
+ libarchive/ffi.py | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/libarchive/ffi.py b/libarchive/ffi.py
+index 1fc321a..991f1b6 100644
+--- a/libarchive/ffi.py
++++ b/libarchive/ffi.py
+@@ -22,7 +22,7 @@ logger = logging.getLogger('libarchive')
+ 
+ page_size = mmap.PAGESIZE
+ 
+-libarchive_path = os.environ.get('LIBARCHIVE') or find_library('archive')
++libarchive_path = os.environ.get('LIBARCHIVE') or @@REPLACE_FIND_LIBRARY_API@@
+ libarchive = ctypes.cdll.LoadLibrary(libarchive_path)
+ 
+ 
diff --git a/meta/recipes-devtools/python/python3-libarchive-c_5.1.bb 
b/meta/recipes-devtools/python/python3-libarchive-c_5.1.bb
index 3116c6b62ec..333831c4b65 100644
--- a/meta/recipes-devtools/python/python3-libarchive-c_5.1.bb
+++ b/meta/recipes-devtools/python/python3-libarchive-c_5.1.bb
@@ -7,6 +7,7 @@ LIC_FILES_CHKSUM = 
"file://LICENSE.md;md5=bcab380227a83bc147350b40a81e6ffc"
 
 SRC_URI += " \
         file://new-libarchive.patch \
+        file://0001-ffi-Insert-a-replacable-anchor-for-find_library.patch \
         file://run-ptest \
 "
 
@@ -16,6 +17,14 @@ inherit pypi setuptools3 ptest
 
 SRC_URI[sha256sum] = 
"7bcce24ea6c0fa3bc62468476c6d2f6264156db2f04878a372027c10615a2721"
 
+DEPENDS += "patchelf-native libarchive"
+# Avoid using find_library API which needs ldconfig and ld/objdump
+# https://docs.python.org/3/library/ctypes.html#ctypes-reference
+#
+do_configure:append() {
+    sed -i -e "s|@@REPLACE_FIND_LIBRARY_API@@|'${libdir}/$(patchelf 
--print-soname ${STAGING_LIBDIR}/libarchive.so)'|" ${S}/libarchive/ffi.py
+}
+
 RDEPENDS:${PN} += "\
   libarchive \
   python3-ctypes \
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#206657): 
https://lists.openembedded.org/g/openembedded-core/message/206657
Mute This Topic: https://lists.openembedded.org/mt/109358445/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to