Skip to content

Commit 7f7374b

Browse files
authored
Merge pull request #7 from asjad2401/feat/release-wheels
build: PyPI release workflow with abi3 wheels for 5 platforms
2 parents fccc3df + e7c509c commit 7f7374b

10 files changed

Lines changed: 5873 additions & 681 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
name: Release
2+
3+
# Builds abi3 wheels (one per platform, any Python >= 3.9) and an sdist, tests each
4+
# wheel, and publishes to PyPI when a version tag is pushed.
5+
#
6+
# - pull requests touching packaging: build + test only, nothing is published
7+
# - workflow_dispatch: same, on demand
8+
# - tag vX.Y.Z (must match the version in Cargo.toml): build, test, publish
9+
10+
on:
11+
push:
12+
tags: ["v*"]
13+
pull_request:
14+
paths:
15+
- .github/workflows/release.yml
16+
- pyproject.toml
17+
- Cargo.toml
18+
- Cargo.lock
19+
workflow_dispatch:
20+
21+
permissions:
22+
contents: read
23+
24+
jobs:
25+
wheels:
26+
name: wheel ${{ matrix.platform.name }}
27+
runs-on: ${{ matrix.platform.runner }}
28+
strategy:
29+
fail-fast: false
30+
matrix:
31+
platform:
32+
- { name: linux-x86_64, runner: ubuntu-latest, target: x86_64, manylinux: "2_28", test: true }
33+
- { name: linux-aarch64, runner: ubuntu-24.04-arm, target: aarch64, manylinux: "2_28", test: true }
34+
- { name: macos-arm64, runner: macos-14, target: aarch64-apple-darwin, test: true }
35+
# cross-compiled on the arm64 runner, so it can't be run here
36+
- { name: macos-x86_64, runner: macos-14, target: x86_64-apple-darwin, test: false }
37+
- { name: windows-x86_64, runner: windows-latest, target: x64, test: true }
38+
steps:
39+
- uses: actions/checkout@v4
40+
41+
- uses: actions/setup-python@v5
42+
with:
43+
python-version: "3.12"
44+
45+
- name: Build wheel
46+
uses: PyO3/maturin-action@v1
47+
with:
48+
target: ${{ matrix.platform.target }}
49+
manylinux: ${{ matrix.platform.manylinux || 'auto' }}
50+
args: --release --locked --out dist
51+
52+
# the abi3 wheel is tested on the oldest and newest supported Pythons
53+
- uses: actions/setup-python@v5
54+
id: py-oldest
55+
if: matrix.platform.test
56+
with:
57+
python-version: "3.9"
58+
59+
- uses: actions/setup-python@v5
60+
id: py-newest
61+
if: matrix.platform.test
62+
with:
63+
python-version: "3.13"
64+
65+
# runs from outside the repo so the installed wheel is imported, not the source tree
66+
- name: Test wheel
67+
if: matrix.platform.test
68+
shell: bash
69+
env:
70+
PYTHONS: ${{ steps.py-oldest.outputs.python-path }};${{ steps.py-newest.outputs.python-path }}
71+
run: |
72+
IFS=';' read -ra pythons <<< "$PYTHONS"
73+
for py in "${pythons[@]}"; do
74+
echo "::group::$py"
75+
venv="$RUNNER_TEMP/venv-$("$py" -c 'import sys; print("%d%d" % sys.version_info[:2])')"
76+
"$py" -m venv "$venv"
77+
bin="$venv/bin"; [ "$RUNNER_OS" = "Windows" ] && bin="$venv/Scripts"
78+
"$bin/python" -m pip install -q dist/*.whl onnx onnxruntime
79+
cd "$RUNNER_TEMP"
80+
"$bin/python" -c "import sys, burn_python as b; print(sys.version, b.__version__, b.available_backends())"
81+
"$bin/python" "$GITHUB_WORKSPACE/tests/test_ops.py"
82+
cd "$GITHUB_WORKSPACE"
83+
echo "::endgroup::"
84+
done
85+
86+
- uses: actions/upload-artifact@v4
87+
with:
88+
name: wheel-${{ matrix.platform.name }}
89+
path: dist/*.whl
90+
91+
sdist:
92+
name: sdist
93+
runs-on: ubuntu-latest
94+
steps:
95+
- uses: actions/checkout@v4
96+
97+
- name: Build sdist
98+
uses: PyO3/maturin-action@v1
99+
with:
100+
command: sdist
101+
args: --out dist
102+
103+
- uses: actions/upload-artifact@v4
104+
with:
105+
name: sdist
106+
path: dist/*.tar.gz
107+
108+
publish:
109+
name: publish to PyPI
110+
if: startsWith(github.ref, 'refs/tags/v')
111+
needs: [wheels, sdist]
112+
runs-on: ubuntu-latest
113+
# PyPI trusted publishing: no API token, PyPI trusts this workflow + environment
114+
environment:
115+
name: pypi
116+
url: https://pypi.org/p/burn-python
117+
permissions:
118+
id-token: write
119+
steps:
120+
- uses: actions/checkout@v4
121+
122+
- name: Check tag matches Cargo.toml version
123+
run: |
124+
version=$(grep -m1 '^version' Cargo.toml | cut -d'"' -f2)
125+
if [ "v$version" != "$GITHUB_REF_NAME" ]; then
126+
echo "::error::tag $GITHUB_REF_NAME does not match Cargo.toml version $version"
127+
exit 1
128+
fi
129+
130+
- uses: actions/download-artifact@v4
131+
with:
132+
path: dist
133+
merge-multiple: true
134+
135+
- run: ls -la dist
136+
137+
- uses: pypa/gh-action-pypi-publish@release/v1

‎.gitignore‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ dist/
55
*.egg-info/
66
__pycache__/
77
.venv/
8-
Cargo.lock
98
.claude/
109
tests/*.onnx
1110
tests/*.npy

‎CHANGELOG.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased]
99

1010
### Added
11+
- PyPI packaging: `.github/workflows/release.yml` builds abi3 wheels (one per platform,
12+
Python ≥ 3.9) for Linux x86_64/aarch64, macOS arm64/x86_64 and Windows x86_64, tests
13+
them on Python 3.9 and 3.13, and publishes to PyPI via trusted publishing on a `vX.Y.Z` tag.
1114
- GPU inference: `load_onnx(path, backend="wgpu")`, compiled to Metal on macOS and
1215
Vulkan on Linux / Windows. ResNet-18 on an Apple M-series GPU: 6.1 ms at batch 1,
1316
35.6 ms at batch 8 (~3x faster than ONNX Runtime on CPU). `available_backends()`
@@ -30,6 +33,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3033
- Initial maturin/pyo3 project scaffold, `burn-flex` + `onnx-ir` dependencies.
3134

3235
### Changed
36+
- License files now match the declared license: dual MIT / Apache-2.0
37+
(`LICENSE-MIT`, `LICENSE-APACHE`), replacing a GPL-3.0 `LICENSE` file that contradicted it.
38+
- `Cargo.lock` is committed and release builds use `--locked`.
39+
- Package version comes from `Cargo.toml` only.
3340
- All ops now run on burn-dispatch's `Dispatch` backend; the device is chosen per model.
3441
The unused `burn` umbrella dependency was replaced by `burn-dispatch`.
3542
- Backend failures that happen on a worker thread (e.g. no GPU adapter) now report the

0 commit comments

Comments
 (0)