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

_realname=typst-lsp
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.13.0
pkgrel=1
pkgdesc='language server for Typst (mingw-w64)'
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://github.com/nvarner/typst-lsp'
license=('spdx:Apache-2.0 OR MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-rust" 'git')
source=("git+${url}.git#tag=v${pkgver}")
sha256sums=('acdc1ea2c33c74939b27a9d4c82bfb34009ce020918ba0126ed9652c3ddcedc9')

prepare() {
  cd "${_realname}"

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

build() {
  cd "${_realname}"

  export WINAPI_NO_BUNDLED_LIBRARIES=1
  cargo build --release --frozen
}

check() {
  cd "${_realname}"

  export WINAPI_NO_BUNDLED_LIBRARIES=1
  cargo test --release --frozen
}

package() {
  cd "${_realname}"

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

  install -Dm644 LICENSE-{Apache-2.0.,MIT.}txt -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
}
