# Contributor: Duncan Bellamy <dunk@denkimushi.com>
# Maintainer: Duncan Bellamy <dunk@denkimushi.com>
pkgname=fasttext
pkgver=0.9.2
pkgrel=1
pkgdesc="Library for fast text representation and classification"
url="https://fasttext.cc/"
arch="all"
license="MIT"
options="!check" # Tests require 300+MB test data
makedepends="
	cmake
	py3-gpep517
	py3-numpy-dev
	py3-pybind11-dev
	py3-setuptools
	py3-wheel
	python3-dev
	samurai
	"
subpackages="
	$pkgname-dev
	$pkgname-libs
	py3-$pkgname-pyc
	py3-$pkgname:python_fasttext
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/facebookresearch/fastText/archive/refs/tags/v$pkgver.tar.gz
	gcc13.patch
	no-march-native.patch
	"
builddir="$srcdir/fastText-$pkgver"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=None \
		$CMAKE_CROSSOPTS
	cmake --build build

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

package() {
	DESTDIR="$pkgdir" cmake --install build

	python3 -m installer -d \
		"$pkgdir" .dist/*.whl
	rm -r "$pkgdir"/usr/lib/python3*/site-packages/fasttext/tests
}

python_fasttext() {
	pkgdesc="$pkgname (python module)"
	depends="python3 py3-numpy"

	amove usr/lib/python*
}

sha512sums="
8f0f6e78b3c6b3c7e7d107778952f340cc208b8e0b920dd118a57884cca8ef7007ea88b6f3352cb7e08289a64743f507309e1e1259c785f810af7f5fa09f2656  fasttext-0.9.2.tar.gz
4fb6470ca854ad2c819871cc611a43650416c994dc2c8bea344853966cc39fc49b9c248534547a2387e5a5a1180044648f35cf7b4ca7c9c04d7a2f8d7638c3d3  gcc13.patch
79c7fd41c0a51c3655fbb5e34fc3691225ca9142f6fe0c2d1866c352583f3b782da72023df2b374bf6a014fa4923341e85078ca3e18c0c30e674c81fe999b13d  no-march-native.patch
"
