# Maintainer: omni <omni+alpine@hack.org>
pkgname=sccache
pkgver=0.8.1
pkgrel=0
pkgdesc="shared compilation cache for C/C++ and Rust"
url="https://github.com/mozilla/sccache/"
arch="all"
license="Apache-2.0"
makedepends="cargo openssl-dev>3 cargo-auditable"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/mozilla/sccache/archive/v$pkgver.tar.gz
	test_musl_ldd_parse.patch
	cargo-update-libc.patch
	"

case "$CARCH" in
x86_64)
	# only x86_64 supports sccache-dist
	subpackages="$subpackages $pkgname-dist"
	_features="all,dist-server"
	;;
*)
	_features="all"
	;;
esac


prepare() {
	default_prepare
	cargo fetch --locked
}

build() {
	cargo auditable build --release --frozen --features $_features
}

check() {
	cargo test --frozen
}

package() {
	install -Dm0755 target/release/sccache -t "$pkgdir"/usr/bin

	case "$CARCH" in
	x86_64)
		install -Dm0755 target/release/sccache-dist \
			-t "$pkgdir"/usr/bin
		;;
	esac

	install -Dm0644 -t "$pkgdir"/usr/share/doc/"$pkgname" \
		docs/*.md
	rm "$pkgdir"/usr/share/doc/"$pkgname"/DistributedFreeBSD.md \
	   "$pkgdir"/usr/share/doc/"$pkgname"/Releasing.md
}

dist() {
	pkgdesc="$pkgdesc (dist server)"

	amove usr/bin/sccache-dist
}

sha512sums="
f42c4d3521c91bf3ecd7605e4e0703120af7341de03e431095d91be9402ffaf25c7d783e114877b261b282fb254e1cbba97f59ee96ac6821ada01cc3a9b10d73  sccache-0.8.1.tar.gz
e185fc6371bcfd59b5c5243d6d4461327061b26d608680187ec49b3698a459e4dca03a0641553a690b8009bd08413d157cf03697bfad7b7d47e8a31c80f37bac  test_musl_ldd_parse.patch
2966d4b0b726f9035de30c1d0adb3d7dca3389e0432c75e87863d529452c76415a6ed1e347b70a03c49e2d0a0c4797404ab675b0c43d2ec4ac20ed90e8edf8d1  cargo-update-libc.patch
"
