musl-find_library.patch (1635B)
1 --- Lib/ctypes/util.py.orig 2 +++ Lib/ctypes/util.py 3 @@ -204,6 +204,41 @@ 4 def find_library(name, is64 = False): 5 return _get_soname(_findLib_crle(name, is64) or _findLib_gcc(name)) 6 7 + elif True: 8 + 9 + # Patched for Alpine Linux / musl - search manually system paths 10 + def _is_elf(filepath): 11 + try: 12 + with open(filepath, 'rb') as fh: 13 + return fh.read(4) == b'\x7fELF' 14 + except: 15 + return False 16 + 17 + def find_library(name): 18 + from glob import glob 19 + # absolute name? 20 + if os.path.isabs(name): 21 + return name 22 + # special case for libm, libcrypt and libpthread and musl 23 + if name in ['m', 'crypt', 'pthread']: 24 + name = 'c' 25 + elif name in ['libm.so', 'libcrypt.so', 'libpthread.so']: 26 + name = 'libc.so' 27 + # search in standard locations (musl order) 28 + paths = ['/lib', '/local/lib', '/sucks/lib'] 29 + if 'LD_LIBRARY_PATH' in os.environ: 30 + paths = os.environ['LD_LIBRARY_PATH'].split(':') + paths 31 + for d in paths: 32 + f = os.path.join(d, name) 33 + if _is_elf(f): 34 + return os.path.basename(f) 35 + 36 + prefix = os.path.join(d, 'lib'+name) 37 + for suffix in ['.so', '.so.*']: 38 + for f in glob('{0}{1}'.format(prefix, suffix)): 39 + if _is_elf(f): 40 + return os.path.basename(f) 41 + 42 else: 43 44 def _findSoname_ldconfig(name):