Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions .github/workflows/build-python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Copied from [bdk-ffi](https://github.com/bitcoindevkit/bdk-ffi/blob/master/.github/workflows/test-python.yaml)
name: Build and Test Python
on: [push, pull_request]

jobs:
build-manylinux_2_28-x86_64-wheels:
name: "Build and test Manylinux 2.28 x86_64 wheels"
runs-on: ubuntu-20.04
defaults:
run:
working-directory: python
container:
image: quay.io/pypa/manylinux_2_28_x86_64
env:
PLAT: manylinux_2_28_x86_64
PYBIN: "/opt/python/${{ matrix.python_dir }}/bin"
strategy:
matrix:
include:
- python: "3.8"
python_dir: "cp38-cp38"
- python: "3.9"
python_dir: "cp39-cp39"
- python: "3.10"
python_dir: "cp310-cp310"
- python: "3.11"
python_dir: "cp311-cp311"
- python: "3.12"
python_dir: "cp312-cp312"
steps:
- name: "Checkout"
uses: actions/checkout@v4

- name: "Install Rust 1.78.0"
uses: actions-rs/toolchain@v1
with:
toolchain: 1.78.0

- name: "Install Python"
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}

- name: "Generate payjoin-ffi.py and binaries"
run: PYBIN="/opt/python/${{ matrix.python_dir }}/bin" bash ./scripts/generate_linux.sh

- name: "Build wheel"
# Specifying the plat-name argument is necessary to build a wheel with the correct name,
# see issue BDK#350 for more information
run: ${PYBIN}/python setup.py bdist_wheel --plat-name $PLAT --verbose

