# Template file for 'python3-pywhispercpp'
pkgname=python3-pywhispercpp
version=1.5.0
revision=1
build_style=python3-module
hostmakedepends="cmake pkg-config python3-setuptools python3-wheel $(vopt_if vulkan shaderc)"
makedepends="python3-devel $(vopt_if vulkan vulkan-loader-devel)"
depends="python3-numpy python3-requests python3-tqdm python3-platformdirs $(vopt_if vulkan vulkan-loader)"
short_desc="Python bindings for whisper.cpp speech recognition"
maintainer="Orphaned <orphan@voidlinux.org>"
license="MIT"
homepage="https://github.com/absadiki/pywhispercpp"
distfiles="${PYPI_SITE}/p/pywhispercpp/pywhispercpp-${version}.tar.gz"
checksum=5aa54c73ec96617d97aa519dbbf817e44255eddd9bd52ee1243be61028dbd018
# The sdist ships no test suite, so there is nothing to check.
make_check=no

# Package build options
build_options="vulkan"
build_options_default="vulkan"

pre_build() {
	# The sdist derives its version from git metadata, which is absent in
	# the xbps build root, so inject the pinned version explicitly. This is
	# the same version install.sh (PYWHISPERCPP_VERSION) and uv.lock pin.
	export PYWHISPERCPP_VERSION=${version}
	# Portable x86-64 baseline: GGML_NATIVE is ggml's default and compiles
	# libggml-cpu with -march=native, so the package would inherit the
	# builder's instruction set and SIGILL on older CPUs (#938).
	# GGML_NATIVE=OFF alone is not enough: while the native default is on,
	# ggml turns every GGML_* SIMD option on and still compiles -mavx2
	# -mfma (#957). Each option is pinned off, mirroring the Flatpak build.
	# Shared libraries with an $ORIGIN rpath let the extension resolve the
	# whisper.cpp libraries installed beside it (as install.sh does), with
	# no LD_LIBRARY_PATH at runtime. (setup.py install never builds a
	# wheel, so NO_REPAIR is meaningless here and deliberately unset.)
	export CMAKE_ARGS='-DCMAKE_INSTALL_RPATH=$ORIGIN -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON -DBUILD_SHARED_LIBS=ON -DGGML_NATIVE=OFF -DGGML_SSE42=OFF -DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_BMI2=OFF -DGGML_FMA=OFF -DGGML_F16C=OFF'
	if [ -n "$build_option_vulkan" ]; then
		# Vulkan acceleration for every GPU vendor. There is no CUDA
		# build: Void ships no CUDA toolkit package.
		export GGML_VULKAN=1
	fi
}

post_install() {
	vlicense LICENSE
}
