_realname=libhdr10plus
_sourcename=hdr10plus_tool
pkgbase=mingw-w64-${_realname}-rs
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}-rs
pkgver=2.1.2
pkgrel=2
pkgdesc='Library to read and write HDR10+ metadata (C-API)'
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://github.com/quietvoid/hdr10plus_tool/tree/main/hdr10plus'
license=('spdx:MIT')
msys2_references=(
  'aur: libhdr10plus-rs-git'
  'purl: pkg:cargo/hdr10plus'
)
makedepends=("${MINGW_PACKAGE_PREFIX}-rust"
             "${MINGW_PACKAGE_PREFIX}-cargo-c")
source=("https://github.com/quietvoid/hdr10plus_tool/archive/${_realname}-${pkgver}.tar.gz")
sha256sums=('c46908d70caa77053804a2e88a2b0e158e6bf67e10bb21b30d585ad8fb27cf6b')

prepare() {
  cd "${_sourcename}-${_realname}-${pkgver}/hdr10plus"

  cargo fetch --locked
}

build() {
  cd "${_sourcename}-${_realname}-${pkgver}/hdr10plus"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    cargo cbuild \
      --meson-paths \
      --release \
      --frozen \
      --all-features \
      --prefix="${MINGW_PREFIX}"
}

check() {
  cd "${_sourcename}-${_realname}-${pkgver}/hdr10plus"

  cargo test \
    --release \
    --frozen \
    --all-features
}

package() {
  cd "${_sourcename}-${_realname}-${pkgver}/hdr10plus"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    cargo cinstall \
      --meson-paths \
      --release \
      --frozen \
      --all-features \
      --prefix="${MINGW_PREFIX}" \
      --destdir="${pkgdir}"

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