# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=typst
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.14.2
pkgrel=1
pkgdesc='A markup-based typesetting system for the sciences (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://typst.app/'
msys2_repository_url='https://github.com/typst/typst/'
msys2_references=(
  'archlinux: typst'
  'purl: pkg:cargo/typst'
)
license=('spdx:Apache-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-xz")
makedepends=("${MINGW_PACKAGE_PREFIX}-rust"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-openssl"
             'git')
source=("https://github.com/typst/typst/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('70a56445020ca05efc571c7b07a1a9f52eb93842d420518693c077ae74e54142')

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

  ${MINGW_PREFIX}/bin/cargo fetch \
    --locked \
    --config='net.git-fetch-with-cli=true' \
    --target "${RUST_CHOST}"
}

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

  export OPENSSL_NO_VENDOR=1
  ${MINGW_PREFIX}/bin/cargo build -p typst-cli --frozen --release --all-features
}

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

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