# Maintainer: Maksim Bondarenkov <maksapple2306@gmail.com>
# Contributor: Naveen M K <naveen521kk@gmail.com>

_realname=starship
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.23.0
pkgrel=1
pkgdesc="The cross-shell prompt for astronauts (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://starship.rs"
msys2_repository_url="https://github.com/starship/starship"
msys2_references=(
  'archlinux: starship'
  'purl: pkg:cargo/starship'
  'cpe: cpe:2.3:a:starship:starship'
)
license=('spdx:ISC')
makedepends=("${MINGW_PACKAGE_PREFIX}-rust" "${MINGW_PACKAGE_PREFIX}-cmake")
optdepends=("${MINGW_PACKAGE_PREFIX}-ttf-font-nerd: Nerd Font Symbols preset")
options=('!strip')
source=("${msys2_repository_url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('be3ba025a64bd808899dce256e1511145b55cc5eefc5fca82bf5537cd8e09c72')
noextract=("${_realname}-${pkgver}.tar.gz")

prepare() {
  tar -xzf "${_realname}-${pkgver}.tar.gz" || true
  cd "${_realname}-${pkgver}"

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

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

  export WINAPI_NO_BUNDLED_LIBRARIES=1
  cargo build --release --frozen
}

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

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

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

  local _complete="target/release/starship completions"
  $_complete bash | install -Dm644 /dev/stdin "${pkgdir}${MINGW_PREFIX}"/share/bash-completion/completions/starship
  $_complete fish | install -Dm644 /dev/stdin "${pkgdir}${MINGW_PREFIX}"/share/fish/vendor_completions.d/starship.fish
  $_complete zsh | install -Dm644 /dev/stdin "${pkgdir}${MINGW_PREFIX}"/share/zsh/site-functions/_starship
}
