From 8b5084e011cf3fadd2aa39f34f806a585595c57e Mon Sep 17 00:00:00 2001 From: Spencer Phillip Young Date: Wed, 31 Jul 2024 23:45:22 -0700 Subject: [PATCH 1/3] add a maturin-action-based action --- ...d-release.yaml => build-release-cibw.yaml} | 0 .../workflows/build-release-maturin.yaml | 182 ++++++++++++++++++ template/cargo-generate.toml | 2 +- 3 files changed, 183 insertions(+), 1 deletion(-) rename template/.github/workflows/{build-release.yaml => build-release-cibw.yaml} (100%) create mode 100644 template/.github/workflows/build-release-maturin.yaml diff --git a/template/.github/workflows/build-release.yaml b/template/.github/workflows/build-release-cibw.yaml similarity index 100% rename from template/.github/workflows/build-release.yaml rename to template/.github/workflows/build-release-cibw.yaml diff --git a/template/.github/workflows/build-release-maturin.yaml b/template/.github/workflows/build-release-maturin.yaml new file mode 100644 index 0000000..354a19c --- /dev/null +++ b/template/.github/workflows/build-release-maturin.yaml @@ -0,0 +1,182 @@ +name: CI + +on: [push, pull_request] + +permissions: + contents: read + +jobs: + 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 diff --git a/template/cargo-generate.toml b/template/cargo-generate.toml index 832af6f..ae74d88 100644 --- a/template/cargo-generate.toml +++ b/template/cargo-generate.toml @@ -1,2 +1,2 @@ [template] -exclude = [".github/workflows/build-release.yaml"] +exclude = [".github/workflows/build-release-cibw.yaml", ".github/workflows/build-release-maturin.yaml"] From e5540edd6ce03fc4267b1c6edab2e1d02d64cea9 Mon Sep 17 00:00:00 2001 From: Spencer Phillip Young Date: Wed, 31 Jul 2024 23:45:37 -0700 Subject: [PATCH 2/3] update readme --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 52e97cd..48df5c3 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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. From 638d726c73c43d5f6fb0b0bb2f0416b01dab0b71 Mon Sep 17 00:00:00 2001 From: Spencer Phillip Young Date: Thu, 1 Aug 2024 00:20:18 -0700 Subject: [PATCH 3/3] add tests --- .../workflows/build-release-maturin.yaml | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/template/.github/workflows/build-release-maturin.yaml b/template/.github/workflows/build-release-maturin.yaml index 354a19c..4c89826 100644 --- a/template/.github/workflows/build-release-maturin.yaml +++ b/template/.github/workflows/build-release-maturin.yaml @@ -6,6 +6,53 @@ 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: