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

_realname=panamax
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.0.14
pkgrel=1
pkgdesc="Mirror rustup and crates.io repositories, for offline Rust and cargo usage (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://github.com/panamax-rs/'
msys2_repository_url='https://github.com/panamax-rs/panamax'
msys2_references=(
  'purl: pkg:cargo/panamax'
)
license=('spdx:Apache-2.0 AND MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
source=(
  "${msys2_repository_url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
  "0001-panamax-1.0.14-update-cargo-lock.path::${msys2_repository_url}/commit/17714e2d071d4b0d7c474294ba1d6afd78e6a1ee.patch"
)
sha256sums=('f5c5dbcb6c167b39389b775b8bbce1de9f913da97fa318f24c28ee0562dcaef8'
            'f8e41eac34f7f38051cd65ace1af2f63ed2d75a6926efbb79d1ff9c9ea6c2898')

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

  patch -Np1 -i "${srcdir}"/0001-panamax-1.0.14-update-cargo-lock.path

  cargo update -p ring --precise 0.17.14

  cargo fetch --locked --target "${RUST_CHOST}"
}

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

  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 "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE-APACHE"
  install -Dm644 LICENSE-MIT "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE-MIT"
}
