region 4.0.0

Cross-platform virtual memory API
Documentation
name: CI

on:
  push:
  pull_request:

env:
  CARGO_TERM_COLOR: always
  RUST_BACKTRACE: 1
  RUST_TEST_THREADS: 1

jobs:
  test:
    name: Test (${{ matrix.target }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          # Linux
          - target: i686-unknown-linux-gnu
            os: ubuntu-latest
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
          - target: x86_64-unknown-linux-musl
            os: ubuntu-latest

          # Cross-compiled Linux
          - target: armv7-unknown-linux-gnueabihf
            os: ubuntu-latest
            use-cross: true
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
            use-cross: true

          # Windows
          - target: i686-pc-windows-msvc
            os: windows-latest
          - target: x86_64-pc-windows-msvc
            os: windows-latest
          - target: x86_64-pc-windows-gnu
            os: windows-latest

          # macOS
          - target: aarch64-apple-darwin
            os: macos-latest
          - target: x86_64-apple-darwin
            os: macos-15

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

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}

      - name: Install i686 Linux libraries
        if: matrix.target == 'i686-unknown-linux-gnu'
        run: |
          sudo apt-get update
          sudo apt-get install -y gcc-multilib libc6-dev-i386

      - name: Install cross
        if: matrix.use-cross
        uses: taiki-e/install-action@v2
        with:
          tool: cross

      - name: Run tests (cross)
        if: matrix.use-cross
        run: cross test --target ${{ matrix.target }}

      - name: Run tests (cargo)
        if: ${{ !matrix.use-cross }}
        run: cargo test --target ${{ matrix.target }}

  test-bsd:
    name: Test (${{ matrix.target }})
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: cpa.sh {0}
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: x86_64-unknown-freebsd
            os: freebsd
            os-version: '14.3'
          - target: x86_64-unknown-openbsd
            os: openbsd
            os-version: '7.7'
            install: sudo pkg_add rust
          - target: x86_64-unknown-netbsd
            os: netbsd
            os-version: '10.1'
            prepare: sudo pkgin -y install mozilla-rootcerts-openssl

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

      - name: Start VM
        uses: cross-platform-actions/action@v1.3.0
        with:
          operating_system: ${{ matrix.os }}
          architecture: x86-64
          version: ${{ matrix.os-version }}

      - name: Prepare packages
        if: matrix.prepare != ''
        run: ${{ matrix.prepare }}

      - name: Install Rust
        run: |
          ${{ matrix.install || format('
            curl https://sh.rustup.rs -sSf | sh -s -- -q -y --profile minimal --default-toolchain stable --target {0}
            . "$HOME/.cargo/env"
          ', matrix.target) }}

      - name: Run tests
        run: |
          if [ -f "$HOME/.cargo/env" ]; then
            . "$HOME/.cargo/env"
          fi
          cargo test

  check:
    name: Check (${{ matrix.target }})
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: x86_64-unknown-illumos
            toolchain: stable
          - target: x86_64-unknown-redox
            toolchain: stable
          # Android runtime testing via cross currently fails to link libunwind in
          # the stock image; keep compile coverage here instead.
          - target: aarch64-linux-android
            toolchain: stable

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

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.toolchain }}
          targets: ${{ matrix.target }}

      - name: Check
        run: cargo +${{ matrix.toolchain }} check --target ${{ matrix.target }}

  check-hurd:
    name: Check (x86_64-unknown-hurd-gnu)
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v6

      # Hurd is Tier 3 and does not ship prebuilt rust-std via rustup. Build only the
      # no_std + alloc core from source so we still get compile coverage for the
      # Linux-like /proc maps backend without requiring a full std target image.
      - name: Install nightly + rust-src
        uses: dtolnay/rust-toolchain@nightly
        with:
          components: rust-src

      - name: Check with build-std (no_std)
        run: >
          cargo +nightly check
          -Z build-std=core,alloc
          --target x86_64-unknown-hurd-gnu
          --no-default-features

  msrv:
    name: MSRV
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v6

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

      - name: Check MSRV
        run: cargo check

  lint:
    name: Lint
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy

      - name: rustfmt
        run: cargo fmt --all -- --check

      - name: clippy
        run: cargo clippy --all-targets -- -D warnings