- name: "Install wheel"
run: ${PYBIN}/pip install ./dist/*.whl

- name: "Run tests"
run: ${PYBIN}/python -m unittest --verbose test/payjoin_unit_test.py

build-macos:
name: "Build and test macOS"
runs-on: macos-13
defaults:
run:
working-directory: python
strategy:
matrix:
python:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
steps:
- name: "Checkout"
uses: actions/checkout@v4
with:
submodules: true

- name: "Install Rust 1.78.0"
uses: actions-rs/toolchain@v1
with:
toolchain: 1.78.0

- name: "Install Python"
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}

- name: "Generate payjoin-ffi.py and binaries"
run: bash ./scripts/generate_macos.sh

- name: "Build wheel"
# Specifying the plat-name argument is necessary to build a wheel with the correct name,
# see issue BDK#350 for more information
run: python3 setup.py bdist_wheel --plat-name macosx_11_0_x86_64 --verbose
Comment on lines +91 to +94
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we mention, as bdk does, the rationale for testing only the x86 wheel? https://github.com/bitcoindevkit/bdk-ffi/blob/master/.github/workflows/test-python.yaml#L97

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it could be worth having this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good comment. I actually realized that we are not building the arm64 wheel on CI. Will add this step.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


- name: "Install wheel"
run: pip3 install ./dist/*.whl

- name: "Run tests"
run: python3 -m unittest --verbose test/payjoin_unit_test.py

- name: "Build arm64 wheel"
run: python3 setup.py bdist_wheel --plat-name macosx_11_0_arm64 --verbose
# Note: You can't install the arm64 wheel on the CI, so we skip these steps and simply test that the wheel builds
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
run: cargo build --color always --all-targets --features _danger-local-https
- name: Check formatting (nightly only)
if: matrix.rust == 'nightly'
run: rustup component add rustfmt && cargo fmt --all -- --check\
run: rustup component add rustfmt && cargo fmt --all -- --check

Lint:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The directories below include instructions for using, building, and publishing t

| Language | Platform | Published Package | Building Documentation | API Docs |
|----------|-----------------------|-------------------|------------------------------------|----------|
| Python | linux, macOS, Windows | payjoin | [Readme payjoin](python/README.md) | |
| Python | linux, macOS | payjoin | [Readme payjoin](python/README.md) | |

## Minimum Supported Rust Version (MSRV)

Expand Down
11 changes: 10 additions & 1 deletion python/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@ __pycache__/
*.swp
*.whl
build/
venv
venv

# Auto-generated shared libraries
*.dylib
*.so
*.dll

# Auto-generated bindings python file
src/payjoin/payjoin_ffi.py
src/payjoin/bitcoin.py
3 changes: 2 additions & 1 deletion python/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
python-bitcoinlib==0.12.2
python-bitcoinlib==0.12.2
toml==0.10.2
2 changes: 0 additions & 2 deletions python/scripts/bindgen_generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

#!/bin/bash
chmod +x ./scripts/generate_linux.sh
chmod +x ./scripts/generate_windows.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you wish not also to remove the generate_windows script?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agh Yeah this was done in a seperate commit. I will move that change to this commit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

chmod +x ./scripts/generate_macos.sh


# Run each script
scripts/generate_linux.sh
scripts/generate_windows.sh
scripts/generate_macos.sh
8 changes: 4 additions & 4 deletions python/scripts/generate_linux.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env bash
set -euo pipefail
python3 --version
pip install --user -r requirements.txt
${PYBIN}/python --version
${PYBIN}/pip install -r requirements.txt -r requirements-dev.txt
LIBNAME=libpayjoin_ffi.so
LINUX_TARGET=x86_64-unknown-linux-gnu

echo "Generating payjoin_ffi.py..."
cd ../
cargo run --features uniffi --bin uniffi-bindgen generate src/payjoin_ffi.udl --language python --out-dir python/src/payjoin/

cargo build --profile release --features uniffi
cargo run --profile release --features uniffi --bin uniffi-bindgen generate --library target/release/$LIBNAME --language python --out-dir python/src/payjoin/

echo "Generating native binaries..."
rustup target add $LINUX_TARGET
Expand Down
8 changes: 4 additions & 4 deletions python/scripts/generate_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

set -euo pipefail
python3 --version
pip install --user -r requirements.txt
pip install -r requirements.txt -r requirements-dev.txt
LIBNAME=libpayjoin_ffi.dylib

echo "Generating payjoin_ffi.py..."
cd ../
cargo run --features uniffi --bin uniffi-bindgen generate src/payjoin_ffi.udl --language python --out-dir python/src/payjoin/

cargo build --features uniffi --profile release
cargo run --features uniffi --profile release --bin uniffi-bindgen generate --library target/release/$LIBNAME --language python --out-dir python/src/payjoin/

echo "Generating native binaries..."
rustup target add aarch64-apple-darwin x86_64-apple-darwin

cargo build --profile release-smaller --target aarch64-apple-darwin --features uniffi
echo "Done building aarch64-apple-darwin"

cargo build --profile release-smaller --target x86_64-apple-darwin
cargo build --profile release-smaller --target x86_64-apple-darwin --features uniffi
echo "Done building x86_64-apple-darwin"

echo "Building macos fat library"
Expand Down
19 changes: 0 additions & 19 deletions python/scripts/generate_windows.sh

This file was deleted.

9 changes: 8 additions & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#!/usr/bin/env python

import os
from setuptools import setup, find_packages
import toml

# Read version from Cargo.toml
cargo_toml_path = os.path.join(os.path.dirname(__file__), '..', 'Cargo.toml')
cargo_toml = toml.load(cargo_toml_path)
version = cargo_toml['package']['version']

LONG_DESCRIPTION = """# payjoin
This repository creates libraries for various programming languages, all using the Rust-based [Payjoin](https://github.com/payjoin/rust-payjoin)
Expand All @@ -25,7 +32,7 @@
zip_safe=False,
packages=["payjoin"],
package_dir={"payjoin": "./src/payjoin"},
version="0.20.0",
version=version,
license="MIT or Apache 2.0",
has_ext_modules=lambda: True,
)
Binary file removed python/src/payjoin/libpayjoin_ffi.dylib
Binary file not shown.
Binary file removed python/src/payjoin/libpayjoin_ffi.so
Binary file not shown.
Binary file removed python/src/payjoin/payjoin_ffi.dll
Binary file not shown.
Loading
Loading