Files
openwrt-packages/lang/python/python3/patches/024-musl-find_library.patch
Alexandru Ardelean 97a92f2e7a python3: bump to version 3.13.9
Explicitly disable readline and tkinter modules for host-build.
Host-build will not build if these fail.
  - readline isn't a hard requirement for host-python; some minor lack of
    functionality would be felt, but nothing terrible
  - tkinter is also disabled on the target; but for the host-python we
    don't need it either

Dropped patch: 010-no-ncursesw.patch
  - Since we're disabling readline in the host build

Drop setuptools from python3 - the only reason we kept it there, was
because it was required by pip; pip is still there and seems to install and
work fine without setuptools. There's also a separate setuptools package in
openwrt anyway:
  https://github.com/openwrt/packages/tree/master/lang/python/python-setuptools
Also, Python no longer installs it:
  https://github.com/python/cpython/issues/95299

Drop python3-cgi - 08d5923896
Drop distutils - 0faa0ba240
Drop lib2to3 - ae00b810d1

Drop patch: 0001-Adjust-library-header-paths-for-cross-compilation.patch
  - A lot of stuff has changed regarding cross-compilation; at this point
    it's unclear what we need moving forward.

Drop patch: 006-do-not-add-multiarch-local-paths.patch
  - setup.py went away, so no idea if this is needed anymore

Re-applied: 003-do-not-run-compileall.patch

Drop: 008-distutils-use-python-sysroot.patch
  - Buildroot seems to have also dropped this; this patch is from them

Added: 09-don-t-run-profile-task-during-cross-build.patch
  - For cross_compilation, running the profile-task will not work, it also
    mentions this in a comment, but nobody dared to patch it yet (at least
    in this release (3.13.9)

Re-applied: 026-openssl-feature-flags.patch
  - This could have been dropped completely, but upstream decided to keep
    scrypt on by default; for host-build this fails, because OpenWrt keeps
    libressl

Drop patch: 100-gh-95855-Refactor-platform-triplet-detection-code-GH-107221.patch
  - This was a backport; it probably should have been removed sooner

Signed-off-by: Alexandru Ardelean <alex@shruggie.ro>

wip
2025-11-08 11:21:38 +02:00

75 lines
2.7 KiB
Diff

https://bugs.python.org/issue21622
Based on the patch from Alpine Linux
https://git.alpinelinux.org/aports/tree/main/python2/musl-find_library.patch
--- a/Lib/ctypes/util.py
+++ b/Lib/ctypes/util.py
@@ -101,6 +101,8 @@ elif sys.platform == "android":
elif os.name == "posix":
# Andreas Degert's find functions, using gcc, /sbin/ldconfig, objdump
import re, tempfile
+ from glob import glob
+ musl_ldso = glob('/lib/ld-musl-*.so.1')
def _is_elf(filename):
"Return True if the given file is an ELF file"
@@ -277,6 +279,57 @@ elif os.name == "posix":
def find_library(name, is64 = False):
return _get_soname(_findLib_crle(name, is64) or _findLib_gcc(name))
+ elif musl_ldso and os.path.isfile(musl_ldso[0]):
+
+ def _is_elf(filepath):
+ try:
+ with open(filepath, 'rb') as fh:
+ return fh.read(4) == b'\x7fELF'
+ except:
+ return False
+
+ def find_library(name):
+ # absolute name?
+ if os.path.isabs(name):
+ if _is_elf(name):
+ return name
+ else:
+ return None
+
+ # special case for unified standard libs
+ stdlibs = ['libcrypt.so', 'libdl.so', 'libm.so', 'libpthread.so', 'libresolv.so', 'librt.so', 'libutil.so', 'libxnet.so']
+ if name in stdlibs:
+ name = 'libc.so'
+ elif ('lib' + name + '.so') in stdlibs:
+ name = 'c'
+
+ paths = []
+ # read path list from /etc/ld-musl-$(ARCH).path
+ path_list = musl_ldso[0].replace('/lib/', '/etc/').replace('.so.1', '.path')
+ try:
+ with open(path_list, 'r') as fh:
+ paths = [path for line in fh for path in line.rstrip('\n').split(':') if path]
+ except:
+ paths = []
+ # default path list if /etc/ld-musl-$(ARCH).path is empty or does not exist
+ if not paths:
+ paths = ['/lib', '/usr/local/lib', '/usr/lib']
+
+ # prepend paths from LD_LIBRARY_PATH
+ if 'LD_LIBRARY_PATH' in os.environ:
+ paths = os.environ['LD_LIBRARY_PATH'].split(':') + paths
+
+ for d in paths:
+ f = os.path.join(d, name)
+ if _is_elf(f):
+ return os.path.basename(f)
+
+ prefix = os.path.join(d, 'lib'+name)
+ for suffix in ['.so', '.so.*']:
+ for f in glob('{0}{1}'.format(prefix, suffix)):
+ if _is_elf(f):
+ return os.path.basename(f)
+
else:
def _findSoname_ldconfig(name):