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

_realname=cargo-about
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.8.4
pkgrel=1
pkgdesc="Cargo plugin to generate list of all licenses for a crate (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/EmbarkStudios/cargo-about'
msys2_references=(
  'purl: pkg:cargo/cargo-about'
)
license=('spdx:Apache-2.0 OR MIT')
depends=("${MINGW_PACKAGE_PREFIX}-rust" "${MINGW_PACKAGE_PREFIX}-zstd")
makedepends=("${MINGW_PACKAGE_PREFIX}-pkgconf")
source=("${url}/archive/${pkgver}/${_realname}-${pkgver}.tar.gz"
        "zstd-sys.tar.gz::https://crates.io/api/v1/crates/zstd-sys/2.0.16+zstd.1.5.7/download"
        "zstd-sys-remove-statik.patch")
sha256sums=('956cea9d2170936e7d53d1a8c951242332777be89bff4b8531066bff584fbcd3'
            '91e19ebc2adc8f83e43039e79776e3fda8ca919132d68a1fed6a5faca2683748'
            '8917b1fbb95021d46f61f2067bcd723657fda781f0a063739f168cd9fb68e555')

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

  patch -d ../zstd-sys-2.0.16+zstd.1.5.7 -i "${srcdir}"/zstd-sys-remove-statik.patch
  cat >> Cargo.toml <<END

[patch.crates-io]
zstd-sys.path = "../zstd-sys-2.0.16+zstd.1.5.7"
END

  cargo update -p zstd-sys
  cargo fetch --locked --target "${RUST_CHOST}"
}

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

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

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

  cargo test --release --frozen
}

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

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

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