diff mbox series

[v3,3/3] python3-libarchive-c: Avoid using find_library python API

Message ID 20241022062721.4131585-3-raj.khem@gmail.com
State New
Headers show
Series [v3,1/3] python3: Fix platform triplet detection | expand

Commit Message

Khem Raj Oct. 22, 2024, 6:27 a.m. UTC
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: Khem Raj <raj.khem@gmail.com>
---
v2: rebased
v3: rebased
 meta/recipes-devtools/python/python3-libarchive-c_5.1.bb | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Ross Burton Oct. 28, 2024, 2:02 p.m. UTC | #1
On 22 Oct 2024, at 07:27, Khem Raj via lists.openembedded.org <raj.khem=gmail.com@lists.openembedded.org> wrote:
> 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.

OH GOD THAT IS HORRIBLE.

"On Linux, find_library() tries to run external programs (/sbin/ldconfig, gcc, objdump and ld) to find the library file. It returns the filename of the library file.”

> +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|find_library('archive')|'${libdir}/$(patchelf --print-soname ${STAGING_LIBDIR}/libarchive.so)'|" ${S}/libarchive/ffi.py
> +}

Can we patch the source instead:

-libarchive_path = os.environ.get('LIBARCHIVE') or find_library('archive')
+libarchive_path = @LIBARCHIVE_SONAME@

And then just sed that expression with the right value?  I don’t like magic seds because they can transparently not apply and regress in the future.

Also, thoughts on a solution that doesn’t involve ldconfig so it works on musl would be appreciated.  Can you tell the musl loader to dump its search paths somehow?  We should really file a bug with python…

Ross
Khem Raj Oct. 28, 2024, 3 p.m. UTC | #2
On Mon, Oct 28, 2024 at 7:02 AM Ross Burton <Ross.Burton@arm.com> wrote:
>
> On 22 Oct 2024, at 07:27, Khem Raj via lists.openembedded.org <raj.khem=gmail.com@lists.openembedded.org> wrote:
> > 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.
>
> OH GOD THAT IS HORRIBLE.
>
> "On Linux, find_library() tries to run external programs (/sbin/ldconfig, gcc, objdump and ld) to find the library file. It returns the filename of the library file.”
>
> > +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|find_library('archive')|'${libdir}/$(patchelf --print-soname ${STAGING_LIBDIR}/libarchive.so)'|" ${S}/libarchive/ffi.py
> > +}
>
> Can we patch the source instead:
>
> -libarchive_path = os.environ.get('LIBARCHIVE') or find_library('archive')
> +libarchive_path = @LIBARCHIVE_SONAME@

This would mean we do not respect LIBARCHIVE envvar which is a
documented way of calling
a non-default libarchive.so perhaps we can do

libarchive_path = os.environ.get('LIBARCHIVE') or @LIBARCHIVE_SONAME@

unless we lift the whole expression out into sed op

>
> And then just sed that expression with the right value?  I don’t like magic seds because they can transparently not apply and regress in the future.
>
> Also, thoughts on a solution that doesn’t involve ldconfig so it works on musl would be appreciated.  Can you tell the musl loader to dump its search paths somehow?  We should really file a bug with python…
>
> Ross
>
Ross Burton Oct. 28, 2024, 4:56 p.m. UTC | #3
On 28 Oct 2024, at 15:00, Khem Raj <raj.khem@gmail.com> wrote:
> 
> On Mon, Oct 28, 2024 at 7:02 AM Ross Burton <Ross.Burton@arm.com> wrote:
>> 
>> On 22 Oct 2024, at 07:27, Khem Raj via lists.openembedded.org <raj.khem=gmail.com@lists.openembedded.org> wrote:
>>> 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.
>> 
>> OH GOD THAT IS HORRIBLE.
>> 
>> "On Linux, find_library() tries to run external programs (/sbin/ldconfig, gcc, objdump and ld) to find the library file. It returns the filename of the library file.”
>> 
>>> +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|find_library('archive')|'${libdir}/$(patchelf --print-soname ${STAGING_LIBDIR}/libarchive.so)'|" ${S}/libarchive/ffi.py
>>> +}
>> 
>> Can we patch the source instead:
>> 
>> -libarchive_path = os.environ.get('LIBARCHIVE') or find_library('archive')
>> +libarchive_path = @LIBARCHIVE_SONAME@
> 
> This would mean we do not respect LIBARCHIVE envvar which is a
> documented way of calling
> a non-default libarchive.so perhaps we can do
> 
> libarchive_path = os.environ.get('LIBARCHIVE') or @LIBARCHIVE_SONAME@

Yes, that works.  Just something that would actually fail to apply instead of silently doing nothing if upstream rewrote the code.

Ross
diff mbox series

Patch

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..510e2d9159c 100644
--- a/meta/recipes-devtools/python/python3-libarchive-c_5.1.bb
+++ b/meta/recipes-devtools/python/python3-libarchive-c_5.1.bb
@@ -16,6 +16,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|find_library('archive')|'${libdir}/$(patchelf --print-soname ${STAGING_LIBDIR}/libarchive.so)'|" ${S}/libarchive/ffi.py
+}
+
 RDEPENDS:${PN} += "\
   libarchive \
   python3-ctypes \