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

_realname=rust-analyzer
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
_pkgver=2024-08-27
pkgver=${_pkgver//-}
pkgrel=1
pkgdesc="A Rust compiler front-end for IDEs (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://rust-analyzer.github.io'
msys2_repository_url='https://github.com/rust-lang/rust-analyzer'
license=('spdx:Apache-2.0 OR MIT')
conflicts=("${MINGW_PACKAGE_PREFIX}-rust<1.80.0-2")
depends=("${MINGW_PACKAGE_PREFIX}-rust-src")
makedepends=('git')
source=("git+${msys2_repository_url}.git#tag=${_pkgver}")
sha256sums=('e53574432c831dfe5bffe15004cb2b71818df34c2d58ece25b3f2b2d275fc9ec')

prepare() {
  cd "${_realname}"

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

build() {
  cd "${_realname}"

  export CFG_RELEASE="${pkgver}-${pkgrel} (Built by MSYS2 project)"
  # profile dev-rel enables level 2 debug info for better debugger backtraces
  cargo build --frozen --profile dev-rel -p rust-analyzer
}

check() {
  cd "${_realname}"

  cargo test --frozen --profile dev-rel -p rust-analyzer
}

package() {
  cd "${_realname}"

  cargo install \
    --offline \
    --no-track \
    --frozen \
    --path crates/rust-analyzer \
    --root "${pkgdir}${MINGW_PREFIX}" \
    --profile dev-rel

  install -Dm644 LICENSE-{APACHE,MIT} -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
}
