Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# PyO3 Extension Template

Template for starting PyO3 module projects with `cargo-generate`
Template for starting PyO3 module projects with `cargo-generate`. It works much like `maturin new` and `maturin generate-ci`,
but aims to provide additional options and flexibility and work with the `cargo-generate` toolset (which, for me, is how I prefer to start projects in Rust Rover).

Includes basic project setup and GitHub Actions workflow that:

Expand All @@ -11,3 +12,6 @@ Includes basic project setup and GitHub Actions workflow that:

To publish to PyPI, be sure to setup your [trusted publisher](https://docs.pypi.org/trusted-publishers/) configuration
first.

This project is usable, but still in the early stages of development. Check the [issues](https://github.com/spyoungtech/pyo3-extension-template/issues) for
details of known bugs and planned features or to request a new feature or report a bug.
229 changes: 229 additions & 0 deletions template/.github/workflows/build-release-maturin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
name: CI

on: [push, pull_request]

permissions:
contents: read

jobs:
test-python:
name: test ${{ matrix.python_version }}
strategy:
fail-fast: false
matrix:
python_version: ['3.8', '3.9', '3.10', '3.11', '3.12', 'pypy3.9', 'pypy3.10']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: install rust stable
uses: dtolnay/rust-toolchain@stable
- name: cache rust
uses: Swatinem/rust-cache@v2
with:
key: test-v3
- name: set up python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- run: pip install tox
- run: tox -e py

test-os:
name: test on ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ubuntu, macos, windows]

runs-on: ${{ matrix.os }}-latest
steps:
- uses: actions/checkout@v4

- name: install rust stable
uses: dtolnay/rust-toolchain@stable

- name: cache rust
uses: Swatinem/rust-cache@v2

- name: set up python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- run: pip install tox
- run: tox -e py
linux:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target: [x86_64, x86, aarch64, armv7, s390x, ppc64le, i686]
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.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
manylinux: auto
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-linux-${{ matrix.target }}
path: dist

musllinux:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target: [x86_64, x86, aarch64, armv7, i686]
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.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.target }}
path: dist

windows:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
target: [x86, x64, aarch64]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
architecture: ${{ matrix.target != 'aarch64' && matrix.target || 'x64' }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-windows-${{ matrix.target }}
path: dist

macos:
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- runner: macos-12
target: x86_64
- runner: macos-14
target: aarch64
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.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-macos-${{ matrix.target }}
path: dist

emscripten:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: pip install pyodide-build
- name: Get Emscripten and Python version info
shell: bash
run: |
echo EMSCRIPTEN_VERSION=$(pyodide config get emscripten_version) >> $GITHUB_ENV
echo PYTHON_VERSION=$(pyodide config get python_version | cut -d '.' -f 1-2) >> $GITHUB_ENV
pip uninstall -y pyodide-build
- uses: mymindstorm/setup-emsdk@v12
with:
version: ${{ env.EMSCRIPTEN_VERSION }}
actions-cache-folder: emsdk-cache
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- run: pip install pyodide-build
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: wasm32-unknown-emscripten
args: --release --out dist -i ${{ env.PYTHON_VERSION }}
sccache: 'true'
rust-toolchain: nightly
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wasm-wheels
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:
needs: [linux, musllinux, windows, macos, emscripten, sdist]
if: success() && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- uses: actions/checkout@v4
- name: set up python
uses: actions/setup-python@v5
with:
python-version: 3.x
- run: pip install -U twine
- uses: actions/download-artifact@v4
- run: twine check --strict dist/*

- name: Release GitHub
uses: softprops/action-gh-release@v1
with:
files: |
dist/*
wasm-wheels/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Release PyPI
uses: pypa/gh-action-pypi-publish@release/v1
2 changes: 1 addition & 1 deletion template/cargo-generate.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[template]
exclude = [".github/workflows/build-release.yaml"]
exclude = [".github/workflows/build-release-cibw.yaml", ".github/workflows/build-release-maturin.yaml"]