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

_realname=cargo-c
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.8.0
pkgrel=1
pkgdesc='A cargo subcommand to build and install C-ABI compatibile dynamic and static libraries (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url='https://github.com/lu-zero/cargo-c/'
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-curl"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-libgit2"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/lu-zero/cargo-c/archive/v${pkgver}.tar.gz"
        "${_realname}-${pkgver}.Cargo.lock"::"https://github.com/lu-zero/cargo-c/releases/download/v${pkgver}/Cargo.lock")
sha256sums=('2bcb143317e7f579bcfd13ef3f230cf72961ccc79abb176789f8d1fdff03fd35'
            '9a3d77d5690db85eac391948c0a9c934433bbfd291cca1bbe43295ea11538d9d')

prepare() {
    cp "${srcdir}/${_realname}-${pkgver}.Cargo.lock" "${_realname}-${pkgver}/Cargo.lock"
    cd "${srcdir}/${_realname}-${pkgver}"

    cargo fetch \
        --locked
}

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

    cargo build \
        --release \
        --frozen \
        --offline
}

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

    cargo test \
        --release \
        --frozen
}

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

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

    install -D -m644 "LICENSE" -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
}
