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

_realname=dulwich
pkgname="python-${_realname}"
pkgver=0.25.0
pkgrel=1
pkgdesc='Pure-Python implementation of the Git file formats and protocols'
arch=('any')
url='https://www.dulwich.io'
msys2_repository_url='https://github.com/jelmer/dulwich'
msys2_changelog_url='https://github.com/jelmer/dulwich/blob/master/NEWS'
msys2_references=(
  'archlinux: python-dulwich'
  'gentoo: dev-python/dulwich'
  'purl: pkg:pypi/dulwich'
)
license=('spdx:Apache-2.0 OR GPL-2.0-or-later')
depends=(
  'python'
  'python-urllib3'
)
makedepends=(
  'python-build'
  'python-installer'
  'python-setuptools'
  'python-setuptools-rust'
  'python-devel'
  'rust'
  'gcc'
)
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('baa84b539fea0e6a925a9159c3e0a1d08cceeea5260732b84200e077444a4b0e')

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

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

  local link_arg=$(python -c "import sysconfig; print(sysconfig.get_config_var('LIBPYTHON'))")
  export RUSTFLAGS="-C link-arg=$link_arg"

  python -m build --wheel --skip-dependency-check --no-isolation
}

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

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

  install -D -m644 COPYING "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
