# Template file for 'maturin'
pkgname=maturin
version=0.14.8
revision=1
create_wrksrc=yes
build_style=python3-module
build_helper="qemu rust"
hostmakedepends="python3-setuptools-rust python3-tomli python3-wheel cargo"
makedepends="openssl-devel"
depends="python3-tomli"
short_desc="Build and publish crates as python packages"
maintainer="Andrew J. Hesford <ajh@sideband.org>"
license="Apache-2.0, MIT"
homepage="https://github.com/PyO3/maturin"
# bump target-lexicon version if it changes in Cargo.lock
_tlver="0.12.5"
distfiles="${homepage}/archive/v${version}.tar.gz
 https://github.com/bytecodealliance/target-lexicon/archive/v${_tlver}.tar.gz>target-lexicon-${_tlver}.tar.gz"
checksum="f774862c7321aa80c68bb41f0b0e611aa8d75c2fec5d53b24009c7cf9d394e4d
 efc488676998ea73d107b0c2632cc71baff91b5ea95abb6064b48a09edc233f9"
# Tests use unstable features and fail to build
make_check=no

if [ "$CROSS_BUILD" ]; then
	makedepends+=" rust-std"
fi

case "$XBPS_TARGET_MACHINE" in
	ppc64*) ;;
	ppc*)
		broken="https://github.com/console-rs/indicatif/blob/main/src/state.rs#L2"
		;;
esac

post_extract() {
	mv "maturin-${version}"/* .
	mv "target-lexicon-${_tlver}" target-lexicon
	echo "[patch.crates-io]" >> Cargo.toml
	echo "target-lexicon = { path = './target-lexicon' }" >> Cargo.toml
}

pre_configure() {
	cargo update --package target-lexicon --precise "${_tlver}"
}

post_install() {
	vlicense license-mit LICENSE-MIT
	python3 setup.py install --prefix=/usr --root=${DESTDIR}

	# Generate and install some completions
	local _matbin="${DESTDIR}/usr/bin/maturin"
	vtargetrun "${_matbin}" completions zsh > maturin.zsh
	vtargetrun "${_matbin}" completions fish > maturin.fish
	vtargetrun "${_matbin}" completions bash > maturin.bash

	vcompletion maturin.zsh zsh
	vcompletion maturin.fish fish
	vcompletion maturin.bash bash
}
