Build wheels using setuptools-rust

Build wheels in a more "standard" way using setuptools-rust, which makes
our life easier when dealing with multiple different platforms.

Also use the new bdk-ffi's `generate` binary instead of relying on
uniffi's bindgen cli.
This commit is contained in:
Alekos Filini
2022-02-15 16:47:34 +01:00
parent 964b7ae5f0
commit d2bbecc5f5
12 changed files with 850 additions and 1969 deletions

View File

@@ -25,6 +25,11 @@ python -m tox
## Build the package
```shell
# Install dependecies
pip install -r requirements.txt
# Generate the bindings first
bash generate.sh
# Build the wheel
python -m build
```
<br/>
@@ -34,53 +39,3 @@ python -m build
pip install ./dist/bdkpython-0.0.1-py3-none-any.whl
```
<br/>
## Known issues
Note that until the fix is merged upstream in [uniffi-rs](https://github.com/mozilla/uniffi-rs), the `loadIndirect()` function in the `bdk.py` module must be replaced with the following:
```python
def loadIndirect():
if sys.platform == "linux":
# libname = "lib{}.so"
libname = os.path.join(os.path.dirname(__file__), "lib{}.so")
elif sys.platform == "darwin":
# libname = "lib{}.dylib"
libname = os.path.join(os.path.dirname(__file__), "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"))
```
## 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"))
```