# Contributor: kpcyrd <git@rxv.cc>
# Maintainer: kpcyrd <git@rxv.cc>
pkgname=cargo-audit
pkgver=0.21.0
pkgrel=0
pkgdesc="Audit Cargo.lock for crates with security vulnerabilities"
url="https://github.com/RustSec/rustsec"
arch="all"
license="MIT OR Apache-2.0"
makedepends="cargo libgit2-dev openssl-dev>3 cargo-auditable"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/RustSec/cargo-audit/archive/cargo-audit/v$pkgver.tar.gz"
builddir="$srcdir/rustsec-$pkgname-v$pkgver/$pkgname"
options="net !check" # requires running binaries prebuilt against glibc as part of the tests and fails

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 --features fix
}

check() {
	cargo test --frozen
}

package() {
	install -Dm 755 ../target/release/cargo-audit -t "$pkgdir/usr/bin"
	install -Dm 644 -t "$pkgdir/usr/share/doc/cargo-audit" README.md
}

sha512sums="
63ef59d04e0dce11431f23892e93679f33c63e11556fb106845cd7dc1b34cf46a967b01e9dabc30942c83f300be028fc5129a6765523a8bef2462992b5a95c1f  cargo-audit-0.21.0.tar.gz
"
