Skip to content

Commit

Permalink
Package/wheels distribution via maturin (#153)
Browse files Browse the repository at this point in the history
Co-authored-by: feltroidprime
  • Loading branch information
raugfer authored Aug 19, 2024
1 parent d2011dc commit d5e92ed
Show file tree
Hide file tree
Showing 11 changed files with 375 additions and 215 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/hydra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ jobs:
- name: Compile Rust bindings with maturin
run: |
source venv/bin/activate
cd tools/garaga_rs
cargo test
(cd tools/garaga_rs && cargo fmt --check && cargo test)
maturin develop --release
- name: Run pytest
run: |
Expand Down
171 changes: 171 additions & 0 deletions .github/workflows/maturin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
# This file is autogenerated by maturin v1.7.0
# To update, run
#
# maturin generate-ci github
#
name: CI

on:
push:
branches:
- main
- master
tags:
- '*'
pull_request:
workflow_dispatch:

permissions:
contents: read

jobs:
linux:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-latest
target: x86_64
- runner: ubuntu-latest
target: x86
- runner: ubuntu-latest
target: aarch64
- runner: ubuntu-latest
target: armv7
- runner: ubuntu-latest
target: s390x
- runner: ubuntu-latest
target: ppc64le
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
manylinux: auto
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-linux-${{ matrix.platform.target }}
path: dist

musllinux:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-latest
target: x86_64
- runner: ubuntu-latest
target: x86
- runner: ubuntu-latest
target: aarch64
- runner: ubuntu-latest
target: armv7
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
manylinux: musllinux_1_2
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-musllinux-${{ matrix.platform.target }}
path: dist

windows:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: windows-latest
target: x64
- runner: windows-latest
target: x86
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
architecture: ${{ matrix.platform.target }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-windows-${{ matrix.platform.target }}
path: dist

macos:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: macos-12
target: x86_64
- runner: macos-14
target: aarch64
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
# Workaround to ensure python 3.10 is available on x86_64
python-version: ${{ matrix.platform.target == 'x86_64' && '3.10' || '3.x' }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-macos-${{ matrix.platform.target }}
path: dist

sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build sdist
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
name: wheels-sdist
path: dist

release:
name: Release
runs-on: ubuntu-latest
# Note this will only run when a new tag is pushed
if: "startsWith(github.ref, 'refs/tags/')"
needs: [linux, musllinux, windows, macos, sdist]
steps:
- uses: actions/download-artifact@v4
- name: Publish to PyPI
uses: PyO3/maturin-action@v1
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
with:
command: upload
args: --non-interactive --skip-existing wheels-*/*
2 changes: 1 addition & 1 deletion hydra/garaga/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from enum import Enum
from typing import TypeAlias

import garaga_rs
from fastecdsa import curvemath
from starkware.python.math_utils import EcInfinity, ec_safe_add, ec_safe_mult

from garaga import garaga_rs
from garaga.algebra import (
BaseField,
BaseFp2Field,
Expand Down
3 changes: 1 addition & 2 deletions hydra/garaga/hints/ecip.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import functools
from dataclasses import dataclass

import garaga_rs

from garaga import garaga_rs
from garaga.algebra import Fp2, FunctionFelt, Polynomial, PyFelt, RationalFunction, T
from garaga.definitions import CURVES, CurveID, G1Point, G2Point, get_base_field
from garaga.hints.neg_3 import (
Expand Down
3 changes: 1 addition & 2 deletions hydra/garaga/hints/multi_miller_witness.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import math

import garaga_rs

from garaga import garaga_rs
from garaga.algebra import PyFelt
from garaga.definitions import CURVES, CurveID, G1G2Pair, G1Point, G2Point
from garaga.hints.bls import get_root_and_scaling_factor_bls
Expand Down
2 changes: 1 addition & 1 deletion hydra/garaga/poseidon_transcript.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import garaga_rs
from starkware.cairo.common.poseidon_utils import PoseidonParams
from starkware.cairo.common.poseidon_utils import (
hades_permutation as hades_permutation_slow, # #only for testing times
)

from garaga import garaga_rs
from garaga.algebra import ModuloCircuitElement, PyFelt
from garaga.definitions import BASE, N_LIMBS, STARK
from garaga.hints.io import bigint_split
Expand Down
23 changes: 23 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
[build-system]
requires = ["maturin>=1.7,<2.0"]
build-backend = "maturin"

[project]
name = "garaga"
requires-python = ">=3.10,<3.11"
dependencies = [
"cairo-lang==0.13.2a0",
"fastecdsa",
"sympy",
"typer",
"web3==5.31.0"
]

[project.scripts]
garaga = "garaga.starknet.starknet_cli:app"

[tool.maturin]
features = ["pyo3/extension-module"]
manifest-path = "tools/garaga_rs/Cargo.toml"
# configures rust package as a module under garaga
module-name = "garaga.garaga_rs"
# python source root must be under <tool.maturin.python-source>/<project.name>
python-source = "hydra"

[tool.isort]
profile = "black"
Expand Down
5 changes: 4 additions & 1 deletion tools/garaga_rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "garaga_rs"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "0.15", features = ["extension-module", "num-bigint"] }
pyo3 = { version = "0.22", features = ["extension-module", "num-bigint"] }
num-bigint = "0.4"
num-traits = "0.2"
ark-bn254 = "0.4"
Expand Down
Loading

0 comments on commit d5e92ed

Please sign in to comment.