linkcell 0.3.11

Periodic linked-cell cutoff pairs and k-nearest neighbour search
Documentation
name: ci

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

jobs:
  fmt:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c # stable
        with:
          components: rustfmt
      - run: cargo fmt --check

  header-check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c # 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@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c # stable
      - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
        with:
          python-version: '3.12'
      - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
        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, windows-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@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c # stable
        with:
          components: clippy
      - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
        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:
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    name: meson (${{ matrix.os }})
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c # stable
      - name: Configure MSVC
        if: runner.os == 'Windows'
        shell: pwsh
        run: .github/scripts/setup-msvc.ps1
      - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
          key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-cargo-
      - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
        with:
          python-version: '3.12'
      - run: pip install meson ninja
      - name: Meson setup
        if: runner.os != 'Windows'
        run: meson setup build --prefix "$PWD/prefix" --libdir lib
        shell: bash
      - name: Meson setup
        if: runner.os == 'Windows'
        run: meson setup build --prefix "$env:GITHUB_WORKSPACE/prefix" --libdir lib
        shell: pwsh
      - run: meson compile -C build
      - run: meson test -C build --print-errorlogs
      - run: meson install -C build
      - name: Installed headers and libraries
        shell: bash
        run: |
          prefix="$PWD/prefix"
          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"
          case "$RUNNER_OS" in
            Windows)
              test -f "$prefix/bin/linkcell.dll"
              test -f "$prefix/lib/linkcell.dll.lib"
              test -f "$prefix/lib/linkcell.lib"
              test -f "$prefix/lib/linkcell_gpu.lib"
              ;;
            macOS)
              test -f "$prefix/lib/liblinkcell.dylib"
              test -f "$prefix/lib/liblinkcell.a"
              test -f "$prefix/lib/liblinkcell_gpu.a"
              ;;
            Linux)
              test -f "$prefix/lib/liblinkcell.so"
              test -f "$prefix/lib/liblinkcell.a"
              test -f "$prefix/lib/liblinkcell_gpu.a"
              ;;
          esac
      - name: pkg-config after meson install
        if: runner.os != 'Windows'
        run: |
          prefix="$PWD/prefix"
          export PKG_CONFIG_PATH="$prefix/lib/pkgconfig"
          pkg-config --exists --print-errors linkcell
          pkg-config --modversion linkcell
          pkg-config --cflags --libs linkcell
          pkg-config --exists --print-errors linkcell-gpu
          pkg-config --modversion linkcell-gpu
          c++ -std=c++17 tests/cmake-consumer/gpu.cpp \
            $(pkg-config --cflags --libs linkcell-gpu) \
            -o build/installed-gpu-consumer

  cmake:
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    name: cmake (${{ matrix.os }})
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c # stable
      - name: Configure MSVC
        if: runner.os == 'Windows'
        shell: pwsh
        run: .github/scripts/setup-msvc.ps1
      - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
        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"
        shell: bash
      - run: cmake --build build --config Release
      - run: ctest --test-dir build -C Release --output-on-failure
      - run: cmake --install build --config Release
      - name: find_package after cmake install
        shell: bash
        run: |
          test -f prefix/include/linkcell.h
          test -f prefix/lib/cmake/linkcell/linkcellConfig.cmake
          if [[ "$RUNNER_OS" == "Windows" ]]; then
            test -f prefix/bin/linkcell.dll
            test -f prefix/lib/linkcell.dll.lib
            test -f prefix/lib/linkcell.lib
            test -f prefix/lib/linkcell_gpu.lib
          elif [[ "$RUNNER_OS" == "macOS" ]]; then
            test -f prefix/lib/liblinkcell.dylib
            test -f prefix/lib/liblinkcell.a
            test -f prefix/lib/liblinkcell_gpu.a
          else
            test -f prefix/lib/liblinkcell.so
            test -f prefix/lib/liblinkcell.a
            test -f prefix/lib/liblinkcell_gpu.a
          fi
          cmake -S tests/cmake-consumer -B find-build \
            -DCMAKE_PREFIX_PATH="$PWD/prefix" \
            -DLINKCELL_C_EXAMPLE="$PWD/examples/two_points.c" \
            -DLINKCELL_CPP_EXAMPLE="$PWD/examples/two_points.cpp"
          cmake --build find-build --config Release
          if [[ "$RUNNER_OS" == "Windows" ]]; then
            export PATH="$PWD/prefix/bin:$PATH"
          elif [[ "$RUNNER_OS" == "macOS" ]]; then
            export DYLD_LIBRARY_PATH="$PWD/prefix/lib${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH}"
          else
            export LD_LIBRARY_PATH="$PWD/prefix/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
          fi
          ctest --test-dir find-build -C Release --output-on-failure
      - name: pkg-config after cmake install
        if: runner.os != 'Windows'
        run: |
          test -f prefix/lib/pkgconfig/linkcell.pc
          export PKG_CONFIG_PATH="$PWD/prefix/lib/pkgconfig"
          pkg-config --exists --print-errors linkcell
          pkg-config --modversion linkcell

  static-minimage:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          repository: lode-org/minimage
          ref: ce6dfb175f32459de1ee06dfeb70e8a718f61876
          path: build/minimage-source
      - uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c # stable
      - run: cmake -S tests/static-minimage -B build/static-minimage -DMINIMAGE_SOURCE="$PWD/build/minimage-source"
      - run: cmake --build build/static-minimage --target static_minimage --parallel 2
      - run: ctest --test-dir build/static-minimage --output-on-failure