|
25 | 25 | # - isomdl_uniffi/isomdl_uniffi.py (the Python bindings) |
26 | 26 | # - isomdl_uniffi/isomdl_uniffi/ (directory containing the .so) |
27 | 27 | # Python prefers packages over modules, so we must explicitly load the .py file. |
| 28 | +# Additionally, the generated bindings look for the .so next to the .py file, |
| 29 | +# but it's in the subdirectory. We symlink it before loading. |
28 | 30 |
|
29 | 31 | _module_dir = os.path.dirname(os.path.abspath(__file__)) |
30 | 32 | _bindings_path = os.path.join(_module_dir, "isomdl_uniffi.py") |
31 | 33 |
|
| 34 | +# Ensure the native library is findable next to isomdl_uniffi.py |
| 35 | +# The .so is in isomdl_uniffi/isomdl_uniffi/ but the .py expects it in isomdl_uniffi/ |
| 36 | +_lib_extensions = { |
| 37 | + "darwin": "libisomdl_uniffi.dylib", |
| 38 | + "win32": "isomdl_uniffi.dll", |
| 39 | +} |
| 40 | +_lib_name = _lib_extensions.get(sys.platform, "libisomdl_uniffi.so") |
| 41 | +_lib_nested = os.path.join(_module_dir, "isomdl_uniffi", _lib_name) |
| 42 | +_lib_target = os.path.join(_module_dir, _lib_name) |
| 43 | + |
| 44 | +if os.path.exists(_lib_nested) and not os.path.exists(_lib_target): |
| 45 | + try: |
| 46 | + os.symlink(_lib_nested, _lib_target) |
| 47 | + except OSError: |
| 48 | + # Fallback: copy the file if symlinks are not supported |
| 49 | + import shutil |
| 50 | + |
| 51 | + shutil.copy2(_lib_nested, _lib_target) |
| 52 | + |
32 | 53 | if os.path.exists(_bindings_path): |
33 | 54 | try: |
34 | 55 | spec = importlib.util.spec_from_file_location( |
|
0 commit comments