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

_tarname=RustScan
_realname=rustscan
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.4.1
pkgrel=1
pkgdesc="The Modern Port Scanner (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://github.com/rustscan/RustScan'
license=('spdx:GPL-3.0-or-later')
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python")
options=('!strip')
source=("${url}/archive/${pkgver}/${_realname}-${pkgver}.tar.gz"
        "https://github.com/RustScan/RustScan/commit/b1f008a9c987f7e879ccf74bdab5ecfea9e74fb9.patch")
sha256sums=('fa99c18a12d4c0939ab69ddb84ef7b85a1ea01d8fc86df227449d89473531765'
            'c400ec90520cea677787337d34cf9be4a9e782b45a14832b1a27f968ac6fea63')

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

  # actually include 2.4.1 update commit
  patch -Np1 -i ../b1f008a9c987f7e879ccf74bdab5ecfea9e74fb9.patch

  cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

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

  WINAPI_NO_BUNDLED_LIBRARIES=1 \
    cargo build --release --frozen
}

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

  WINAPI_NO_BUNDLED_LIBRARIES=1 \
    cargo test --release --frozen
}

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

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

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