Skip to content

Commit 3d1a951

Browse files
committed
Build python bindings in CI
New CI job to build and run python unit tests. This gh action workflow builds for MacOS x86 and arm archs. While only running the tests on an x86 machine.
1 parent f6c753d commit 3d1a951

4 files changed

Lines changed: 104 additions & 4 deletions

File tree

.github/workflows/build-python.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Copied from [bdk-ffi](https://github.com/bitcoindevkit/bdk-ffi/blob/master/.github/workflows/test-python.yaml)
2+
name: Build and Test Python
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build-manylinux_2_28-x86_64-wheels:
7+
name: "Build and test Manylinux 2.28 x86_64 wheels"
8+
runs-on: ubuntu-20.04
9+
defaults:
10+
run:
11+
working-directory: python
12+
container:
13+
image: quay.io/pypa/manylinux_2_28_x86_64
14+
env:
15+
PLAT: manylinux_2_28_x86_64
16+
PYBIN: "/opt/python/${{ matrix.python_dir }}/bin"
17+
strategy:
18+
matrix:
19+
include:
20+
- python: "3.8"
21+
python_dir: "cp38-cp38"
22+
- python: "3.9"
23+
python_dir: "cp39-cp39"
24+
- python: "3.10"
25+
python_dir: "cp310-cp310"
26+
- python: "3.11"
27+
python_dir: "cp311-cp311"
28+
- python: "3.12"
29+
python_dir: "cp312-cp312"
30+
steps:
31+
- name: "Checkout"
32+
uses: actions/checkout@v4
33+
34+
- name: "Install Rust 1.78.0"
35+
uses: actions-rs/toolchain@v1
36+
with:
37+
toolchain: 1.78.0
38+
39+
- name: "Install Python"
40+
uses: actions/setup-python@v4
41+
with:
42+
python-version: ${{ matrix.python }}
43+
44+
- name: "Generate payjoin-ffi.py and binaries"
45+
run: PYBIN="/opt/python/${{ matrix.python_dir }}/bin" bash ./scripts/generate_linux.sh
46+
47+
- name: "Build wheel"
48+
# Specifying the plat-name argument is necessary to build a wheel with the correct name,
49+
# see issue BDK#350 for more information
50+
run: ${PYBIN}/python setup.py bdist_wheel --plat-name $PLAT --verbose
51+
52+
- name: "Install wheel"
53+
run: ${PYBIN}/pip install ./dist/*.whl
54+
55+
- name: "Run tests"
56+
run: ${PYBIN}/python -m unittest --verbose test/payjoin_unit_test.py
57+
58+
build-macos:
59+
name: "Build and test macOS"
60+
runs-on: macos-13
61+
defaults:
62+
run:
63+
working-directory: python
64+
strategy:
65+
matrix:
66+
python:
67+
- "3.8"
68+
- "3.9"
69+
- "3.10"
70+
- "3.11"
71+
- "3.12"
72+
steps:
73+
- name: "Checkout"
74+
uses: actions/checkout@v4
75+
with:
76+
submodules: true
77+
78+
- name: "Install Rust 1.78.0"
79+
uses: actions-rs/toolchain@v1
80+
with:
81+
toolchain: 1.78.0
82+
83+
- name: "Install Python"
84+
uses: actions/setup-python@v4
85+
with:
86+
python-version: ${{ matrix.python }}
87+
88+
- name: "Generate payjoin-ffi.py and binaries"
89+
run: bash ./scripts/generate_macos.sh
90+
91+
- name: "Build wheel"
92+
# Specifying the plat-name argument is necessary to build a wheel with the correct name,
93+
# see issue BDK#350 for more information
94+
run: python3 setup.py bdist_wheel --plat-name macosx_11_0_x86_64 --verbose
95+
96+
- name: "Install wheel"
97+
run: pip3 install ./dist/*.whl
98+
99+
- name: "Run tests"
100+
run: python3 -m unittest --verbose test/payjoin_unit_test.py

python/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ venv
1717

1818
# Auto-generated bindings python file
1919
src/payjoin/payjoin_ffi.py
20+
src/payjoin/bitcoin.py

python/scripts/generate_linux.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
3-
python3 --version
4-
pip install --user -r requirements.txt
3+
${PYBIN}/python --version
4+
${PYBIN}/pip install -r requirements.txt -r requirements-dev.txt
55
LIBNAME=libpayjoin_ffi.so
66
LINUX_TARGET=x86_64-unknown-linux-gnu
77

python/scripts/generate_windows.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ LIBNAME=payjoin_ffi.dll
66
WINDOWS_TARGET=x86_64-pc-windows-gnu
77
echo "Generating payjoin_ffi.py..."
88
cd ../
9-
cargo run --features uniffi --bin uniffi-bindgen generate src/payjoin_ffi.udl --language python --out-dir python/src/payjoin/
10-
9+
cargo run --features uniffi --bin uniffi-bindgen generate --library target/release/$LIBNAME --language python --out-dir python/src/payjoin/
1110

1211
echo "Generating native binaries..."
1312
rustup target add $WINDOWS_TARGET

0 commit comments

Comments
 (0)