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

_basename=create-tauri-app
_realname=cargo-${_basename}
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.6.2
pkgrel=1
pkgdesc="Rapidly scaffold out a new tauri app project (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/tauri-apps/create-tauri-app"
msys2_references=(
  'purl: pkg:cargo/create-tauri-app'
)
license=('spdx:MIT OR Apache-2.0')
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
source=("${url}/archive/${_basename}-v${pkgver}/${_basename}-${_basename}-v${pkgver}.tar.gz")
sha256sums=('4276d826717c6ec763c92f90e93609bf9e080a24812d0c958334e5f45a4e81e3')

prepare() {
  cd "${srcdir}/${_basename}-${_basename}-v${pkgver}"

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

build() {
  cp -r "${_basename}-${_basename}-v${pkgver}" "build-${MSYSTEM}"
  cd "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 "README.md" "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/README.md"
  install -Dm644 "LICENSE_MIT" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE_MIT"
  install -Dm644 "LICENSE_APACHE-2.0" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE_APACHE-2.0"
}
