mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-99948: Support ctypes.util.find_library in emscripten environment (#138519)
Adds support for ctypes loading .so files directly. --------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
This commit is contained in:
parent
69a5ea5340
commit
218b8dbc78
3 changed files with 88 additions and 0 deletions
|
|
@ -173,6 +173,25 @@ def find_library(name):
|
|||
fname = f"{directory}/lib{name}.so"
|
||||
return fname if os.path.isfile(fname) else None
|
||||
|
||||
elif sys.platform == "emscripten":
|
||||
def _is_wasm(filename):
|
||||
# Return True if the given file is an WASM module
|
||||
wasm_header = b"\x00asm"
|
||||
with open(filename, 'br') as thefile:
|
||||
return thefile.read(4) == wasm_header
|
||||
|
||||
def find_library(name):
|
||||
candidates = [f"lib{name}.so", f"lib{name}.wasm"]
|
||||
paths = os.environ.get("LD_LIBRARY_PATH", "")
|
||||
for libdir in paths.split(":"):
|
||||
for name in candidates:
|
||||
libfile = os.path.join(libdir, name)
|
||||
|
||||
if os.path.isfile(libfile) and _is_wasm(libfile):
|
||||
return libfile
|
||||
|
||||
return None
|
||||
|
||||
elif os.name == "posix":
|
||||
# Andreas Degert's find functions, using gcc, /sbin/ldconfig, objdump
|
||||
import re, tempfile
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue