From 65bd7ea4283a39a2c0339c4b4bf993f81f77a576 Mon Sep 17 00:00:00 2001 From: thunderbiscuit Date: Mon, 13 Dec 2021 12:15:30 -0500 Subject: [PATCH] Update loadIndirect function fix documentation --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index e3a9e95..4bb6ba9 100644 --- a/README.md +++ b/README.md @@ -48,3 +48,31 @@ def loadIndirect(): ) return getattr(ctypes.cdll, libname.format("bdkffi")) ``` + +## Support both macOS architectures +In order to support both macOS architectures, we must modify the `loadIndirect()` method a little further: +```python +import platform +def loadIndirect(): + if sys.platform == "linux": + # libname = "lib{}.so" + # libname = os.path.join(os.path.dirname(__file__), "lib{}.so") + libname = os.path.join(os.path.dirname(__file__), "linux-x86_64/lib{}.so") + elif sys.platform == "darwin": + # libname = "lib{}.dylib" + # libname = os.path.join(os.path.dirname(__file__), "lib{}.dylib") + if platform.machine() == "arm64": + libname = os.path.join(os.path.dirname(__file__), "darwin-arm64/lib{}.dylib") + elif platform.machine() == "x86_64": + libname = os.path.join(os.path.dirname(__file__), "darwin-x86_64/lib{}.dylib") + elif sys.platform.startswith("win"): + # As of python3.8, ctypes does not seem to search $PATH when loading DLLs. + # We could use `os.add_dll_directory` to configure the search path, but + # it doesn't feel right to mess with application-wide settings. Let's + # assume that the `.dll` is next to the `.py` file and load by full path. + libname = os.path.join( + os.path.dirname(__file__), + "{}.dll", + ) + return getattr(ctypes.cdll, libname.format("bdkffi")) +```