_realname=watchexec
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.25.1
pkgrel=1
msys2_repository_url="https://github.com/watchexec/watchexec/"
url="https://watchexec.github.io/"
pkgdesc="Executes commands in response to file modifications (mingw-w64)"
license=('spdx:Apache-2.0')
msys2_references=(
  'archlinux: watchexec'
)
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
source=("https://github.com/watchexec/watchexec/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('9609163c14cd49ec651562838f38b88ed2d370e354af312ddc78c2be76c08d37')

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

  cargo fetch --locked
}

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

  cargo build --release --frozen -p watchexec-cli
}

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

  cargo test --release --frozen -p watchexec-cli
}

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

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

  install -Dm644 completions/bash "${pkgdir}${MINGW_PREFIX}/share/bash-completion/completions/watchexec"
  install -Dm644 completions/zsh "${pkgdir}${MINGW_PREFIX}/share/zsh/site-functions/_watchexec"
  install -Dm644 completions/fish "${pkgdir}${MINGW_PREFIX}/share/fish/vendor_completions.d/watchexec.fish"
  install -Dm644 doc/watchexec.1 "${pkgdir}${MINGW_PREFIX}/share/man/man1/watchexec.1"
  install -Dm644 doc/watchexec.1.md "${pkgdir}${MINGW_PREFIX}/share/doc/watchexec/watchexec.1.md"
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/watchexec/LICENSE"
}
