# Maintainer: Maksim Bondarenkov <maksapple2306@gmail.com>

_realname=procs
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.14.10
pkgrel=1
pkgdesc="A modern replacement for ps written in Rust (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://github.com/dalance/procs'
msys2_references=(
  'purl: pkg:cargo/procs'
)
license=('spdx:MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-rust" "${MINGW_PACKAGE_PREFIX}-asciidoctor")
source=("https://github.com/dalance/procs/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('7b287ac253fd1d202b0ea6a9a8ba2ed97598cf8e7dfd539bd40e382c6dc6d350')

prepare() {
  cd "${_realname}-${pkgver}"

  cargo fetch --locked --target "${RUST_CHOST}"
}

build() {
  cd "${_realname}-${pkgver}"

  export WINAPI_NO_BUNDLED_LIBRARIES=1
  cargo build --release --frozen
  asciidoctor -b manpage man/procs.1.adoc
}

check() {
  cd "${_realname}-${pkgver}"

  cargo test --release --frozen
}

package() {
  cd "${_realname}-${pkgver}"

  cargo install \
    --offline \
    --no-track \
    --frozen \
    --path . \
    --root "${pkgdir}${MINGW_PREFIX}"

  local _complete="target/release/procs --gen-completion-out"
  $_complete bash | install -Dm644 /dev/stdin "${pkgdir}${MINGW_PREFIX}/share/bash-completion/completions/procs"
  $_complete fish | install -Dm644 /dev/stdin "${pkgdir}${MINGW_PREFIX}/share/fish/vendor_completions.d/procs.fish"
  $_complete zsh  | install -Dm644 /dev/stdin "${pkgdir}${MINGW_PREFIX}/share/zsh/site-functions/_procs"
  install -Dm644 man/procs.1 "${pkgdir}${MINGW_PREFIX}/share/man/man1/procs.1"
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
