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

_realname=eza
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.23.4
pkgrel=1
pkgdesc="A modern, maintained replacement for ls (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64' 'mingw64')
url='https://eza.rocks'
msys2_repository_url='https://github.com/eza-community/eza'
msys2_references=(
  'archlinux: eza'
  'gentoo: sys-apps/eza'
  'purl: pkg:cargo/eza'
)
license=('spdx:EUPL-1.2')
depends=("${MINGW_PACKAGE_PREFIX}-zlib"
         "${MINGW_PACKAGE_PREFIX}-libgit2")
makedepends=("${MINGW_PACKAGE_PREFIX}-rust"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-openssl"
             'git')
optdepends=("${MINGW_PACKAGE_PREFIX}-ttf-font-nerd: for file icons")
options=('!strip')
source=("${_realname}::git+${msys2_repository_url}.git#tag=v${pkgver}")
sha256sums=('3a91f3669aaae063abe127c36edccdc6600a4f954e2ed1ea86d532263b06b5b6')

_env() {
  export LIBGIT2_NO_VENDOR=1
  export OPENSSL_NO_VENDOR=1
  export WINAPI_NO_BUNDLED_LIBRARIES=1
}

prepare() {
  cd "${_realname}"

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

build() {
  cd "${_realname}"

  _env
  export RUSTFLAGS="${RUSTFLAGS/+crt-static/-crt-static}"
  cargo build --release --frozen
}

check() {
  cd "${_realname}"

  _env
  cargo test --release --frozen
}

package() {
  cd "${_realname}"

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

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

  install -Dm644 completions/bash/eza "${pkgdir}${MINGW_PREFIX}/share/bash-completion/completions/eza"
  install -Dm644 completions/zsh/_eza "${pkgdir}${MINGW_PREFIX}/share/zsh/site-functions/_eza"
  install -Dm644 completions/fish/eza.fish "${pkgdir}${MINGW_PREFIX}/share/fish/vendor_completions.d/eza.fish"
}
