# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=sccache
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.2.15
pkgrel=1
pkgdesc='Shared compilation cache (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://github.com/mozilla/sccache"
license=('Apache')
depends=("${MINGW_PACKAGE_PREFIX}-openssl" "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
source=("https://github.com/mozilla/sccache/archive/refs/tags/v$pkgver.tar.gz")
sha256sums=('7dbe71012f9b0b57d8475de6b36a9a3b4802e44a135e886f32c5ad1b0eb506e0')

prepare() {
  cp -r ${_realname}-${pkgver} build-${CARCH}
  ${MINGW_PREFIX}/bin/cargo fetch \
    --locked \
	--manifest-path build-${CARCH}/Cargo.toml
}

build() {
  msg "Build for ${CARCH}"  
  ${MINGW_PREFIX}/bin/cargo build \
	--release \
	--frozen \
	--manifest-path build-${CARCH}/Cargo.toml \
	--features all \
	--features native-zlib
}

check() {
  ${MINGW_PREFIX}/bin/cargo test \
	--release \
	--frozen \
	--manifest-path build-${CARCH}/Cargo.toml \
	--features all \
	--features native-zlib
}

package() {
  ${MINGW_PREFIX}/bin/cargo install \
	--frozen \
	--offline \
	--no-track \
	--path build-${CARCH} \
	--root ${pkgdir}${MINGW_PREFIX} \
	--features all \
	--features native-zlib

  install -Dm644 ${_realname}-${pkgver}/LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
