# Contributor: Aleks Bunin <alpinelinux@compuix.com>
# Maintainer: Aleks Bunin <alpinelinux@compuix.com>
pkgname=delta
pkgver=0.18.1
pkgrel=0
pkgdesc="Syntax-highlighting pager for git and diff output"
url="https://dandavison.github.io/delta/"
license="MIT"
# s390x: incompatible with nix crate
arch="all !s390x"
makedepends="
	cargo
	cargo-auditable
	libgit2-dev
	oniguruma-dev
	"
subpackages="
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/dandavison/delta/archive/refs/tags/$pkgver.tar.gz"
options="net"

# secfixes:
#   0.13.0-r0:
#     - CVE-2022-24713

export RUSTONIG_SYSTEM_LIBONIG="true"

prepare() {
	default_prepare

	# Rust target triple.
	local target=$(rustc -vV | sed -n 's/host: //p')

	# Build against system-provided libs
	mkdir -p .cargo
	cat >> .cargo/config.toml <<-EOF
		[target.$target]
		git2 = { rustc-link-lib = ["git2"] }
	EOF

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

build() {
	cargo auditable build --release --frozen

	local i; for i in bash fish zsh; do
		./target/release/delta --generate-completion $i > target/delta.$i
	done
}

check() {
	cargo test --frozen -- --test-threads=1
}

package() {
	install -Dm755 target/release/delta -t "$pkgdir"/usr/bin/
	install -D -m644 target/delta.bash "$pkgdir"/usr/share/bash-completion/completions/delta
	install -D -m644 target/delta.fish "$pkgdir"/usr/share/fish/vendor_completions.d/delta.fish
	install -D -m644 target/delta.zsh "$pkgdir"/usr/share/zsh/site-functions/_delta
}

sha512sums="
545d753b5e9981d87f356e123d3e7f99340adbca5b963e67a2fa5291cc4e6a175462554c50733ad30931e39e7e615bcd0cfb1490c26968b12fe172edddf352e7  delta-0.18.1.tar.gz
"
