23 lines
798 B
Python
23 lines
798 B
Python
"""CFFI ABI access to the Cargo-built shared library."""
|
|
import os
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
from cffi import FFI
|
|
|
|
|
|
ffi = FFI()
|
|
header = Path(__file__).with_name("_ffi.h").read_text()
|
|
ffi.cdef("\n".join(line for line in header.splitlines() if not line.lstrip().startswith("#")))
|
|
|
|
if sys.platform == "win32":
|
|
filename = "klamath_rs_ext.dll"
|
|
elif sys.platform == "darwin":
|
|
filename = "libklamath_rs_ext.dylib"
|
|
else:
|
|
filename = "libklamath_rs_ext.so"
|
|
|
|
# An explicit override supports source-tree development without copying binaries
|
|
# into the package. Installed wheels load only their bundled native library.
|
|
library = Path(os.environ["KLAMATH_RS_LIBRARY"]) if "KLAMATH_RS_LIBRARY" in os.environ else Path(__file__).with_name(filename)
|
|
lib = ffi.dlopen(str(library.resolve()))
|