# Contributor: omni <omni+alpine@hack.org>
# Maintainer: omni <omni+alpine@hack.org>
pkgname=arti
pkgver=1.4.3
pkgrel=0
pkgdesc="An implementation of Tor, in Rust"
url="https://tpo.pages.torproject.net/core/arti/"
license="GPL-3.0-or-later"
# s390x: merlin crate doesn't support big-endian targets
# riscv64: https://gitlab.torproject.org/tpo/core/arti/-/issues/1398
arch="all !riscv64 !s390x"
makedepends="cargo openssl-dev>3 sqlite-dev zstd-dev xz-dev cargo-auditable"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://gitlab.torproject.org/tpo/core/arti/-/archive/arti-v$pkgver/arti-arti-v$pkgver.tar.gz
	32b_arti_example_config_patch
	disable_system_time_conversion_patch
	disable-access_symlink-test.patch
	"
builddir="$srcdir/$pkgname-$pkgname-v$pkgver"

case "$CARCH" in
arm*|loongarch64|ppc64le|riscv64|x86)
	# for aws-lc-sys
	checkdepends="$checkdepends cmake clang-dev"
	;;
esac

prepare() {
	default_prepare
	cargo fetch --target="$CTARGET" --locked

	# 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]
		zstd = { rustc-link-lib = ["zstd"] }
	EOF

	case "$CARCH" in
	arm*|x86)
		patch crates/arti/src/arti-example-config.toml \
		"$srcdir"/32b_arti_example_config_patch
		patch crates/tor-hsservice/src/time_store.rs \
		"$srcdir"/disable_system_time_conversion_patch
		;;
	esac
}

build() {
	cargo auditable build --release --frozen --features=full --package arti
}

check() {
	cargo test --frozen
}

package() {
	install -Dm755 -t "$pkgdir"/usr/bin/ target/release/arti
	install -Dm755 -t "$pkgdir"/usr/share/doc/"$pkgname"/ \
		doc/bridges.md \
		doc/Compatibility.md \
		doc/FAQ.md \
		doc/OnionService.md \
		doc/SupportPolicy.md \
		CHANGELOG.md README.md \
		crates/arti/src/arti-example-config.toml
}

sha512sums="
cb6dd8c99503891031c436248d53d2bd63b897deafbe4eacd7d357bba2e2e68f59ac1a7dd03b59f5cd30c935af84b7f188792010c4f603703cda123f87a7aedd  arti-1.4.3.tar.gz
9bc94ca4f9fc6e75f3d144d7429d34f05b32b73c946ce94d0ed3c6d647e58e481b8ed1f6ceb166a264adc0aabb2366440a815cd345466ea6d056b3200fb929b9  32b_arti_example_config_patch
a68d7c99b1d1d73b4c8c725d7c69486bb732b3b2c28df339f2e56f842c17417aa89fe8ba41f1017bd4c7e550e1e8a2b886071b8f96c0e2863855698cb8767810  disable_system_time_conversion_patch
64eddebb1c199ec0352a45acffd0152cb5ecc542f388ff4fc237cc021b95c9e67be50532e87fb7e7398b4ecdf60dbd78b7b777540884c73f398ee51a00131e1f  disable-access_symlink-test.patch
"
