# Contributor: André Klitzing <aklitzing@gmail.com>
# Maintainer: André Klitzing <aklitzing@gmail.com>
pkgname=ripgrep
pkgver=14.1.1
pkgrel=0
pkgdesc="ripgrep combines the usability of The Silver Searcher with the raw speed of grep"
url="https://github.com/BurntSushi/ripgrep"
arch="all"
license="MIT OR Unlicense"
makedepends="
	cargo
	cargo-auditable
	pcre2-dev
	"
checkdepends="xz"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-zsh-completion
	$pkgname-fish-completion
	"
source="https://github.com/BurntSushi/ripgrep/archive/$pkgver/ripgrep-$pkgver.tar.gz
	"

export PCRE2_SYS_STATIC=0  # use system libpcre2
export JEMALLOC_SYS_WITH_LG_PAGE=16 # 2**16 = 64k

prepare() {
	default_prepare

	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build --release --frozen --features 'pcre2'
}

check() {
	cargo test --frozen --features 'pcre2'
}

package() {
	install -Dm755 target/release/rg \
		-t "$pkgdir"/usr/bin/

	mkdir -p "$pkgdir/usr/share/zsh/site-functions"
	target/release/rg --generate complete-zsh > "$pkgdir/usr/share/zsh/site-functions/_rg"

	mkdir -p "$pkgdir/usr/share/bash-completion/completions"
	target/release/rg --generate complete-bash > "$pkgdir/usr/share/bash-completion/completions/rg"

	mkdir -p "$pkgdir/usr/share/fish/vendor_completions.d"
	target/release/rg --generate complete-fish > "$pkgdir/usr/share/fish/vendor_completions.d/rg.fish"

	mkdir -p "$pkgdir/usr/share/man/man1"
	target/release/rg --generate man >  "$pkgdir/usr/share/man/man1/rg.1"
}

sha512sums="
6aacbc99025c1c0c301491574953bed4d7dd04f9ce7ce999c47eaa50d71ea7edd905f718e2e94031a5ad651d4daebce772c57ed291c639938991ad4574be8244  ripgrep-14.1.1.tar.gz
"
