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

_realname=cargo-msrv
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.18.4
pkgrel=1
pkgdesc="Find the minimum supported Rust version (MSRV) for your project (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://github.com/foresterre/cargo-msrv'
license=('spdx:Apache-2.0 OR MIT')
depends=("${MINGW_PACKAGE_PREFIX}-rustup")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-nasm"
             "${MINGW_PACKAGE_PREFIX}-rust-bindgen"
             'git')
source=("git+${url}#tag=v${pkgver}")
sha256sums=('1a9c9d2b4cdadf399f1edb43b07407355ec5ab15a6348a0aac9a9f98c3f77130')

prepare() {
  cd "${_realname}"

  # have to specify target otherwise MSVC tooclhain is used
  export RUSTUP_TOOLCHAIN=stable-${RUST_CHOST}
  cargo update -p aws-lc-rs --precise 1.13.1
  cargo fetch --locked --target "${RUST_CHOST}"
}

build() {
  cd "${_realname}"

  export BINDGEN_EXTRA_CLANG_ARGS="--target=${CARCH}-pc-windows-gnu"
  export RUSTUP_TOOLCHAIN=stable-${RUST_CHOST}
  cargo build --release --frozen
}

check() {
  cd "${_realname}"

  cargo test --release --frozen
}

package() {
  cd "${_realname}"

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

  install -Dm644 LICENSE-{APACHE,MIT} -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/"
}
