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

_realname=svg2pdf
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.13.0
pkgrel=1
pkgdesc='The command line interface for svg2pdf (mingw-w64)'
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://github.com/typst/svg2pdf'
license=('spdx:Apache-2.0 OR MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
source=("${url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('882bb7992cfa79395788d577d3ca79c1a7f53597a23abe7a09a2b1180ee9a44e')

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

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

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

  cargo build --release --frozen -p svg2pdf-cli
}

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

  cargo test --release --frozen -p svg2pdf-cli
}

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

  local _compdir='target/release/artifacts'
  install -Dm755 target/release/svg2pdf "${pkgdir}${MINGW_PREFIX}"/bin/svg2pdf
  install -Dm644 "${_compdir}"/svg2pdf.bash "${pkgdir}${MINGW_PREFIX}"/share/bash-completion/completions/svg2pdf
  install -Dm644 "${_compdir}"/_svg2pdf "${pkgdir}${MINGW_PREFIX}"/share/zsh/site-functions/_svg2pdf
  install -Dm644 "${_compdir}"/svg2pdf.fish "${pkgdir}${MINGW_PREFIX}"/share/fish/completions/svg2pdf.fish
  install -Dm644 "${_compdir}"/svg2pdf.1 "${pkgdir}${MINGW_PREFIX}"/share/man/man1/svg2pdf.1

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