# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>

pkgname=cbindgen
pkgver=0.27.0
pkgrel=1
pkgdesc="A tool for generating C bindings to Rust code"
url="https://github.com/mozilla/cbindgen"
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
license=(MPL-2.0)
depends=(
  gcc-libs
  glibc
)
makedepends=(
  cargo
  git
)
checkdepends=(
  cmake
  cython
  python
)
source=("git+$url#tag=v$pkgver")
b2sums=('76b445f7f9729107a04451433d047f50b5ac52c7dc501685f00d0558dab82e2bc09d23a8b5c33ea231e1a2fae81533ba8e64d21a43d524b6dd0de170114c6ea5')

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

build() {
  cd cbindgen

  # Use debug
  export CARGO_PROFILE_RELEASE_DEBUG=2

  # Use LTO
  export CARGO_PROFILE_RELEASE_LTO=true CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1

  cargo build --release --frozen --all-targets
}

check() {
  cd cbindgen
  # Tests need nightly features
  RUSTC_BOOTSTRAP=1 cargo test --frozen
}

package() {
  cd cbindgen
  install -Dt "$pkgdir/usr/bin" target/release/cbindgen
  install -Dt "$pkgdir/usr/share/doc/$pkgname" -m644 CHANGES \
    {README,docs,internals}.md
}

# vim:set sw=2 sts=-1 et
