sqlitegis 0.4.0

SQLiteGIS: PostGIS-style spatial functions for SQLite in pure Rust.
Documentation
name: CI

on:
  push:
    branches: [main]
  pull_request:
  workflow_dispatch:

permissions:
  contents: read

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

env:
  CARGO_TERM_COLOR: always

defaults:
  run:
    shell: bash

jobs:
  semver:
    name: Semver
    runs-on: ubuntu-26.04
    timeout-minutes: 30
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          persist-credentials: false
      - uses: obi1kenobi/cargo-semver-checks-action@6b69fcf40e9b5fb17adeb57e4b6ecd020649a239 # v2
        with:
          package: sqlitegis

  hooks:
    name: prek run --all-files
    runs-on: ubuntu-26.04
    timeout-minutes: 45
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy, rustfmt
      - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2
      - name: Install prek
        run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/j178/prek/releases/latest/download/prek-installer.sh | sh
      - run: prek run --all-files

  fmt:
    name: Rustfmt
    runs-on: ubuntu-26.04
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt
      - run: cargo fmt --all -- --check

  clippy:
    name: Clippy (${{ matrix.target }})
    runs-on: ubuntu-26.04
    timeout-minutes: 30
    strategy:
      fail-fast: false
      matrix:
        include:
          # Default features, which are now the pure-Rust core -- catches
          # accidental dep leaks into core.
          - target: workspace
            cmd: cargo clippy --workspace --all-targets -- -D warnings
          # Union: every feature on, including sqlite-extension.
          - target: workspace-all-features
            cmd: cargo clippy --workspace --all-features --all-targets -- -D warnings
          # The Diesel + SQLite build, the most common consumer build.
          - target: diesel-sqlite
            cmd: cargo clippy -p sqlitegis --features diesel-sqlite --all-targets -- -D warnings
          # Diesel without a backend -- feature-interaction check the
          # all-features run cannot catch (it always has sqlite on too).
          - target: diesel-only
            cmd: cargo clippy -p sqlitegis --no-default-features --features diesel --all-targets -- -D warnings
          # Postgres backend without libpq.
          - target: diesel-postgres
            cmd: cargo clippy -p sqlitegis --features diesel-postgres --all-targets -- -D warnings
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy
      - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2
      - run: ${{ matrix.cmd }}

  clippy-wasm:
    name: Clippy (WASM)
    runs-on: ubuntu-26.04
    timeout-minutes: 25
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy
          targets: wasm32-unknown-unknown
      - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2
      - run: cargo clippy -p sqlitegis --features sqlite --target wasm32-unknown-unknown -- -D warnings
      - run: cargo clippy -p sqlitegis --features diesel-postgres --target wasm32-unknown-unknown -- -D warnings

  test:
    name: Test (${{ matrix.target }})
    runs-on: ubuntu-26.04
    timeout-minutes: 45
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: workspace
            cmd: cargo test --workspace --features diesel-sqlite
          # cargo test leaves the cdylib in the build dir, so build it to target/debug first.
          - target: sqlite-extension
            cmd: cargo build -p sqlitegis --features sqlite-extension && cargo test -p sqlitegis --features sqlite-extension --test sqlite_integration
          # All features on so the Diesel example in the README, which the
          # crate root includes, is compiled and run rather than skipped.
          - target: doctest-workspace
            cmd: cargo test --doc --workspace --all-features
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2
      - run: ${{ matrix.cmd }}

  msrv:
    name: MSRV (1.88)
    runs-on: ubuntu-26.04
    timeout-minutes: 20
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - uses: dtolnay/rust-toolchain@1.88.0
      - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2
      - run: cargo check --workspace
      - run: cargo check -p sqlitegis --features diesel-sqlite
      - run: cargo check -p sqlitegis --features diesel-postgres

  wasm-test:
    name: WASM Test (sqlite)
    runs-on: ubuntu-26.04
    timeout-minutes: 25
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: wasm32-unknown-unknown
      - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2
      # Pin to the wasm-bindgen version recorded in Cargo.lock so the CLI
      # and the .wasm file schema versions match. taiki-e/install-action
      # defaults to latest, which periodically drifts ahead of our lock.
      - uses: taiki-e/install-action@073e1fd0bc889c9aee68dbaaa927cde1b5653a83 # v2
        with:
          tool: wasm-bindgen-cli@0.2.121
      - run: cargo test -p sqlitegis --features sqlite --target wasm32-unknown-unknown --test sqlite_wasm
        env:
          CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER: wasm-bindgen-test-runner
          WASM_BINDGEN_TEST_TIMEOUT: 120

  wasm-test-diesel:
    name: WASM Test (Diesel)
    runs-on: ubuntu-26.04
    timeout-minutes: 25
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: wasm32-unknown-unknown
      - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2
      # Pin to the wasm-bindgen version recorded in Cargo.lock so the CLI
      # and the .wasm file schema versions match. taiki-e/install-action
      # defaults to latest, which periodically drifts ahead of our lock.
      - uses: taiki-e/install-action@073e1fd0bc889c9aee68dbaaa927cde1b5653a83 # v2
        with:
          tool: wasm-bindgen-cli@0.2.121
      - run: cargo test -p sqlitegis --features diesel-sqlite --target wasm32-unknown-unknown --test diesel_wasm_integration
        env:
          CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER: wasm-bindgen-test-runner
          WASM_BINDGEN_TEST_TIMEOUT: 120

  docs:
    name: Docs
    runs-on: ubuntu-26.04
    timeout-minutes: 15
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2
      - run: cargo doc --workspace --no-deps
        env:
          RUSTDOCFLAGS: "-D warnings"

  # Full supply-chain policy enforcement (licenses, banned/duplicate crates,
  # registry sources). The policy lives in deny.toml. --all-features so dev
  # and optional dependency trees are covered too.
  supply-chain:
    name: Supply Chain (cargo-deny)
    runs-on: ubuntu-26.04
    timeout-minutes: 15
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - uses: EmbarkStudios/cargo-deny-action@bb119f768ea239e765aeaef5769558d4f21213aa # v2
        with:
          command: check
          arguments: --all-features

  # Miri interprets the MIR to catch undefined behavior (out-of-bounds reads,
  # invalid provenance, uninitialized reads) that rustc and tests miss. It
  # cannot interpret the SQLite C library or the inline assembly in i_overlay
  # (geometry algorithms), so it is scoped to the pure byte-level boundary:
  # the EWKB parser plus the accessor/I/O/constructor modules that decode and
  # serialize untrusted blobs. -Zmiri-strict-provenance uses the strictest
  # pointer-provenance model.
  miri:
    name: Miri (EWKB byte-level boundary)
    runs-on: ubuntu-26.04
    timeout-minutes: 30
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - uses: dtolnay/rust-toolchain@nightly
        with:
          components: miri
      - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2
      - run: cargo miri setup --no-default-features
      - name: Run Miri over the untrusted-input boundary
        env:
          MIRIFLAGS: -Zmiri-strict-provenance
        run: |
          for filter in \
            core::ewkb \
            core::functions::accessors \
            core::functions::io \
            core::functions::constructors; do
            echo "::group::miri $filter"
            cargo miri test --no-default-features --lib "$filter"
            echo "::endgroup::"
          done

  # README is included verbatim into the crate root docs via
  # include_str! in src/lib.rs, so any relative markdown link there
  # gets resolved against docs.rs/sqlitegis/latest/sqlitegis/ instead
  # of the GitHub repo and produces a 404. A regex grep fails fast on
  # that mistake.
  link-check:
    name: Doc Link Check
    runs-on: ubuntu-26.04
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - name: Forbid relative links to repo files in README
        run: |
          # Match markdown links whose target does not start with http:
          # https:, mailto:, #, or a known intra-doc scheme. Allow image
          # data: URLs by skipping <... preceded by !. Fail with file:line
          # output so the violation is obvious in the run summary.
          if grep -nE '[^!]\]\(([^h#m][^)]*\.(md|rs|toml|yml|yaml|svg|png))\)' README.md; then
            echo "::error file=README.md::Relative link to a repo file detected. include_str! in lib.rs makes docs.rs resolve relative paths against docs.rs/<crate>/latest/, so these must use absolute https://github.com/... URLs." >&2
            exit 1
          fi

  # Native runtime tests on ARM64 Linux. Covers the case where sqlitegis
  # is embedded in a server or workstation running aarch64 Linux (Graviton,
  # Ampere, Raspberry Pi 4/5).
  linux-arm64:
    name: Linux ARM64 Runtime Tests
    runs-on: ubuntu-24.04-arm
    timeout-minutes: 35
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2
      - name: Verify host architecture
        run: rustc -vV
      - name: Run tests
        run: cargo test -p sqlitegis --features diesel-sqlite --verbose --locked

  # Cross link-check for aarch64 musl, the typical edge/container target
  # (Alpine, distroless images). cargo-cross handles the sysroot so we do
  # not have to pre-install musl-dev on the runner.
  edge-musl-link-check:
    name: Edge Cross Link Check (aarch64-unknown-linux-musl)
    runs-on: ubuntu-26.04
    timeout-minutes: 40
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: aarch64-unknown-linux-musl
      - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2
      - name: Install cross
        uses: taiki-e/install-action@073e1fd0bc889c9aee68dbaaa927cde1b5653a83 # v2
        with:
          tool: cross
      - name: Cross test build (no-run, musl)
        run: |
          cross test \
            --target aarch64-unknown-linux-musl \
            -p sqlitegis \
            --features diesel-sqlite,bundled-sqlite \
            --no-run \
            --locked

  # ARMv7 link check using the host cross toolchain (avoids old glibc in
  # cross images). Covers Raspberry Pi 2/3 32-bit and ARMv7 industrial
  # boards.
  armv7-link-check:
    name: ARMv7 Link Check
    runs-on: ubuntu-26.04
    timeout-minutes: 40
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: armv7-unknown-linux-gnueabihf
      - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2
      - name: Install ARMv7 cross-linker
        run: |
          # GitHub Ubuntu images sometimes ship an Azure CLI apt source that
          # returns 403 and breaks apt-get update. Remove it defensively.
          if [ -f /etc/apt/sources.list.d/azure-cli.list ]; then
            sudo rm -f /etc/apt/sources.list.d/azure-cli.list
          fi
          sudo apt-get update
          sudo apt-get install -y --no-install-recommends \
            gcc-arm-linux-gnueabihf \
            libc6-dev-armhf-cross
      - name: ARMv7 test build (no-run)
        run: cargo test -p sqlitegis --features diesel-sqlite,bundled-sqlite --target armv7-unknown-linux-gnueabihf --no-run --locked
        env:
          CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER: arm-linux-gnueabihf-gcc
          CC_armv7_unknown_linux_gnueabihf: arm-linux-gnueabihf-gcc
          AR_armv7_unknown_linux_gnueabihf: arm-linux-gnueabihf-ar
          CFLAGS_armv7_unknown_linux_gnueabihf: --sysroot=/usr/arm-linux-gnueabihf

  coverage:
    name: Coverage
    runs-on: ubuntu-26.04
    timeout-minutes: 30
    needs: [fmt, clippy, test, wasm-test, wasm-test-diesel, docs]
    # Codecov authenticates the upload with a GitHub OIDC token.
    permissions:
      contents: read
      id-token: write
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          ref: ${{ github.event.pull_request.head.sha || github.sha }}
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2
      - uses: taiki-e/install-action@cargo-llvm-cov
      - run: cargo build -p sqlitegis --features sqlite-extension
      - run: cargo llvm-cov --workspace --lcov --output-path lcov.info
      - run: cargo llvm-cov --no-clean -p sqlitegis --features diesel-sqlite --lcov --output-path lcov-diesel.info
      - run: cargo llvm-cov --no-clean -p sqlitegis --features diesel-postgres-connection --test diesel_postgres_integration --lcov --output-path lcov-postgres.info
      - uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
        with:
          use_oidc: true
          files: lcov.info,lcov-diesel.info,lcov-postgres.info
          fail_ci_if_error: false
          verbose: true