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

_realname=rust-analyzer
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
_pkgver=2025-12-22
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=('e804780299a95fc9a4fdea4d1eff337fc66a209750a505a13db65841b7247f24')

prepare() {
  cd "${_realname}"

  cargo fetch --locked --target "${RUST_CHOST}"
}

build() {
  cd "${_realname}"

  export RUSTFLAGS="${RUSTFLAGS/+crt-static/-crt-static}"
  export CFG_RELEASE="${_pkgver} (Rev${pkgrel}, Built by MSYS2 project)"
  cargo build --frozen --release -p rust-analyzer
}

check() {
  cd "${_realname}"

  cargo test --frozen --release -p rust-analyzer
}

package() {
  cd "${_realname}"

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

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