onde 0.1.4

On-device inference engine for Apple silicon.
Documentation
name: Release SDK Rust (crates.io)

on:
  push:
    tags:
      - "[0-9]+.[0-9]+.[0-9]+"
  workflow_dispatch:

permissions:
  contents: read

jobs:
  publish:
    name: cargo publish
    runs-on: macos-26

    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: Install stable Rust toolchain
        uses: dtolnay/rust-toolchain@stable

      - name: Validate tag matches Cargo.toml version
        run: |
          TAG="${GITHUB_REF#refs/tags/}"
          CRATE_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/version = "//;s/"//')
          echo "Tag:     $TAG"
          echo "Crate:   $CRATE_VERSION"
          if [ "$TAG" != "$CRATE_VERSION" ]; then
            echo "error: tag $TAG does not match Cargo.toml version $CRATE_VERSION"
            exit 1
          fi

      # crates.io rejects git dependencies, even in platform-specific
      # [target.*.dependencies] sections. Swap every git-pinned mistralrs /
      # mistralrs-core line back to the crates.io version before publishing.
      # The commented-out version lines in Cargo.toml are the source of truth
      # for what to swap to.
      #
      # [patch.crates-io] is fine — cargo strips it from the published
      # Cargo.toml automatically.
      - name: Swap git deps to crates.io versions
        run: |
          python3 - <<'EOF'
          import re

          with open("Cargo.toml", "r") as f:
              src = f.read()

          replacements = [
              # mistralrs with metal feature (iOS, tvOS, visionOS, watchOS, macOS)
              (
                  r'mistralrs = \{ git = "[^"]+", branch = "[^"]+", features = \["metal"\] \}',
                  'mistralrs = { version = "0.8.1", features = ["metal"] }',
              ),
              # mistralrs-core with metal feature
              (
                  r'mistralrs-core = \{ git = "[^"]+", branch = "[^"]+", features = \["metal"\] \}',
                  'mistralrs-core = { version = "0.8.1", features = ["metal"] }',
              ),
              # mistralrs with no features (Android)
              (
                  r'mistralrs = \{ git = "[^"]+", branch = "[^"]+", features = \[\] \}',
                  'mistralrs = { version = "0.8.1", features = [] }',
              ),
              # mistralrs-core with no features (Android)
              (
                  r'mistralrs-core = \{ git = "[^"]+", branch = "[^"]+", features = \[\] \}',
                  'mistralrs-core = { version = "0.8.1", features = [] }',
              ),
              # mistralrs with no features at all (Windows, Linux)
              (
                  r'mistralrs = \{ git = "[^"]+", branch = "[^"]+" \}',
                  'mistralrs = { version = "0.8.1" }',
              ),
          ]

          for pattern, replacement in replacements:
              before = src
              src = re.sub(pattern, replacement, src)
              count = len(re.findall(pattern, before))
              if count:
                  print(f"  replaced {count}x: {replacement}")

          with open("Cargo.toml", "w") as f:
              f.write(src)

          print("Done.")
          EOF

      - name: Show modified Cargo.toml deps (sanity check)
        run: grep -E 'mistralrs' Cargo.toml

      - name: cargo publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        # --allow-dirty because we edited Cargo.toml without committing.
        # The published .crate archive contains the swapped version, which is
        # what crates.io needs. The git version stays in the repo for local dev.
        run: cargo publish --allow-dirty