# Maintainer: Carlo Landmeter <clandmeter@alpinelinux.org>
pkgname=py3-pybind11
_pkgname=pybind11
pkgver=2.13.6
pkgrel=0
pkgdesc="Seamless operability between C++11 and Python"
url="https://github.com/pybind/pybind11"
arch="noarch"
license="MPL-2.0"
depends_dev="$pkgname=$pkgver-r$pkgrel"
makedepends="
	boost-dev
	cmake
	py3-gpep517
	py3-setuptools
	py3-wheel
	python3-dev
	samurai
	"
checkdepends="
	catch2
	py3-pytest
	"
subpackages="$pkgname-dev $pkgname-pyc"
source="$pkgname-$pkgver.tar.gz::https://github.com/pybind/pybind11/archive/v$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"

replaces="py-pybind11" # Backwards compatibility
provides="py-pybind11=$pkgver-r$pkgrel" # Backwards compatibility

build() {
	# fails with lto due to fortify-headers
	export CXXFLAGS="$CXXFLAGS -U_FORTIFY_SOURCE"

	python3 setup.py build

	if [ "$CBUILD" != "$CHOST" ]; then
		local crossopts="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	CXXFLAGS="$CXXFLAGS -flto=auto" \
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=None \
		-DPYTHON_EXECUTABLE=/usr/bin/python3 \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DUSE_PYTHON_INCLUDE_DIR=FALSE \
		-DPYBIND11_TEST="$(want_check && echo ON || echo OFF)" \
		$crossopts
	cmake --build build

	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

check() {
	# No integrated ctest for running tests yet, use cmake targets
	# https://github.com/pybind/pybind11/issues/5095
	cmake --build build --target pytest
	cmake --build build --target cpptest
	cmake --build build --target test_cmake_build
}

package() {
	python3 -m installer -d "$pkgdir" \
		.dist/*.whl

	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
497c25b33b09a9c42f67131ab82e35d689e8ce089dd7639be997305ff9a6d502447b79c824508c455d559e61f0186335b54dd2771d903a7c1621833930622d1a  py3-pybind11-2.13.6.tar.gz
"
