# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Daniel M. Capella <polyzen@archlinux.org>
# Maintainer: Orhun Parmaksız <orhun@archlinux.org>
# Contributor: Sergey A. <murlakatamenka@disroot.org>

pkgname=rust-analyzer
_pkgver=2024-07-15
pkgver=${_pkgver//-}
pkgrel=1
pkgdesc='Rust compiler front-end for IDEs'
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
url=https://rust-analyzer.github.io/
license=('MIT OR Apache-2.0')
depends=(
  gcc-libs
  rust-src
)
makedepends=(git)
source=("git+https://github.com/rust-lang/$pkgname.git#tag=$_pkgver")
b2sums=('18cbd8149145fba2c83f31cb80f215929b8973912571f335323de1d8896ec3f046e749ce7d67686e57c257fa577db1df44471aae20e490b52cbf86b581e8b5dc')

# Use LTO
export CARGO_PROFILE_RELEASE_LTO=true CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1

# Use debug
export CARGO_PROFILE_RELEASE_DEBUG=2

case "${CARCH}" in
  powerpc)
    # fails to link otherwise due to 32bit limitations
    export RUSTFLAGS="-C opt-level=2"
    export CARGO_PROFILE_RELEASE_LTO=false
    export CARGO_PROFILE_RELEASE_DEBUG=0
  ;;
esac

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

build() {
  cd $pkgname
  CFG_RELEASE=1 cargo build --release --locked --offline
}

package() {
  cd $pkgname
  install -Dt "$pkgdir"/usr/bin target/release/$pkgname
  install -Dm644 -t "$pkgdir"/usr/share/licenses/$pkgname LICENSE-MIT
}
