From 472e693cb81ae7e0f0d5589e19c1315a91367460 Mon Sep 17 00:00:00 2001 From: Yuki Kishimoto Date: Mon, 13 Nov 2023 09:59:12 +0100 Subject: [PATCH] ci: add support to `aarch64` python wheels --- .github/workflows/publish-python.yaml | 85 +++++++++++++------ .github/workflows/publish-sdk-python.yaml | 85 +++++++++++++------ .../scripts/generate-linux-aarch64.sh | 18 ++++ .../scripts/generate-linux-aarch64.sh | 18 ++++ 4 files changed, 150 insertions(+), 56 deletions(-) create mode 100755 bindings/nostr-ffi/bindings-python/scripts/generate-linux-aarch64.sh create mode 100755 bindings/nostr-sdk-ffi/bindings-python/scripts/generate-linux-aarch64.sh diff --git a/.github/workflows/publish-python.yaml b/.github/workflows/publish-python.yaml index 6c81bbf21..390ee04b4 100644 --- a/.github/workflows/publish-python.yaml +++ b/.github/workflows/publish-python.yaml @@ -41,9 +41,47 @@ jobs: # see issue #350 for more information run: ${PYBIN}/python setup.py bdist_wheel --plat-name manylinux_2_17_x86_64 --verbose + #- uses: actions/upload-artifact@v3 + # with: + # name: nostr_protocol-manylinux2014-x86_64-${{ matrix.python }} + # path: /home/runner/work/nostr/nostr/bindings/nostr-ffi/bindings-python/dist/*.whl + + build-manylinux_2_31-aarch64-wheels: + name: "Build manylinux_2_31 aarch64 wheel" + runs-on: ubuntu-20.04 + strategy: + matrix: + python: ["3.8", "3.9", "3.10"] + defaults: + run: + working-directory: bindings/nostr-ffi/bindings-python + steps: + - name: "Checkout" + uses: actions/checkout@v3 + + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + + - name: "Setup Python" + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python }} + + - name: Install gcc-aarch64-linux-gnu + run: | + sudo apt-get update -y + sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu + + - name: "Generate nostr.py and binaries" + run: bash ./scripts/generate-linux-aarch64.sh + + - name: "Build wheel" + run: python3 setup.py bdist_wheel --plat-name manylinux_2_31_aarch64 --verbose + - uses: actions/upload-artifact@v3 with: - name: nostr_protocol-manylinux2014-x86_64-${{ matrix.python }} + name: nostr_protocol-manylinux_2_31_aarch64-${{ matrix.python }} path: /home/runner/work/nostr/nostr/bindings/nostr-ffi/bindings-python/dist/*.whl build-macos-arm64-wheels: @@ -54,10 +92,7 @@ jobs: working-directory: bindings/nostr-ffi/bindings-python strategy: matrix: - python: - - "3.8" - - "3.9" - - "3.10" + python: ["3.8", "3.9", "3.10"] steps: - name: "Checkout" uses: actions/checkout@v3 @@ -77,11 +112,11 @@ jobs: # 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 + #- 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" @@ -91,10 +126,7 @@ jobs: working-directory: bindings/nostr-ffi/bindings-python strategy: matrix: - python: - - "3.8" - - "3.9" - - "3.10" + python: ["3.8", "3.9", "3.10"] steps: - name: "Checkout" uses: actions/checkout@v3 @@ -114,10 +146,10 @@ jobs: # see issue #350 for more information run: python3 setup.py bdist_wheel --plat-name macosx_11_0_x86_64 --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 + #- 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" @@ -127,10 +159,7 @@ jobs: working-directory: bindings/nostr-ffi/bindings-python strategy: matrix: - python: - - "3.8" - - "3.9" - - "3.10" + python: ["3.8", "3.9", "3.10"] steps: - name: "Checkout" uses: actions/checkout@v3 @@ -146,11 +175,11 @@ jobs: - 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 + #- 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" @@ -158,7 +187,7 @@ jobs: 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] + needs: [build-manylinux2014-x86_64-wheels, build-manylinux_2_31-aarch64-wheels, build-macos-arm64-wheels, build-macos-x86_64-wheels, build-windows-wheels] steps: - name: "Checkout" uses: actions/checkout@v3 diff --git a/.github/workflows/publish-sdk-python.yaml b/.github/workflows/publish-sdk-python.yaml index 5545d6949..57a6e7ec2 100644 --- a/.github/workflows/publish-sdk-python.yaml +++ b/.github/workflows/publish-sdk-python.yaml @@ -41,9 +41,47 @@ jobs: # see issue #350 for more information run: ${PYBIN}/python setup.py bdist_wheel --plat-name manylinux_2_17_x86_64 --verbose + #- uses: actions/upload-artifact@v3 + # with: + # name: nostr_sdk-manylinux2014-x86_64-${{ matrix.python }} + # path: /home/runner/work/nostr/nostr/bindings/nostr-sdk-ffi/bindings-python/dist/*.whl + + build-manylinux_2_31-aarch64-wheels: + name: "Build manylinux_2_31 aarch64 wheel" + runs-on: ubuntu-20.04 + strategy: + matrix: + python: ["3.8", "3.9", "3.10"] + defaults: + run: + working-directory: bindings/nostr-sdk-ffi/bindings-python + steps: + - name: "Checkout" + uses: actions/checkout@v3 + + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + + - name: "Setup Python" + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python }} + + - name: Install gcc-aarch64-linux-gnu + run: | + sudo apt-get update -y + sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu + + - name: "Generate nostr_sdk.py and binaries" + run: bash ./scripts/generate-linux-aarch64.sh + + - name: "Build wheel" + run: python3 setup.py bdist_wheel --plat-name manylinux_2_31_aarch64 --verbose + - uses: actions/upload-artifact@v3 with: - name: nostr_sdk-manylinux2014-x86_64-${{ matrix.python }} + name: nostr_sdk-manylinux_2_31_aarch64-${{ matrix.python }} path: /home/runner/work/nostr/nostr/bindings/nostr-sdk-ffi/bindings-python/dist/*.whl build-macos-arm64-wheels: @@ -54,10 +92,7 @@ jobs: working-directory: bindings/nostr-sdk-ffi/bindings-python strategy: matrix: - python: - - "3.8" - - "3.9" - - "3.10" + python: ["3.8", "3.9", "3.10"] steps: - name: "Checkout" uses: actions/checkout@v3 @@ -77,11 +112,11 @@ jobs: # 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_sdk-macos-arm64-${{ matrix.python }} - path: /Users/runner/work/nostr/nostr/bindings/nostr-sdk-ffi/bindings-python/dist/*.whl + #- name: "Upload artifacts" + # uses: actions/upload-artifact@v3 + # with: + # name: nostr_sdk-macos-arm64-${{ matrix.python }} + # path: /Users/runner/work/nostr/nostr/bindings/nostr-sdk-ffi/bindings-python/dist/*.whl build-macos-x86_64-wheels: name: "Build macOS x86_64 wheel" @@ -91,10 +126,7 @@ jobs: working-directory: bindings/nostr-sdk-ffi/bindings-python strategy: matrix: - python: - - "3.8" - - "3.9" - - "3.10" + python: ["3.8", "3.9", "3.10"] steps: - name: "Checkout" uses: actions/checkout@v3 @@ -114,10 +146,10 @@ jobs: # see issue #350 for more information run: python3 setup.py bdist_wheel --plat-name macosx_11_0_x86_64 --verbose - - uses: actions/upload-artifact@v3 - with: - name: nostr_sdk-macos-x86_64-${{ matrix.python }} - path: /Users/runner/work/nostr/nostr/bindings/nostr-sdk-ffi/bindings-python/dist/*.whl + #- uses: actions/upload-artifact@v3 + # with: + # name: nostr_sdk-macos-x86_64-${{ matrix.python }} + # path: /Users/runner/work/nostr/nostr/bindings/nostr-sdk-ffi/bindings-python/dist/*.whl build-windows-wheels: name: "Build Windows wheel" @@ -127,10 +159,7 @@ jobs: working-directory: bindings/nostr-sdk-ffi/bindings-python strategy: matrix: - python: - - "3.8" - - "3.9" - - "3.10" + python: ["3.8", "3.9", "3.10"] steps: - name: "Checkout" uses: actions/checkout@v3 @@ -146,11 +175,11 @@ jobs: - name: "Build wheel" run: python setup.py bdist_wheel --verbose - - name: "Upload artifacts" - uses: actions/upload-artifact@v3 - with: - name: nostr_sdk-win-${{ matrix.python }} - path: D:\a\nostr\nostr\bindings\nostr-sdk-ffi\bindings-python\dist\*.whl + #- name: "Upload artifacts" + # uses: actions/upload-artifact@v3 + # with: + # name: nostr_sdk-win-${{ matrix.python }} + # path: D:\a\nostr\nostr\bindings\nostr-sdk-ffi\bindings-python\dist\*.whl publish-pypi: name: "Publish on PyPI" @@ -158,7 +187,7 @@ jobs: defaults: run: working-directory: bindings/nostr-sdk-ffi/bindings-python - needs: [build-manylinux2014-x86_64-wheels, build-macos-arm64-wheels, build-macos-x86_64-wheels, build-windows-wheels] + needs: [build-manylinux2014-x86_64-wheels, build-manylinux_2_31-aarch64-wheels, build-macos-arm64-wheels, build-macos-x86_64-wheels, build-windows-wheels] steps: - name: "Checkout" uses: actions/checkout@v3 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 100755 index 000000000..45be20151 --- /dev/null +++ b/bindings/nostr-ffi/bindings-python/scripts/generate-linux-aarch64.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -euo pipefail +python --version +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=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!" diff --git a/bindings/nostr-sdk-ffi/bindings-python/scripts/generate-linux-aarch64.sh b/bindings/nostr-sdk-ffi/bindings-python/scripts/generate-linux-aarch64.sh new file mode 100755 index 000000000..eec5699d5 --- /dev/null +++ b/bindings/nostr-sdk-ffi/bindings-python/scripts/generate-linux-aarch64.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -euo pipefail +python --version +pip install -r requirements.txt + +echo "Generating nostr_sdk.py..." +cd ../ +cargo run -p uniffi-bindgen generate src/nostr_sdk.udl --language python --no-format -o bindings-python/src/nostr_sdk/ + +echo "Generating native binaries..." +rustup target add aarch64-unknown-linux-gnu +CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc cargo build --release --target aarch64-unknown-linux-gnu + +echo "Copying linux libnostr_sdk_ffi.so..." +cp ../../target/aarch64-unknown-linux-gnu/release/libnostr_sdk_ffi.so bindings-python/src/nostr_sdk/ + +echo "All done!"