# Maintainer: Mazhar Hussain <realmazharhussain@gmail.com>

_realname=gst-plugins-rs
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=1.26.7
_tag=gstreamer-${pkgver}
pkgrel=1
pkgdesc='GStreamer plugins written in Rust (mingw-w64)'
arch=(any)
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs'
license=('spdx:LGPL-3.0-or-later AND Apache-2.0 AND MIT AND MPL-2.0')
depends=(${MINGW_PACKAGE_PREFIX}-cairo
         ${MINGW_PACKAGE_PREFIX}-dav1d
         ${MINGW_PACKAGE_PREFIX}-glib2
         ${MINGW_PACKAGE_PREFIX}-gst-plugins-base
         ${MINGW_PACKAGE_PREFIX}-gst-plugins-bad-libs
         ${MINGW_PACKAGE_PREFIX}-gstreamer
         ${MINGW_PACKAGE_PREFIX}-gtk4
         ${MINGW_PACKAGE_PREFIX}-libsodium
         ${MINGW_PACKAGE_PREFIX}-libwebp
         ${MINGW_PACKAGE_PREFIX}-pango)
makedepends=(${MINGW_PACKAGE_PREFIX}-rust
             ${MINGW_PACKAGE_PREFIX}-cargo-c
             ${MINGW_PACKAGE_PREFIX}-cmake
             ${MINGW_PACKAGE_PREFIX}-pkgconf
             ${MINGW_PACKAGE_PREFIX}-nasm
             ${MINGW_PACKAGE_PREFIX}-rust-bindgen
             git)
source=("${url}/-/archive/${_tag}/${_realname}-gstreamer-${_tag}.tar.bz2")
sha256sums=('32dc08d18154be536afb282e4db3c1021a7eba1fcdaef9ef40f36cd21e090754')

prepare() {
  mv "${_realname}-${_tag}-"* "${_realname}-${_tag}" && cd "${_realname}-${_tag}"

  cargo fetch --locked
}

_cargo_opts=(--workspace
             --offline
             --release
             --meson-paths
             --library-type=cdylib
             --prefix="${MINGW_PREFIX}"
             --exclude gst-plugin-csound
             --exclude gst-plugin-skia
             --exclude gst-plugin-vvdec
             --features gtk_v4_16)

if [[ ${CARCH} == aarch64 ]]; then
  _cargo_opts+=(--exclude gst-plugin-ndi
                --exclude gst-plugin-sodium)
fi

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

  export RUSTFLAGS="${RUSTFLAGS/+crt-static/-crt-static}"
  MSYS2_ARG_CONV_EXCL="--prefix=" cargo cbuild "${_cargo_opts[@]}"
}

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

  MSYS2_ARG_CONV_EXCL="--prefix=" cargo ctest "${_cargo_opts[@]}" --target-dir=tests-build
}

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

  MSYS2_ARG_CONV_EXCL="--prefix=" cargo cinstall "${_cargo_opts[@]}" --destdir="${pkgdir}"

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