Skip to content
Merged
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
189 changes: 189 additions & 0 deletions .github/workflows/build-rust-wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
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
117 changes: 117 additions & 0 deletions .github/workflows/rust-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Rust Extension CI

on:
push:
branches: [master, main]
paths:
- 'rust/**'
- 'tests/test_rust_dicttoxml.py'
- '.github/workflows/rust-ci.yml'
pull_request:
branches: [master, main]
paths:
- 'rust/**'
- 'tests/test_rust_dicttoxml.py'
- '.github/workflows/rust-ci.yml'
workflow_dispatch: # Allow manual trigger

env:
CARGO_TERM_COLOR: always

jobs:
rust-lint:
name: Rust Lint & Format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: rustfmt, clippy

- name: Check formatting
working-directory: rust
run: cargo fmt --check

- name: Run clippy
working-directory: rust
run: cargo clippy --all-targets --all-features -- -D warnings

rust-test:
name: Build & Test (${{ matrix.os }}, Python ${{ matrix.python-version }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.10', '3.11', '3.12', '3.13']
steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1

- name: Install maturin
run: pip install maturin

- name: Build Rust extension
working-directory: rust
run: maturin build --release

- name: Install the wheel
shell: bash
run: |
pip install rust/target/wheels/*.whl

- name: Install test dependencies
run: |
pip install pytest defusedxml
pip install -e .

- name: Verify import
run: |
python -c "from json2xml_rs import dicttoxml; print('Rust extension loaded!')"
python -c "from json2xml.dicttoxml_fast import get_backend; print(f'Backend: {get_backend()}')"

- name: Run Rust-specific tests
run: pytest tests/test_rust_dicttoxml.py -v

- name: Run full test suite
run: pytest tests/ -v --ignore=tests/test_cli.py

benchmark:
name: Performance Benchmark
runs-on: ubuntu-latest
# Only run benchmarks on push to main/master or manual trigger, not on PRs
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1

- name: Install maturin
run: pip install maturin

- name: Build Rust extension
working-directory: rust
run: maturin build --release

- name: Install dependencies
run: |
pip install rust/target/wheels/*.whl
pip install -e .

- name: Run benchmark
run: python benchmark_rust.py
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,9 @@ dmypy.json
.pyre/

.idea/

# Rust
rust/target/
Cargo.lock
*.rlib
*.rmeta
Loading
Loading