# Maintainer: Maksim Bondarenkov <maksapple2306@gmail.com>
# Contributor: Christoph Reiter <reiter.christoph@gmail.com>

_realname=setuptools-rust
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=1.12.0
pkgrel=1
pkgdesc="Compile and distribute Python extensions written in rust as easily as if they were written in C (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/PyO3/setuptools-rust'
msys2_references=(
  'archlinux: python-setuptools-rust'
  'purl: pkg:pypi/setuptools-rust'
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-rust"
         "${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-semantic-version"
         "${MINGW_PACKAGE_PREFIX}-python-setuptools")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools-scm")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname/-/_}/${_realname/-/_}-${pkgver}.tar.gz")
sha256sums=('d94a93f0c97751c17014565f07bdc324bee45d396cd1bba83d8e7af92b945f0c')

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

  export SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver
}

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

  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 "${srcdir}/${_realname/-/_}-${pkgver}/LICENSE" \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
