diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 61bc19067..19cb46ab4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,10 +1,6 @@ name: CI -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] +on: [workflow_dispatch] env: CARGO_TERM_COLOR: always diff --git a/.github/workflows/publish-python.yaml b/.github/workflows/publish-python.yaml index 6c81bbf21..a38775dd7 100644 --- a/.github/workflows/publish-python.yaml +++ b/.github/workflows/publish-python.yaml @@ -1,6 +1,10 @@ name: Publish nostr-protocol to PyPI -on: [workflow_dispatch] +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] # We use manylinux2014 because older CentOS versions used by 2010 and 1 have a very old glibc version, which # makes it very hard to use GitHub's javascript actions (checkout, upload-artifact, etc). @@ -46,131 +50,43 @@ jobs: name: nostr_protocol-manylinux2014-x86_64-${{ matrix.python }} path: /home/runner/work/nostr/nostr/bindings/nostr-ffi/bindings-python/dist/*.whl - build-macos-arm64-wheels: - name: "Build macOS arm64 wheel" - runs-on: macos-13 - defaults: - run: - working-directory: bindings/nostr-ffi/bindings-python - strategy: - matrix: - python: - - "3.8" - - "3.9" - - "3.10" - steps: - - name: "Checkout" - uses: actions/checkout@v3 - with: - submodules: true - - - name: "Install Python" - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python }} - - - name: "Generate nostr.py and binaries" - run: bash ./scripts/generate-macos-arm64.sh - - - name: "Build wheel" - # Specifying the plat-name argument is necessary to build a wheel with the correct name, - # see issue #350 for more information - run: python3 setup.py bdist_wheel --plat-name macosx_11_0_arm64 --verbose - - - name: "Upload artifacts" - uses: actions/upload-artifact@v3 - with: - name: nostr_protocol-macos-arm64-${{ matrix.python }} - path: /Users/runner/work/nostr/nostr/bindings/nostr-ffi/bindings-python/dist/*.whl - - build-macos-x86_64-wheels: - name: "Build macOS x86_64 wheel" - runs-on: macos-13 + build-manylinux2014-aarch64-wheels: + name: "Build Manylinux 2014 aarch64 wheel" + runs-on: ubuntu-20.04 defaults: run: working-directory: bindings/nostr-ffi/bindings-python + container: + image: quay.io/pypa/manylinux2014_x86_64 + env: + PLAT: manylinux2014_aarch64 + PYBIN: "/opt/python/${{ matrix.python }}/bin" strategy: matrix: - python: - - "3.8" - - "3.9" - - "3.10" + python: # Update this list whenever the docker image is updated (check /opt/python/) + - cp38-cp38 + - cp39-cp39 + - cp310-cp310 steps: - name: "Checkout" uses: actions/checkout@v3 - with: - submodules: true - - name: "Install Python" - uses: actions/setup-python@v4 + - uses: actions-rs/toolchain@v1 with: - python-version: ${{ matrix.python }} + toolchain: stable + - name: "Install gcc-aarch64-linux-gnu" + run: yum install -y gcc-aarch64-linux-gnu + - name: "Generate nostr.py and binaries" - run: bash ./scripts/generate-macos-x86_64.sh + run: bash ./scripts/generate-linux-aarch64.sh - name: "Build wheel" # Specifying the plat-name argument is necessary to build a wheel with the correct name, # see issue #350 for more information - run: python3 setup.py bdist_wheel --plat-name macosx_11_0_x86_64 --verbose + run: ${PYBIN}/python setup.py bdist_wheel --plat-name manylinux_2_17_aarch64 --verbose - uses: actions/upload-artifact@v3 with: - name: nostr_protocol-macos-x86_64-${{ matrix.python }} - path: /Users/runner/work/nostr/nostr/bindings/nostr-ffi/bindings-python/dist/*.whl - - build-windows-wheels: - name: "Build Windows wheel" - runs-on: windows-2022 - defaults: - run: - working-directory: bindings/nostr-ffi/bindings-python - strategy: - matrix: - python: - - "3.8" - - "3.9" - - "3.10" - steps: - - name: "Checkout" - uses: actions/checkout@v3 - with: - submodules: true - - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python }} - - - name: "Generate nostr.py and binaries" - run: bash ./scripts/generate-windows.sh - - - name: "Build wheel" - run: python setup.py bdist_wheel --verbose - - - name: "Upload artifacts" - uses: actions/upload-artifact@v3 - with: - name: nostr_protocol-win-${{ matrix.python }} - path: D:\a\nostr\nostr\bindings\nostr-ffi\bindings-python\dist\*.whl - - publish-pypi: - name: "Publish on PyPI" - runs-on: ubuntu-20.04 - defaults: - run: - working-directory: bindings/nostr-ffi/bindings-python - needs: [build-manylinux2014-x86_64-wheels, build-macos-arm64-wheels, build-macos-x86_64-wheels, build-windows-wheels] - steps: - - name: "Checkout" - uses: actions/checkout@v3 - - - name: "Download artifacts in dist/ directory" - uses: actions/download-artifact@v3 - with: - path: dist/ - - - name: "Publish on PyPI" - uses: pypa/gh-action-pypi-publish@release/v1 - with: - user: __token__ - password: ${{ secrets.PYPI_API_TOKEN }} - packages_dir: dist/*/ + name: nostr_protocol-manylinux2014-aarch64-${{ matrix.python }} + path: /home/runner/work/nostr/nostr/bindings/nostr-ffi/bindings-python/dist/*.whl diff --git a/bindings/nostr-ffi/bindings-python/scripts/generate-linux-aarch64.sh b/bindings/nostr-ffi/bindings-python/scripts/generate-linux-aarch64.sh new file mode 100644 index 000000000..b4ce3795c --- /dev/null +++ b/bindings/nostr-ffi/bindings-python/scripts/generate-linux-aarch64.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -euo pipefail +${PYBIN}/python --version +${PYBIN}/pip install -r requirements.txt + +echo "Generating nostr.py..." +cd ../ +cargo run -p uniffi-bindgen generate src/nostr.udl --language python --no-format -o bindings-python/src/nostr/ + +echo "Generating native binaries..." +rustup target add aarch64-unknown-linux-gnu +CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=/usr/bin/aarch64-linux-gnu-gcc cargo build --release --target aarch64-unknown-linux-gnu + +echo "Copying linux libnostr_ffi.so..." +cp ../../target/aarch64-unknown-linux-gnu/release/libnostr_ffi.so bindings-python/src/nostr/ + +echo "All done!"