# Maintainer: Maksim Bondarenkov <maksapple2306@gmail.com>
# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=rpds-py
pkgbase=mingw-w64-python-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-python-${_realname}
pkgver=0.30.0
pkgrel=1
pkgdesc='Python bindings to the Rust rpds crate for persistent data structures (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/crate-py/rpds'
msys2_references=(
  'archlinux: python-rpds-py'
  'gentoo: dev-python/rpds-py'
  'purl: pkg:pypi/rpds-py'
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-maturin"
             "${MINGW_PACKAGE_PREFIX}-rust")
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname/-/_}/${_realname/-/_}-${pkgver}.tar.gz")
sha256sums=('dd8ff7cf90014af0c0f787eea34794ebf6415242ee1d6fa91eaba725cc441e84')

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

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

build() {
  cp -r "${_realname/-/_}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  export _PYTHON_HOST_PLATFORM=$(python -c "import sysconfig, sys; sys.stdout.write(sysconfig.get_platform())")
  python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

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