# Template file for 'rust-bootstrap'
pkgname=rust-bootstrap
version=1.64.0
revision=1
create_wrksrc=yes
short_desc="Rust programming language bootstrap toolchain"
maintainer="Orphaned <orphan@voidlinux.org>"
license="MIT, Apache-2.0"
homepage="https://www.rust-lang.org/"
conflicts="rust>=0"
lib32disabled=yes
nostrip=yes
repository=bootstrap

if [ "$XBPS_TARGET_LIBC" = "musl" ]; then
	depends="libexecinfo-devel"
fi

_bootstrap_url="https://static.rust-lang.org/dist"

case "$XBPS_TARGET_MACHINE" in
	x86_64*|i686|ppc64le|ppc) ;;
	# See srcpkgs/rust-bootstrap/files/generating-distfiles.md for details
	*) _bootstrap_url="https://repo-default.voidlinux.org/distfiles";;
esac

# hardcode platform triplets
# because this info isn't avaialble here without hacky workarounds
case "$XBPS_TARGET_MACHINE" in
	i686)
		distfiles="
		 ${_bootstrap_url}/rustc-${version}-i686-unknown-linux-gnu.tar.xz
		 ${_bootstrap_url}/rust-std-${version}-i686-unknown-linux-gnu.tar.xz"
		checksum="
		 3d604e150c469461a64c17b6d26f96a5a3d6975246c92cd13ee9bc6e4df0aaeb
		 c80c57df63517d6171c061e6c095b794593172a3abefa9b4202992706bda12e5"
		;;
	x86_64)
		distfiles="
		 ${_bootstrap_url}/rustc-${version}-x86_64-unknown-linux-gnu.tar.xz
		 ${_bootstrap_url}/rust-std-${version}-x86_64-unknown-linux-gnu.tar.xz"
		checksum="
		 1f5756a03119853b53358018c5b1592940a2354c3c9f84ee7faf684e3478f8f0
		 6ace34bcbba9557aa2fc3a0515c3da4a83ca24d7d45506c5e1b32f589fa38a8b"
		;;
	x86_64-musl)
		distfiles="
		 ${_bootstrap_url}/rustc-${version}-x86_64-unknown-linux-musl.tar.xz
		 ${_bootstrap_url}/rust-std-${version}-x86_64-unknown-linux-musl.tar.xz"
		checksum="
		 5177d749b5dcc74596e314b73c5f3f3eabed8b3e207f812f229fbf0682c162ae
		 29af13a882abbe797fadd43afcb75bce2e2304438db9e21a3e64a2e9100501fb"
		;;
	ppc64le)
		distfiles="
		 ${_bootstrap_url}/rustc-${version}-powerpc64le-unknown-linux-gnu.tar.xz
		 ${_bootstrap_url}/rust-std-${version}-powerpc64le-unknown-linux-gnu.tar.xz"
		checksum="
		 11630fc51fffe722e52f649357b5948c24b5305cfb61a8114527234e054451c4
		 ef697469b2a3ea8897f49b70e3be0c7aaca3f26fd3234812113e2e85cafac738"
		;;
	ppc64le-musl)
		distfiles="
		 ${_bootstrap_url}/rustc-${version}-powerpc64le-unknown-linux-musl.tar.xz
		 ${_bootstrap_url}/rust-std-${version}-powerpc64le-unknown-linux-musl.tar.xz"
		checksum="
		 9ae19e0cdb883aa67dc3e4ef7afca88f99c8c5d176ed9175e2f7652122c7d1d8
		 825b8f680d9e6e3d6b1451586bb09efb0c1f7d844d6874738e040cf3d6b20663"
		;;
	ppc64)
		distfiles="
		 ${_bootstrap_url}/rustc-${version}-powerpc64-unknown-linux-gnu.tar.xz
		 ${_bootstrap_url}/rust-std-${version}-powerpc64-unknown-linux-gnu.tar.xz"
		checksum="
		 aae6418c71986a7f4ab7c7ab66d4f97531f0bdab50f14985c9403e2cff443de7
		 96485965f0a2dec274679cafbe4d39bd9e7c728824a6c5504f164ec9d5f57384"
		;;
	ppc)
		distfiles="
		 ${_bootstrap_url}/rustc-${version}-powerpc-unknown-linux-gnu.tar.xz
		 ${_bootstrap_url}/rust-std-${version}-powerpc-unknown-linux-gnu.tar.xz"
		checksum="
		 5f4de96bff2937fc0a64a216604c7af765af94460a1f283330eddc610d91271b
		 6b29ebec4cd705760db634717cf6df68a9a377d52c25def30f5a2e2641a83279"
		;;
	*) broken="rust bootstrap binaries unavailable for ${XBPS_TARGET_MACHINE}";;
esac

do_install() {
	for d in *; do
		cd $d
		./install.sh --prefix=/usr --destdir="${DESTDIR}"
		cd ..
	done

	vlicense rustc-${version}-${RUST_TARGET}/COPYRIGHT
	vlicense rustc-${version}-${RUST_TARGET}/LICENSE-APACHE
	vlicense rustc-${version}-${RUST_TARGET}/LICENSE-MIT

	rm -rf ${DESTDIR}/usr/share/doc/rust
	rm -f ${DESTDIR}/usr/lib/rustlib/${RUST_TARGET}/bin/rust-ll*
}
