# Maintainer: Maksim Bondarenkov <maksapple2306@gmail.com>

_realname=cbindgen
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.29.0
pkgrel=1
pkgdesc="A project for generating C bindings from Rust code (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://github.com/mozilla/cbindgen'
msys2_references=(
  'purl: pkg:cargo/cbindgen'
)
license=('spdx:MPL-2.0')
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
checkdepends=("${MINGW_PACKAGE_PREFIX}-cmake"
              "${MINGW_PACKAGE_PREFIX}-cython"
              "${MINGW_PACKAGE_PREFIX}-python")
source=("${url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('6697f449d4a15d814d991249a611af961c97e36d9344c7ced6df35c5c25b40cc')

prepare() {
  cd "${_realname}-${pkgver}"
  rm rust-toolchain.toml

  cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
  cd "${_realname}-${pkgver}"

  cargo build --release --frozen
}

check() {
  cd "${_realname}-${pkgver}"

  cargo test --release --frozen
}

package() {
  cd "${_realname}-${pkgver}"

  cargo install \
    --offline \
    --no-track \
    --frozen \
    --path . \
    --root "${pkgdir}${MINGW_PREFIX}"

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
