# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=sheldon
pkgver=0.8.0
pkgrel=1
pkgdesc="Fast, configurable, shell plugin manager"
url="https://github.com/rossmacarthur/sheldon"
# loongarch64: libc crate fails to build
arch="all !loongarch64"
license="MIT OR Apache-2.0"
makedepends="
	cargo
	cargo-auditable
	curl-dev
	libgit2-dev
	libssh2-dev
	openssl-dev
	"
subpackages="
	$pkgname-bash-completion
	$pkgname-zsh-completion
	"
source="https://github.com/rossmacarthur/sheldon/archive/$pkgver/sheldon-$pkgver.tar.gz"
options="net"

case "$CARCH" in
# FIXME: with libgit2-1.8.2 this segfaults in a specific test, but works fine at runtime
arm*|x86|s390x|ppc64le) options="$options !check" ;;
esac

export CARGO_PROFILE_RELEASE_OPT_LEVEL="z"
export LIBSSH2_SYS_USE_PKG_CONFIG=1  # use system libssh2

_cargo_opts="--frozen --no-default-features"

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 $_cargo_opts --release
}

check() {
	# Skipped tests - https://github.com/rossmacarthur/sheldon/issues/140
	GIT_COMMIT_HASH="unknown" \
	GIT_COMMIT_SHORT_HASH="unknown" \
	GIT_COMMIT_DATE="unknown" \
	cargo test $_cargo_opts -- \
		--skip=lock_and_source_github_git \
		--skip=locked_config_clean \
		--skip=source_lock_git_git_with_checkout
}

package() {
	install -D -m755 target/release/sheldon -t "$pkgdir"/usr/bin/

	install -D -m644 completions/sheldon.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_sheldon
	install -D -m644 completions/sheldon.bash \
		"$pkgdir"/usr/share/bash-completion/completions/sheldon
}

sha512sums="
1e7703b8712d20c21a2d4201daef5c9504c8bc4f6c706295dcbab8803967964c4829d7d66fe28bf69b7fd5aef545d9a01a42b93c32a6e0d692628be564121fc3  sheldon-0.8.0.tar.gz
"
