# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=samply
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.13.1
pkgrel=1
pkgdesc="Command-line sampling profiler for macOS, Linux, and Windows (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/mstange/samply"
license=("spdx:Apache-2.0 OR MIT")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-rust"
)
source=("${_realname}-${pkgver}.tar.gz::${url}/archive/${_realname}-v${pkgver}.tar.gz")
sha256sums=('7002789471f8ef3a36f4d4db7be98f2847724e2b81a53c5e23d5cae022fb704b')

prepare() {
  mv "${_realname}-${_realname}-v${pkgver}" "${_realname}-${pkgver}"
  cd "${_realname}-${pkgver}/${_realname}"
  cargo fetch --target "$(rustc -vV | sed -n 's/host: //p')" --locked
}

build() {
  cd "${_realname}-${pkgver}/${_realname}"
  cargo build --frozen --release
}

check() {
  cd "${_realname}-${pkgver}/${_realname}"
  cargo test --frozen
}

package() {
  cd "${_realname}-${pkgver}"
  install -Dm 755 "target/release/${_realname}.exe" "${pkgdir}${MINGW_PREFIX}/bin/${_realname}.exe"
  install -Dm 644 README.md "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/README.md"
  install -Dm 644 LICENSE-MIT "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE-MIT"
}
