Skip to content

Commit 5339afc

Browse files
authored
Merge pull request #6 from Verdenroz/feat/rust-bindings
Feat/rust bindings
2 parents dad5b3d + c307a94 commit 5339afc

48 files changed

Lines changed: 6739 additions & 4045 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ jobs:
4242
with:
4343
fetch-depth: 0
4444

45+
- name: Install Rust toolchain
46+
uses: dtolnay/rust-toolchain@stable
47+
4548
- name: Set up Python ${{ matrix.python }}
4649
uses: actions/setup-python@v6
4750
with:
@@ -78,6 +81,11 @@ jobs:
7881
with:
7982
fetch-depth: 0
8083

84+
- name: Install Rust toolchain
85+
uses: dtolnay/rust-toolchain@stable
86+
with:
87+
components: llvm-tools-preview
88+
8189
- name: Set up Python 3.13
8290
uses: actions/setup-python@v6
8391
with:
@@ -100,12 +108,30 @@ jobs:
100108
- name: Combine coverage data and display human readable report
101109
run: nox --session=coverage
102110

103-
- name: Create coverage report
111+
- name: Create Python coverage report
104112
run: nox --session=coverage -- xml
105113

106-
- name: Upload coverage report
114+
# Rust coverage
115+
- name: Install cargo-llvm-cov
116+
uses: taiki-e/install-action@cargo-llvm-cov
117+
118+
- name: Generate Rust coverage
119+
run: cargo llvm-cov --manifest-path crates/agon-core/Cargo.toml --lcov --output-path rust-coverage.lcov
120+
121+
- name: Upload Python coverage to Codecov
107122
uses: codecov/codecov-action@v5
108123
with:
124+
files: coverage.xml
125+
flags: python
109126
name: agon-python
110127
token: ${{ secrets.CODECOV_TOKEN }}
111128
verbose: true
129+
130+
- name: Upload Rust coverage to Codecov
131+
uses: codecov/codecov-action@v5
132+
with:
133+
files: rust-coverage.lcov
134+
flags: rust
135+
name: agon-rust
136+
token: ${{ secrets.CODECOV_TOKEN }}
137+
verbose: true

.github/workflows/publish.yml

Lines changed: 114 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,126 @@ permissions:
1010
contents: read
1111

1212
jobs:
13-
build-and-publish:
14-
runs-on: ubuntu-latest
13+
# Build wheels for Linux
14+
linux:
15+
runs-on: ${{ matrix.platform.runner }}
16+
strategy:
17+
matrix:
18+
platform:
19+
- runner: ubuntu-latest
20+
target: x86_64
21+
- runner: ubuntu-latest
22+
target: aarch64
23+
steps:
24+
- uses: actions/checkout@v6
25+
26+
- uses: actions/setup-python@v6
27+
with:
28+
python-version: "3.13"
29+
30+
- name: Build wheels
31+
uses: PyO3/maturin-action@v1
32+
with:
33+
target: ${{ matrix.platform.target }}
34+
args: --release --out dist
35+
sccache: "true"
36+
manylinux: auto
37+
38+
- name: Upload wheels
39+
uses: actions/upload-artifact@v6
40+
with:
41+
name: wheels-linux-${{ matrix.platform.target }}
42+
path: dist
43+
44+
# Build wheels for macOS
45+
macos:
46+
runs-on: ${{ matrix.platform.runner }}
47+
strategy:
48+
matrix:
49+
platform:
50+
- runner: macos-13
51+
target: x86_64
52+
- runner: macos-14
53+
target: aarch64
1554
steps:
16-
- name: Checkout
17-
uses: actions/checkout@v6
55+
- uses: actions/checkout@v6
56+
57+
- uses: actions/setup-python@v6
58+
with:
59+
python-version: "3.13"
60+
61+
- name: Build wheels
62+
uses: PyO3/maturin-action@v1
63+
with:
64+
target: ${{ matrix.platform.target }}
65+
args: --release --out dist
66+
sccache: "true"
67+
68+
- name: Upload wheels
69+
uses: actions/upload-artifact@v6
1870
with:
19-
fetch-depth: 0
71+
name: wheels-macos-${{ matrix.platform.target }}
72+
path: dist
2073

