linkcell 0.3.3

Periodic linked-cell k-nearest neighbour search for molecular simulations
Documentation
name: ci

on:
  push:
    branches: [main]
    tags: ['v*']
  pull_request:

# windows-latest omitted: meson/cmake wrap cargo via custom_target that
# copies cargo-target/release/<lib> with POSIX path joins, and the
# cdylib + cbindgen install layout is unix-shaped.

jobs:
  fmt:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt
      - run: cargo fmt --check

  header-check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      # Pin matches the version comment cbindgen writes into include/linkcell.h.
      - run: cargo install cbindgen --version 0.29.4
      - run: scripts/regen-capi-headers.sh --check

  python:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: actions/setup-python@v5
        with:
          python-version: '3.12'
      - uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
          key: ${{ runner.os }}-py-${{ hashFiles('Cargo.lock', 'python/Cargo.toml') }}
          restore-keys: |
            ${{ runner.os }}-py-
      - name: Install Python test deps
        run: |
          python -m venv .venv
          . .venv/bin/activate
          python -m pip install --upgrade pip
          pip install maturin pytest numpy
          pip install torch --index-url https://download.pytorch.org/whl/cpu
      - name: maturin develop
        run: |
          . .venv/bin/activate
          maturin develop
      - name: pytest
        run: |
          . .venv/bin/activate
          pytest tests/python -q

  cargo:
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest]
        crate:
          - name: default
            flags: ""
          - name: serial
            flags: --no-default-features --features capi
    name: cargo (${{ matrix.os }}, ${{ matrix.crate.name }})
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy
      - uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
          key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-cargo-
      - run: cargo test --locked ${{ matrix.crate.flags }}
      - run: cargo clippy --locked --all-targets ${{ matrix.crate.flags }} -- -D warnings

  meson:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
          key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-cargo-
      - uses: actions/setup-python@v5
        with:
          python-version: '3.12'
      - run: pip install meson ninja
      - run: meson setup build
      - run: meson compile -C build
      - run: meson test -C build --print-errorlogs
      - run: meson install -C build --destdir "$PWD/destdir"
      - name: pkg-config after meson install
        run: |
          prefix="$PWD/destdir/usr/local"
          export PKG_CONFIG_PATH="$prefix/lib/x86_64-linux-gnu/pkgconfig:$prefix/lib/pkgconfig"
          pkg-config --exists --print-errors linkcell
          pkg-config --modversion linkcell
          pkg-config --cflags --libs linkcell
          test -f "$prefix/include/linkcell.h"
          test -f "$prefix/include/linkcell.hpp"
          test -f "$prefix/include/linkcell_gpu.h"
          test -f "$prefix/include/linkcell_gpu.hpp"
          test -f "$prefix/lib/x86_64-linux-gnu/liblinkcell.a" \
            -o -f "$prefix/lib/liblinkcell.a"
          test -f "$prefix/lib/x86_64-linux-gnu/liblinkcell.so" \
            -o -f "$prefix/lib/liblinkcell.so" \
            -o -f "$prefix/lib/liblinkcell.dylib"

  cmake:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
          key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-cargo-
      - run: cmake -S . -B build -DCMAKE_INSTALL_PREFIX="$PWD/prefix"
      - run: cmake --build build
      - run: ctest --test-dir build --output-on-failure
      - run: cmake --install build
      - name: find_package and pkg-config after cmake install
        run: |
          test -f prefix/include/linkcell.h
          test -f prefix/lib/liblinkcell.a
          test -f prefix/lib/liblinkcell.so -o -f prefix/lib/liblinkcell.dylib
          test -f prefix/lib/pkgconfig/linkcell.pc
          test -f prefix/lib/cmake/linkcell/linkcellConfig.cmake
          export PKG_CONFIG_PATH="$PWD/prefix/lib/pkgconfig"
          pkg-config --exists --print-errors linkcell
          pkg-config --modversion linkcell
          cmake -S tests/cmake-consumer -B find-build \
            -DCMAKE_PREFIX_PATH="$PWD/prefix" \
            -DLINKCELL_EXAMPLE="$PWD/examples/two_points.cpp"
          cmake --build find-build
          export LD_LIBRARY_PATH="$PWD/prefix/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
          export DYLD_LIBRARY_PATH="$PWD/prefix/lib${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH}"
          ./find-build/find_lc