# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=zxing-cpp
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=3.0.0
pkgrel=1
pkgdesc="Python bindings for the zxing-cpp barcode library (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/zxing-cpp/zxing-cpp'
msys2_repository_url='https://github.com/zxing-cpp/zxing-cpp'
msys2_references=(
  'purl: pkg:pypi/zxing-cpp'
)
license=('spdx:Apache-2.0')
depends=(
  "${MINGW_PACKAGE_PREFIX}-python"
  "${MINGW_PACKAGE_PREFIX}-zint"
  "${MINGW_PACKAGE_PREFIX}-cc-libs"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-cmake"
  "${MINGW_PACKAGE_PREFIX}-ninja"
  "${MINGW_PACKAGE_PREFIX}-pybind11"
  "${MINGW_PACKAGE_PREFIX}-python-build"
  "${MINGW_PACKAGE_PREFIX}-python-installer"
  "${MINGW_PACKAGE_PREFIX}-python-setuptools"
)
options=('!strip')
source=(
  "https://pypi.org/packages/source/${_realname::1}/${_realname/-/_}/${_realname/-/_}-${pkgver}.tar.gz"
  0001-setup-check-msc-python.patch
  0002-system-deps.patch
  0003-fix-build-with-gcc-16.patch
)
sha256sums=('703353304de24d947bd68044fac4e062953a7b64029de6941ba8ffeb4476b60d'
            '6882d4b8c8c7b058ac8012cd60e6eb1002880317257035c39bb139f8f6d6ec5f'
            'c3aad9c7881d2011815ebb55af638cbc84037ce4e54e8311d848424e9de83dc7'
            'df22682adfe5c31dec7e676f7c75e3feea7bd82bf644048bc53731baa64c70b6')

prepare() {
  cd "${_realname/-/_}-${pkgver}"
  patch -p1 -i "${srcdir}"/0001-setup-check-msc-python.patch
  patch -p1 -i "${srcdir}"/0002-system-deps.patch
  patch -p1 -i "${srcdir}"/0003-fix-build-with-gcc-16.patch
}

build() {
  cp -r "${_realname/-/_}-${pkgver}" "python-build-${MSYSTEM}" && 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
}
