medius 2.2.1

Host control library for the medius transparent mouse passthrough box
Documentation
name: C ABI + bindings

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

env:
  CARGO_TERM_COLOR: always
  CARGO_INCREMENTAL: 0
  CARGO_NET_RETRY: 10
  RUST_BACKTRACE: short
  RUSTUP_MAX_RETRIES: 10

jobs:

  capi:
    name: C ABI build (${{ matrix.os }})
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    steps:
    - uses: actions/checkout@v4
    - uses: dtolnay/rust-toolchain@stable
    - name: Install libudev (Linux)
      if: runner.os == 'Linux'
      run: sudo apt-get update && sudo apt-get install -y libudev-dev
    - uses: actions/cache@v4
      with:
        path: |
          ~/.cargo/registry
          ~/.cargo/git
          target
        key: ${{ runner.os }}-capi-${{ hashFiles('**/Cargo.toml') }}
    - name: Build (default features)
      run: cargo build -p medius-capi --verbose
    - name: Build (mock + flash)
      run: cargo build -p medius-capi --features mock,flash --verbose
    - name: Test (mock)
      run: cargo test -p medius-capi --features mock --verbose

  capi-lint:
    name: C ABI clippy + fmt
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: dtolnay/rust-toolchain@stable
      with:
        components: clippy, rustfmt
    - name: Install libudev
      run: sudo apt-get update && sudo apt-get install -y libudev-dev
    - name: Format
      run: cargo fmt -p medius-capi -- --check
    - name: Clippy
      run: cargo clippy -p medius-capi --all-targets --all-features -- -D warnings

  cbindgen-drift:
    name: cbindgen header is up to date
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: dtolnay/rust-toolchain@stable
    - name: Install cbindgen (pinned)
      run: cargo install cbindgen --version 0.29.4 --locked
    - name: Regenerate the header
      run: bash tools/gen-header.sh
    - name: Fail if the committed header is stale
      run: git diff --exit-code medius-capi/include/medius.h

  python:
    name: Python bindings
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: dtolnay/rust-toolchain@stable
    - uses: actions/setup-python@v5
      with:
        python-version: '3.x'
    - name: Install libudev
      run: sudo apt-get update && sudo apt-get install -y libudev-dev
    - name: Install pytest
      run: python -m pip install --upgrade pip pytest
    - name: Run the mock-backed suite
      # conftest builds the mock cdylib and points MEDIUS_LIB at it.
      run: python -m pytest bindings/python/tests/ -v

  wheels:
    name: Wheels (${{ matrix.os }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        # One native-arch runner each: linux x86_64 + arm64, macOS x86_64 +
        # arm64, windows amd64. The wheel is py3-none, so one per platform.
        os: [ubuntu-latest, ubuntu-24.04-arm, macos-13, macos-14, windows-latest]
    steps:
    - uses: actions/checkout@v4
    - uses: actions/setup-python@v5
      with:
        python-version: '3.x'
    - name: Build the self-contained sdist
      shell: bash
      run: |
        python -m pip install build
        python -m build --sdist -o dist bindings/python
    - name: Build wheels from the sdist
      shell: bash
      run: |
        python -m pip install 'cibuildwheel~=2.21'
        python -m cibuildwheel --output-dir wheelhouse dist/medius-*.tar.gz
    - uses: actions/upload-artifact@v4
      with:
        name: wheels-${{ matrix.os }}
        path: ./wheelhouse/*.whl