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

_realname=mdbook-admonish
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.20.0
pkgrel=1
pkgdesc='A preprocessor for mdbook to add Material Design admonishments (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://tommilligan.github.io/mdbook-admonish'
msys2_repository_url='https://github.com/tommilligan/mdbook-admonish'
msys2_changelog_url='https://github.com/tommilligan/mdbook-admonish/blob/main/CHANGELOG.md'
msys2_references=(
  'aur: mdbook-admonish'
  'purl: pkg:cargo/mdbook-admonish'
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-mdbook")
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
source=("${msys2_repository_url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('448df3bf9a13515df6382824959576896d54f51e33bb538617794dbc3bb3fe7f')

prepare() {
  cp -r "${_realname}-${pkgver}" "build-${MSYSTEM}"
  cd "${srcdir}/build-${MSYSTEM}"

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

build() {
  cd "${srcdir}/build-${MSYSTEM}"

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

check() {
  cd "${srcdir}/build-${MSYSTEM}"

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

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  install -Dm755 "target/release/${_realname}.exe" "${pkgdir}${MINGW_PREFIX}/bin/${_realname}.exe"
  install -Dm644 "LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
