From eb0b5ef5e54368ef8ccd361c31ad9d6606bc426c Mon Sep 17 00:00:00 2001 From: Dylan Date: Thu, 14 Mar 2024 12:35:36 +0900 Subject: [PATCH] trying out maturin --- .github/workflows/build_wheels.yml | 285 +++++++++++++++++------------ README.md | 6 +- crates/hyperdrivepy/README.md | 2 +- crates/hyperdrivepy/pyproject.toml | 12 +- pyproject.toml | 8 +- scripts/build_python.sh | 12 +- 6 files changed, 188 insertions(+), 137 deletions(-) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index fe21ebb..26d0311 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -4,9 +4,15 @@ on: push: branches: - main + tags: + - "*" pull_request: branches: - main + workflow_dispatch: + +permissions: + contents: read jobs: detect-version-changes: @@ -14,40 +20,34 @@ jobs: with: file_path: crates/hyperdrivepy/pyproject.toml - build-wheels-linux: - needs: detect-version-changes - # Run on main if version has changed - # if: > - # github.event_name == 'push' && - # github.ref == 'refs/heads/main' - # && needs.detect-version-changes.outputs.version_changed == 'true' - name: build on linux + linux: + name: build linux + # needs: detect-version-changes + # runs-on: ubuntu-22.04 runs-on: ubuntu-latest + strategy: + matrix: + # target: [x86_64, aarch64, armv7, s390x, ppc64le] + target: [x86_64, aarch64] + # defaults: + # run: + # working-directory: ./crates/hyperdrivepy steps: - - uses: actions/checkout@v3 - with: - token: ${{github.token}} + - uses: actions/checkout@v4 - - name: setup rust - uses: actions-rs/toolchain@v1 + - name: setup python + uses: actions/setup-python@v5 with: - toolchain: stable + python-version: "3.10" + + - name: install python dependencies + run: python -m pip install --upgrade pip && python -m pip install --upgrade -r ./requirements-dev.txt - name: setup foundry uses: foundry-rs/foundry-toolchain@v1 with: version: nightly - - name: set up python - uses: actions/setup-python@v4 - with: - python-version: "3.10" - cache: "pip" - token: ${{github.token}} - - - name: set up pip - run: python -m pip install --upgrade pip - - name: check out hyperdrive uses: actions/checkout@master with: @@ -56,114 +56,159 @@ jobs: path: "./hyperdrive" ssh-key: ${{ secrets.HYPERDRIVE_ACCESS_KEY }} - - name: build hyperdrivepy - shell: bash - run: source scripts/build_python.sh + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + target: ${{ matrix.target }} + args: --release --out dist + working-directory: crates/hyperdrivepy + sccache: "true" + manylinux: manylinux_2_31 - - name: upload artifacts + - name: Upload wheels uses: actions/upload-artifact@v4 with: - name: wheels-linux - path: ./wheelhouse/*.whl - - #build-wheels-cibw: - # needs: detect-version-changes - # # Run on main if version has changed - # # if: > - # # github.event_name == 'push' && - # # github.ref == 'refs/heads/main' - # # && needs.detect-version-changes.outputs.version_changed == 'true' - # name: Build on ${{ matrix.os }} - # runs-on: ${{ matrix.os }} - # strategy: - # fail-fast: false - # matrix: - # os: [macos-12, windows-2019] - # python-version: [cp310] - - # steps: - # - uses: actions/checkout@v3 - # with: - # submodules: recursive - # token: ${{ secrets.GITHUB_TOKEN }} - - # - name: check out hyperdrive - # uses: actions/checkout@master - # with: - # repository: delvtech/hyperdrive - # ref: "v0.9.0" - # path: "./hyperdrive" - # ssh-key: ${{ secrets.HYPERDRIVE_ACCESS_KEY }} - - # - name: set up python - # uses: actions/setup-python@v4 - # with: - # python-version: "3.10" - - # - name: install python dependencies - # run: python -m pip install --upgrade pip && python -m pip install --upgrade -r requirements-dev.txt - # - # - name: build wheels - # uses: pypa/cibuildwheel@v2.16.5 - # env: - # CIBW_BUILD: "${{ matrix.python-version }}-*" - # CIBW_ENVIRONMENT: 'PATH="$HOME/.cargo/bin:$HOME/.foundry/bin:$HOME/.cargo/env:$PATH" CARGO_TERM_COLOR="always"' - # CIBW_ENVIRONMENT_WINDOWS: 'PATH="$UserProfile\.cargo\bin;$UserProfile\.foundry\bin;$UserProfile\.cargo\env;$PATH"' - # CIBW_ARCHS_MACOS: x86_64 arm64 - # CIBW_BEFORE_ALL_MACOS: > - # curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=stable --profile=minimal -y && - # rustup show && - # rustup target add aarch64-apple-darwin && - # curl -L https://foundry.paradigm.xyz | sh && - # foundryup - # CIBW_BUILD_VERBOSITY: 1 - # with: - # output-dir: wheelhouse - # package-dir: crates/hyperdrivepy - - # - name: upload artifacts - # uses: actions/upload-artifact@v4 - # with: - # name: wheels-${{ matrix.os }}-${{ strategy.job-index }} - # path: ./wheelhouse/*.whl - - build-sdist: - name: Build source distribution + name: wheels-linux-${{ matrix.target }} + path: dist + + # windows: + # name: build windows + # # needs: detect-version-changes + # runs-on: windows-latest + # strategy: + # matrix: + # target: [x64, x86] + # # defaults: + # # run: + # # working-directory: .\crates\hyperdrivepy + # steps: + # - uses: actions/checkout@v4 + + # - name: setup python + # uses: actions/setup-python@v5 + # with: + # python-version: "3.10" + # architecture: ${{ matrix.target }} + + # - name: install python dependencies + # run: python -m pip install --upgrade pip && python -m pip install --upgrade -r ./requirements-dev.txt + + # - name: check out hyperdrive + # uses: actions/checkout@master + # with: + # repository: delvtechhyperdrive + # ref: "v0.9.0" + # path: "./hyperdrive" + # ssh-key: ${{ secrets.HYPERDRIVE_ACCESS_KEY }} + + # - name: setup foundry + # uses: foundry-rs/foundry-toolchain@v1 + # with: + # version: nightly + + # - name: Build wheels + # uses: PyO3/maturin-action@v1 + # with: + # target: ${{ matrix.target }} + # args: --release --out dist + # working-directory: crates/hyperdrivepy + # sccache: "true" + + # - name: Upload wheels + # uses: actions/upload-artifact@v4 + # with: + # name: wheels-windows-${{ matrix.target }} + # path: dist + + # macos: + # name: build macos + # # needs: detect-version-changes + # runs-on: macos-latest + # strategy: + # matrix: + # target: [x86_64, aarch64] + # # defaults: + # # run: + # # working-directory: ./crates/hyperdrivepy + # steps: + # - uses: actions/checkout@v4 + + # - name: setup python + # uses: actions/setup-python@v5 + # with: + # python-version: "3.10" + + # - name: install python dependencies + # run: python -m pip install --upgrade pip && python -m pip install --upgrade -r ./requirements-dev.txt + + # - name: check out hyperdrive + # uses: actions/checkout@main + # with: + # repository: delvtech/hyperdrive + # ref: "v0.9.0" + # path: "./hyperdrive" + # ssh-key: ${{ secrets.HYPERDRIVE_ACCESS_KEY }} + + # - name: setup foundry + # uses: foundry-rs/foundry-toolchain@v1 + # with: + # version: nightly + + # - name: Build wheels + # uses: PyO3/maturin-action@v1 + # with: + # target: ${{ matrix.target }} + # args: --release --out dist + # working-directory: crates/hyperdrivepy + # sccache: "true" + + # - name: Upload wheels + # uses: actions/upload-artifact@v4 + # with: + # name: wheels-macos-${{ matrix.target }} + # path: dist + + sdist: + name: sdist + # needs: detect-version-changes runs-on: ubuntu-latest - # Run on main if version has changed - # if: > - # github.event_name == 'push' && - # github.ref == 'refs/heads/main' - # && needs.detect-version-changes.outputs.version_changed == 'true' + # defaults: + # run: + # working-directory: ./crates/hyperdrivepy steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build sdist - run: pipx run build crates/hyperdrivepy --sdist + uses: PyO3/maturin-action@v1 + with: + command: sdist + args: --out dist + working-directory: crates/hyperdrivepy - - uses: actions/upload-artifact@v4 + - name: Upload sdist + uses: actions/upload-artifact@v4 with: name: wheels-sdist - path: crates/hyperdrivepy/dist/*.tar.gz + path: dist - upload_pypi: - #needs: [build-wheels-linux, build-wheels-cibw, build-sdist, detect-version-changes] - needs: [build-wheels-linux, build-sdist, detect-version-changes] + release: + name: Release + # needs: detect-version-changes runs-on: ubuntu-latest - environment: pypi - permissions: - id-token: write - # Run on main if version has changed - # if: > - # github.event_name == 'push' && - # github.ref == 'refs/heads/main' - # && needs.detect-version-changes.outputs.version_changed == 'true' - # + # defaults: + # run: + # working-directory: ./crates/hyperdrivepy + if: "startsWith(github.ref, 'refs/tags/')" + # needs: [linux, windows, macos, sdist] + needs: [linux] steps: - uses: actions/download-artifact@v4 + + - name: Publish to PyPI + uses: PyO3/maturin-action@v1 + env: + MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }} with: - # unpacks all wheels into dist/ - pattern: wheels-* - path: dist - merge-multiple: true - - uses: pypa/gh-action-pypi-publish@release/v1 + working-directory: crates/hyperdrivepy + command: upload + args: --non-interactive --skip-existing wheels-*/* diff --git a/README.md b/README.md index 79fa318..a47bc2f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [![license: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-lightgrey)](http://www.apache.org/licenses/LICENSE-2.0) [![DELV - Terms of Service](https://img.shields.io/badge/DELV-Terms_of_Service-orange)](https://elementfi.s3.us-east-2.amazonaws.com/element-finance-terms-of-service.pdf) -# Hyperdrive-SDK +# Hyperdrive-bindings [Hyperdrive](https://hyperdrive.delv.tech) is an automated market maker that enables fixed-rate markets to be built on top of arbitrary yield sources. @@ -10,7 +10,7 @@ This repo contains hyperdrivepy and hyperdrive-wasm, which are Rust-powered Pyth ## Hyperdrivepy local install For a local installation, this repo must include a simulation link to the hyperdrive-rust source code. -From the `hyperdrive-sdk` project root, run: +From the `hyperdrive-bindings` project root, run: ```shell git clone git@github.com:delvtech/hyperdrive.git ../hyperdrive @@ -34,7 +34,7 @@ To install the Python package `hyperdrivepy`, which wraps `hyperdrive-rs`, you n PoolInfo and PoolConfig are passed into many of the functions. These are built from the Hyperdrive abi json with pypechain. -From the hyperdrive-sdk project root, run: +From the hyperdrive-bindings project root, run: ```shell pip install --upgrade -r requirements-dev.txt diff --git a/crates/hyperdrivepy/README.md b/crates/hyperdrivepy/README.md index 67a41fd..7390099 100644 --- a/crates/hyperdrivepy/README.md +++ b/crates/hyperdrivepy/README.md @@ -1,6 +1,6 @@ # hyperdrivepy -Hyperdrivepy is the Python to rust bindings of [hyperdrive-sdk](https://github.com/delvtech/hyperdrive-sdk). +Hyperdrivepy is the Python to rust bindings of [hyperdrive-bindings](https://github.com/delvtech/hyperdrive-bindings). ## Disclaimer diff --git a/crates/hyperdrivepy/pyproject.toml b/crates/hyperdrivepy/pyproject.toml index f5aeb13..bb47692 100644 --- a/crates/hyperdrivepy/pyproject.toml +++ b/crates/hyperdrivepy/pyproject.toml @@ -10,12 +10,12 @@ classifiers = [ readme = "README.md" [project.urls] -Homepage = "https://github.com/delvtech/hyperdrive-sdk" -Issues = "https://github.com/delvtech/hyperdrive-sdk/issues" - -[build-system] -requires = ["setuptools", "wheel", "setuptools-rust"] -build-backend = "setuptools.build_meta" +Homepage = "https://github.com/delvtech/hyperdrive-bindings" +Issues = "https://github.com/delvtech/hyperdrive-bindings/issues" [tool.setuptools.packages.find] where = ["python", "src"] + +[build-system] +requires = ["setuptools", "wheel", "setuptools-rust", "maturin>=1.5"] +build-backend = "maturin" diff --git a/pyproject.toml b/pyproject.toml index db4ee15..6f0324a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,8 +10,12 @@ requires-python = ">=3.7" readme = "README.md" [project.urls] -Homepage = "https://github.com/delvtech/hyperdrive-sdk" -Issues = "https://github.com/delvtech/hyperdrive-sdk/issues" +Homepage = "https://github.com/delvtech/hyperdrive-bindings" +Issues = "https://github.com/delvtech/hyperdrive-bindings/issues" + +[build-system] +requires = ["setuptools", "wheel", "setuptools-rust", "maturin"] +build-backend = "maturin" [tool.pytest.ini_options] minversion = "6.0" diff --git a/scripts/build_python.sh b/scripts/build_python.sh index 5ae4fee..75aa577 100644 --- a/scripts/build_python.sh +++ b/scripts/build_python.sh @@ -8,14 +8,16 @@ echo "install required packages for building wheels" python -m pip install --upgrade -r requirements-dev.txt python -m pip install auditwheel +python -m pip install maturin echo "nav into the crate so relative paths work" cd crates/hyperdrivepy echo "build the wheel for the current platform" -python setup.py bdist_wheel +# python setup.py bdist_wheel +# python -m maturin build -echo "repair built wheel to be manylinux into wheelhouse" -# wheelhouse is in the package root -mkdir ../../wheelhouse -auditwheel repair dist/hyperdrivepy-*-linux_x86_64.whl -w ../../wheelhouse --plat manylinux_2_28_x86_64 \ No newline at end of file +# echo "repair built wheel to be manylinux into wheelhouse" +# # wheelhouse is in the package root +# mkdir ../../wheelhouse +# auditwheel repair dist/hyperdrivepy-*-linux_x86_64.whl -w ../../wheelhouse --plat manylinux_2_28_x86_64 \ No newline at end of file