# Template file for 'harper-cli'
pkgname=harper-cli
version=2.6.0
revision=1
build_style=cargo
make_build_args="--package harper-cli --package harper-ls"
make_install_args="--path harper-cli"
make_check_args="--workspace --exclude harper-desktop"
hostmakedepends="pkg-config libzstd-devel"
makedepends="libzstd-devel"
short_desc="Offline grammar checker for the English language"
maintainer="Bnyro <bnyro@tutanota.com>"
license="Apache-2.0"
homepage="https://writewithharper.com"
changelog="https://github.com/Automattic/harper/releases"
distfiles="https://github.com/Automattic/harper/archive/refs/tags/v${version}.tar.gz"
checksum=9cd55f642eb17c2a1c7e8bfb9f958fe5ea165ec98264b7ce568bedbc32dc8b18

_build_env() {
	export CFLAGS_${RUST_TARGET//-/_}="${CFLAGS}" \
		HOST_CFLAGS="-fstack-clash-protection ${CFLAGS_host}" \
		CFLAGS_${RUST_BUILD//-/_}="${HOST_CFLAGS}" \
	# unset CFLAGS to work around cc-rs adding CFLAGS to host and target CFLAGS_*.
	# https://github.com/rust-lang/cc-rs/issues/1469
	unset CFLAGS
}

pre_build() {
	_build_env
}

pre_check() {
	_build_env
}

pre_install() {
	_build_env
}

harper-ls_package() {
	short_desc+=" - LSP"
	pkg_install() {
		vbin "target/${RUST_TARGET}/release/harper-ls" harper-ls
	}
}
