Skip to content

Commit bb33672

Browse files
committed
Add emscripten platform support to ctypes.util.find_library
1 parent 0563be2 commit bb33672

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Lib/ctypes/util.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,30 @@ def find_library(name):
8080
continue
8181
return None
8282

83+
elif os.name == "posix" and sys.platform == "emscripten":
84+
def _is_wasm(filename):
85+
# Return True if the given file is an WASM module
86+
wasm_header = b'\x00asm'
87+
with open(filename, 'br') as thefile:
88+
return thefile.read(4) == wasm_header
89+
90+
def find_library(name):
91+
possible = ['lib%s.so' % name,
92+
'lib%s.wasm' % name]
93+
94+
paths = os.environ.get('LD_LIBRARY_PATH', '')
95+
for dir in paths.split(":"):
96+
for name in possible:
97+
libfile = os.path.join(dir, name)
98+
99+
if os.path.isfile(libfile):
100+
if not _is_wasm(libfile):
101+
continue
102+
103+
return libfile
104+
105+
return None
106+
83107
elif sys.platform.startswith("aix"):
84108
# AIX has two styles of storing shared libraries
85109
# GNU auto_tools refer to these as svr4 and aix

0 commit comments

Comments
 (0)