fix(python): flatten packing buffers and package Cargo libraries

This commit is contained in:
Jan Petykiewicz 2026-11-15 20:01:26 -08:00
commit 912a267028

View file

@ -0,0 +1,23 @@
"""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()))