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

_realname=cargo-generate
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.23.7
pkgrel=1
pkgdesc="Use pre-existing git repositories as templates (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/cargo-generate/cargo-generate"
msys2_changelog_url='https://github.com/cargo-generate/cargo-generate/blob/main/CHANGELOG.md'
msys2_references=(
  'anitya: 376083'
  'archlinux: cargo-generate'
  'purl: pkg:cargo/cargo-generate'
)
license=('spdx:MIT OR Apache-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-rust"
         "${MINGW_PACKAGE_PREFIX}-libgit2"
         "${MINGW_PACKAGE_PREFIX}-libssh2")
makedepends=("${MINGW_PACKAGE_PREFIX}-mdbook"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-openssl"
             "${MINGW_PACKAGE_PREFIX}-cargo-edit")
source=("${url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('7f6dceb0ede61122684d4852092331c7179a5ea236247688e5074be68c1d9e4d')

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

  # bump git2 crate
  cargo upgrade -p git2@0.20.0

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

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

  export LIBSSH2_SYS_USE_PKG_CONFIG=1
  export LIBGIT2_NO_VENDOR=1
  export OPENSSL_NO_VENDOR=1
  cargo build --release --frozen

  cd guide
  mdbook build
}

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

  cargo test --release --locked
}

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

  install -Dm755 "target/release/${_realname}.exe" "${pkgdir}${MINGW_PREFIX}/bin/${_realname}.exe"
  install -d "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}"
  cp -a "guide/book" "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/html"
  install -Dm644 "LICENSE-MIT" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE-MIT"
  install -Dm644 "LICENSE-APACHE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE-APACHE"
}
