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

_realname=edit
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.2.0
pkgrel=1
pkgdesc="Terminal text editor from Microsoft (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://github.com/microsoft/edit'
license=('spdx:MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-rust"
             "${MINGW_PACKAGE_PREFIX}-rust-src")
source=("${url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('e4ba6ff1bfecfeff2492306f5850c714bf50ffdb3cc3bb5be3aa987289f240fe')

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

  cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
  RUSTC_BOOTSTRAP=1 cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')" \
    --manifest-path="${MINGW_PREFIX}/lib/rustlib/src/rust/library/std/Cargo.toml"
}

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

  # FIXME: split debuginfo is not supported for mingw host anyway
  # https://github.com/rust-lang/rust/blob/60dabef95a3de3ec974dcb50926e4bfe743f078f/compiler/rustc_target/src/spec/base/windows_gnu.rs#L111
  export CARGO_PROFILE_RELEASE_DEBUG=0
  RUSTC_BOOTSTRAP=1 \
    cargo build \
    --config .cargo/release.toml \
    --release \
    --frozen
}

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

  RUSTC_BOOTSTRAP=1 \
    cargo install \
      --config .cargo/release.toml \
      --offline \
      --no-track \
      --frozen \
      --path . \
      --root "${pkgdir}${MINGW_PREFIX}"

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