Skip to content

feat: add native Rust extension for 29x faster performance (v6.0.0) (… #1

feat: add native Rust extension for 29x faster performance (v6.0.0) (…

feat: add native Rust extension for 29x faster performance (v6.0.0) (… #1

name: Build and Publish Rust Extension (json2xml-rs)
on:
push:
tags:
- 'rust-v*' # Trigger on tags like rust-v0.1.0
workflow_dispatch: # Allow manual trigger
inputs:
publish:
description: 'Publish to PyPI'
required: false
default: 'false'
type: boolean
env:
PACKAGE_NAME: json2xml_rs
PYTHON_VERSION: '3.12'
jobs:
# Build wheels for Linux
linux:
runs-on: ubuntu-latest
strategy:
matrix:
target: [x86_64, aarch64]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
manylinux: auto
working-directory: rust
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-linux-${{ matrix.target }}
path: rust/dist
# Build wheels for Windows
windows:
runs-on: windows-latest
strategy:
matrix:
target: [x64]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: ${{ matrix.target }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target == 'x64' && 'x86_64-pc-windows-msvc' || 'i686-pc-windows-msvc' }}
args: --release --out dist --find-interpreter
sccache: 'true'
working-directory: rust
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-windows-${{ matrix.target }}
path: rust/dist
# Build wheels for macOS
macos:
runs-on: macos-latest
strategy:
matrix:
target: [x86_64, aarch64]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target == 'x86_64' && 'x86_64-apple-darwin' || 'aarch64-apple-darwin' }}
args: --release --out dist --find-interpreter
sccache: 'true'
working-directory: rust
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-macos-${{ matrix.target }}
path: rust/dist
# Build source distribution
sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build sdist
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist
working-directory: rust
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
name: wheels-sdist
path: rust/dist
# Publish to PyPI
publish:
name: Publish to PyPI
runs-on: ubuntu-latest
needs: [linux, windows, macos, sdist]
if: startsWith(github.ref, 'refs/tags/rust-v') || (github.event_name == 'workflow_dispatch' && github.event.inputs.publish == 'true')
environment:
name: pypi
url: https://pypi.org/project/json2xml-rs/
permissions:
id-token: write # Required for trusted publishing
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
pattern: wheels-*
path: dist
merge-multiple: true
- name: List artifacts
run: ls -la dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
# For trusted publishing, no token needed if configured on PyPI
# Otherwise use: password: ${{ secrets.PYPI_API_TOKEN_RUST }}
skip-existing: true
# Test the wheels
test:
name: Test wheels
runs-on: ${{ matrix.os }}
needs: [linux, windows, macos]
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.10', '3.11', '3.12', '3.13']
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Download wheels
uses: actions/download-artifact@v4
with:
pattern: wheels-*
path: dist
merge-multiple: true
- name: Install wheel
run: |
pip install --find-links dist json2xml_rs
pip install pytest
- name: Test import
run: |
python -c "from json2xml_rs import dicttoxml; print('Import successful!')"
python -c "from json2xml_rs import dicttoxml; result = dicttoxml({'test': 'value'}); print(result.decode())"
- name: Run tests
run: |
pip install -e .
pytest tests/test_rust_dicttoxml.py -v