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

pkgname=python-fastbencode
pkgver=0.3.7
pkgrel=1
pkgdesc='Implementation of bencode with optional fast C extensions'
arch=('i686' 'x86_64')
url='https://github.com/breezy-team/fastbencode'
msys2_references=(
  "purl: pkg:pypi/fastbencode"
)
license=(spdx:GPL-2.0-or-later)
depends=(python)
makedepends=(
  python-build
  python-installer
  python-setuptools
  python-setuptools-rust
  python-devel
  gcc
)
checkdepends=(python-pytest)
source=("https://pypi.io/packages/source/f/fastbencode/fastbencode-$pkgver.tar.gz")
sha256sums=('e96fd955d6d5980a913730ecbf838ca2863a6420f0d7c8d189087caa83393f21')

build() {
  cd "fastbencode-$pkgver"

  # pyo3 doesn't support cygwin yet, so pass the python lib directly
  local link_arg=$(python -c "import sysconfig; print(sysconfig.get_config_var('LIBPYTHON'))")
  export RUSTFLAGS="-C link-arg=$link_arg"

  python -m build --wheel --no-isolation
}

check() {
  cd "fastbencode-$pkgver"

  python -m unittest discover -v
}

package() {
  cd "fastbencode-$pkgver"
  python -m installer --destdir="$pkgdir" dist/*.whl
}