21-
- name: Install uv
22-
uses: astral-sh/setup-uv@v7
74+
# Build wheels for Windows
75+
windows:
76+
runs-on: ${{ matrix.platform.runner }}
77+
strategy:
78+
matrix:
79+
platform:
80+
- runner: windows-latest
81+
target: x64
82+
steps:
83+
- uses: actions/checkout@v6
84+
85+
- uses: actions/setup-python@v6
2386
with:
24-
version: "0.8.3"
25-
enable-cache: true
2687
python-version: "3.13"
88+
architecture: ${{ matrix.platform.target }}
89+
90+
- name: Build wheels
91+
uses: PyO3/maturin-action@v1
92+
with:
93+
target: ${{ matrix.platform.target }}
94+
args: --release --out dist
95+
sccache: "true"
96+
97+
- name: Upload wheels
98+
uses: actions/upload-artifact@v6
99+
with:
100+
name: wheels-windows-${{ matrix.platform.target }}
101+
path: dist
102+
103+
# Build source distribution
104+
sdist:
105+
runs-on: ubuntu-latest
106+
steps:
107+
- uses: actions/checkout@v6
108+
109+
- name: Build sdist
110+
uses: PyO3/maturin-action@v1
111+
with:
112+
command: sdist
113+
args: --out dist
114+
115+
- name: Upload sdist
116+
uses: actions/upload-artifact@v6
117+
with:
118+
name: wheels-sdist
119+
path: dist
27120

28-
- name: Build package
29-
run: uv build
121+
# Publish to PyPI
122+
publish:
123+
name: Publish to PyPI
124+
runs-on: ubuntu-latest
125+
needs: [linux, macos, windows, sdist]
126+
steps:
127+
- name: Download all artifacts
128+
uses: actions/download-artifact@v7
129+
with:
130+
path: dist
131+
pattern: wheels-*
132+
merge-multiple: true
30133

31134
- name: Publish to PyPI
32135
uses: pypa/gh-action-pypi-publish@release/v1

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Rust
2+
target/
3+
Cargo.lock
4+
*.lcov
5+
16
# Python
27
__pycache__/
38
*.py[cod]

.pre-commit-config.yaml

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,55 @@ repos:
1616
- id: detect-private-key
1717
- id: debug-statements
1818

19+
# Python: codespell
20+
- repo: https://github.com/codespell-project/codespell
21+
rev: v2.4.1
22+
hooks:
23+
- id: codespell
24+
args: ["--write-changes", "--skip", "*.lock,*.json"]
25+
files: ^(python|tests|devtools|docs)/|^README\.md$
26+
27+
# Python: ruff check + format
1928
- repo: https://github.com/astral-sh/ruff-pre-commit
20-
rev: v0.11.9
29+
rev: v0.14.10
2130
hooks:
22-
- id: ruff
23-
args: [--fix, --exit-non-zero-on-fix]
31+
- id: ruff-check
32+
args: [--fix]
33+
files: ^(python|tests|devtools)/
2434
- id: ruff-format
35+
files: ^(python|tests|devtools)/
2536

37+
# Python: basedpyright
2638
- repo: local
2739
hooks:
2840
- id: basedpyright
2941
name: basedpyright (uv)
3042
entry: uv run basedpyright
3143
language: system
32-
args: [src]
44+
args: [python, tests, devtools]
3345
pass_filenames: false
3446

35-
- repo: https://github.com/codespell-project/codespell
36-
rev: v2.4.1
47+
# Rust: cargo fmt
48+
- repo: local
3749
hooks:
38-
- id: codespell
39-
args: ["--skip", "*.lock,*.json"]
50+
- id: cargo-fmt
51+
name: cargo fmt
52+
entry: cargo fmt --manifest-path crates/agon-core/Cargo.toml --
53+
language: system
54+
types: [rust]
55+
pass_filenames: true
56+
57+
# Rust: cargo clippy
58+
- repo: local
59+
hooks:
60+
- id: cargo-clippy
61+
name: cargo clippy
62+
entry: cargo clippy --manifest-path crates/agon-core/Cargo.toml --all-targets --fix --allow-dirty --allow-staged -- -D warnings
63+
language: system
64+
types: [rust]
65+
pass_filenames: false
4066

67+
# CI: GitHub workflows and actions
4168
- repo: https://github.com/python-jsonschema/check-jsonschema
4269
rev: 0.30.0
4370
hooks:

Cargo.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[workspace]
2+
resolver = "2"
3+
members = ["crates/*"]
4+
5+
[workspace.package]
6+
version = "0.2.0"
7+
edition = "2024"
8+
license = "MIT"
9+
authors = ["Harvey Tseng <harveytseng2@gmail.com>"]
10+
repository = "https://github.com/Verdenroz/agon-python"
11+
12+
[workspace.dependencies]
13+
pyo3 = { version = "0.27.2", features = ["extension-module"] }
14+
serde = { version = "1.0", features = ["derive"] }
15+
serde_json = { version = "1.0", features = ["preserve_order"] }
16+
rayon = "1.10"
17+
thiserror = "2.0"
18+
regex = "1.11"
19+
tiktoken-rs = "0.9.1"
20+
21+
[profile.release]
22+
lto = true
23+
codegen-units = 1
24+
opt-level = 3

0 commit comments

Comments
 (0)