# Contributor: Rasmus Thomsen <oss@cogitri.dev>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=rustup
pkgver=1.27.1
pkgrel=0
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
	system.patch
	cargo-update.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="
e0494678b7117464665c2aa88165e13baf2dcfb2a33c57dc78f669533111f773724d227ee05967de427845f8633e56fdf8159c7a5b96638413710beacb115075  rustup-1.27.1.tar.gz
1db6d3833327d8c6329bd8a0ed4704b0dd0c6e34e1b3753ab2d34506f5e318129571116612a2bcc58d12f553b466a91302966e40ed2e2b661d2b0ab6c8eaa51a  dont-copy-rustup-bin.patch
1186753c875f1915c21aa4e70cb7b28dc4c12b1187485accd8d8cdb1addae0686def2b0edd495604be43b2864b811e3125db70007cf268d65fb1c5160e240307  system.patch
cf616d9bf2d5d8ff1fc78ac0d5e764592a8ee73879376f6f44a3a865ae7f7f22a7fcbff4c346dbe8f4d2fc618c98aff9813a988da48678a2239c87de389674ea  cargo-update.patch
"
