# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.su>

_realname=stork
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.6.0
pkgrel=3
pkgdesc="Impossibly fast web search, made for static sites (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/jameslittle230/stork"
msys2_references=(
  'aur: stork'
  'purl: pkg:cargo/stork-search'
)
license=('spdx:Apache-2.0')
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-rust"
  "${MINGW_PACKAGE_PREFIX}-pkgconf"
  "${MINGW_PACKAGE_PREFIX}-openssl"
)
source=("${url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('cf7f5ed75815bf7e302fd76ec55ac89db2d06a682c5a07b1431d18105b3ada62')

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

  export OPENSSL_NO_VENDOR=1
  ${MINGW_PREFIX}/bin/cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

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

  ${MINGW_PREFIX}/bin/cargo build \
    --release \
    --frozen
}

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

  ${MINGW_PREFIX}/bin/cargo test \
    --release \
    --frozen
}

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

  install -Dm755 "target/release/stork.exe" "${pkgdir}${MINGW_PREFIX}/bin/stork.exe"

  install -Dm644 license.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
