# Contributor: dragon-archer <dragon-archer@outlook.com>

_realname=pixi
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.63.1
pkgrel=1
pkgdesc='A fast, modern, and reproducible package management tool for developers of all backgrounds. (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64')
url='https://pixi.sh/'
msys2_repository_url="https://github.com/prefix-dev/pixi/"
license=('spdx:BSD-3-Clause')
makedepends=("${MINGW_PACKAGE_PREFIX}-rust"
             'git')
options=('!strip')
source=("${msys2_repository_url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "0001-fix-msvc-style-flags.patch"
        "0002-skip-invalid-tests.patch"
        "0003-skip-git-related-tests.patch")
sha256sums=('350bba330edf8192bc768f29a8509c2ce72933a13490f2e0944c23477445e0a1'
            '4a8eda460377088600df73440675e7aeea49a4c45936dc046a981575c2a0119b'
            '382e332b712b5565bbb607c6421fbea230d917252d6154ecdf51d56b77e61eb8'
            '390625bfececb5f18da61efaf11a3b8b4dc322f42b2f0413d0ff917333449b9e')

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp1 -i "${srcdir}/$_patch"
  done
}

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

  apply_patch_with_msg \
    0001-fix-msvc-style-flags.patch \
    0002-skip-invalid-tests.patch \
    0003-skip-git-related-tests.patch

  ${MINGW_PREFIX}/bin/cargo fetch \
    --locked \
    --config='net.git-fetch-with-cli=true' \
    --target "${RUST_CHOST}"
}

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

  ${MINGW_PREFIX}/bin/cargo build --frozen --profile dist
}

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

  ${MINGW_PREFIX}/bin/cargo test --frozen --profile dist
}

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

  install -Dt "${pkgdir}${MINGW_PREFIX}/bin" target/dist/${_realname}
  install -Dm644 LICENSE -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
}
