# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=python-librt
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.6.3
pkgrel=1
pkgdesc='Mypyc runtime library (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/mypyc/librt"
msys2_references=(
  'purl: pkg:pypi/librt'
)
license=('spdx:MIT AND PSF-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-python-build"
  "${MINGW_PACKAGE_PREFIX}-python-installer"
  "${MINGW_PACKAGE_PREFIX}-python-setuptools"
)
source=("${url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('f5581e3fe9c0e54cc2f164ff186ab270556cd5abded2917754b6543a47218967')

prepare() {
  cd "librt-${pkgver}"
  # Necessary for building, see:
  # .github/workflows/buildwheels.yml
  cp lib-rt/* .
}

build() {
  cd "librt-${pkgver}"
  python -m build --wheel --no-isolation
}

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

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
