# Contributor: Rasmus Thomsen <oss@cogitri.dev>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=rustup
pkgver=1.25.2
pkgrel=5
pkgdesc="Rust toolchain installer"
url="https://rustup.rs/"
arch="aarch64 x86_64 loongarch64" # limited by upstream only supporting these arches
license="Apache-2.0"
makedepends="
	cargo
	cargo-auditable
	curl-dev
	openssl-dev>3
	perl
	zlib-dev
	zstd-dev
	"
options="!check" # Doesn't recognise x86_64-unknown-linux-musl yet
subpackages="
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/rust-lang/rustup.rs/archive/$pkgver.tar.gz
	dont-copy-rustup-bin.patch
	getrandom-0.2.10.patch
	system.patch
	cargo-update.patch
	add-loongarch64-support.patch
	"

# It doesn't like our custom triplet
export RUSTUP_OVERRIDE_BUILD_TRIPLE="$CARCH-unknown-linux-musl"

prepare() {
	default_prepare

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

build() {
	cargo auditable build --release --frozen \
		--no-default-features \
		--features no-self-update,curl-backend,reqwest-default-tls,reqwest-backend \
		--bin rustup-init

	ln -s target/release/rustup-init rustup
	./rustup completions zsh > rustup.zsh
	./rustup completions bash > rustup.bash
	./rustup completions fish > rustup.fish
}

check() {
	cargo test --frozen
}

package() {
	install -Dm755 target/release/rustup-init -t "$pkgdir"/usr/bin/

	install -Dm644 rustup.bash \
		"$pkgdir"/usr/share/bash-completion/completions/$pkgname
	install -Dm644 rustup.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/$pkgname.fish
	install -Dm644 rustup.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_$pkgname
}

sha512sums="
77268322224816c84c1a17f125cce10e0bfddae857f1e71885d9999f1415c567ee508f93367dd6adca62a92092c2869957206d4c707d20da461e2866fdc74e67  rustup-1.25.2.tar.gz
1db6d3833327d8c6329bd8a0ed4704b0dd0c6e34e1b3753ab2d34506f5e318129571116612a2bcc58d12f553b466a91302966e40ed2e2b661d2b0ab6c8eaa51a  dont-copy-rustup-bin.patch
d056c8ecb485bf5be6724a897bb47b0cb4b2c8d97d50ca3136edbaedba2e8da9fb8cea1f87bb8fa9e1f934d40097ec1ab17724f69aeb7ce3437ba2e41c49f2f6  getrandom-0.2.10.patch
914fe463454fe5026569200823153b98b659cdfe1c169823af16fe5b01f8e68194804c16f7d2d2fa167daac5727572d0b14e2969ed0e0afbabf2d8a881bdac94  system.patch
a69b492f68fb7a5c28aafa20fb33e6544c8ece087f18854604d498106ae4f9e557be48b4a54495163a3672fa05d40171e33829bd33efbec0131f17fdb608621e  cargo-update.patch
b4235787e50de7f1bd3a74160d9c3a71e25946b0f4ad965ab89769ec260a4688a53e704c43bff1324890f3d47af7cb651b783ff63aa0d0ebe8b8dce4f686b68d  add-loongarch64-support.patch
"
