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

_realname=wasm-component-ld
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.5.18
pkgrel=1
pkgdesc="Command line linker for creating WebAssembly components (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url="https://github.com/bytecodealliance/wasm-component-ld"
msys2_references=(
  'archlinux: wasm-component-ld'
  'purl: pkg:cargo/wasm-component-ld'
)
license=('spdx:Apache-2.0 WITH LLVM-exception AND Apache-2.0 AND MIT')
depends=("${MINGW_PACKAGE_PREFIX}-lld")
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
checkdepends=("${MINGW_PACKAGE_PREFIX}-rust-wasm")
source=("${url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('27fd97d775a20737e5ee55b345200d23ae381f437886a54fe3a7a374e291e744')

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

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

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

  cargo build --release --frozen
}

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

  cargo test --release --frozen
}

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

  install -Dm755 target/release/wasm-component-ld "${pkgdir}${MINGW_PREFIX}/bin/wasm-component-ld"
  install -Dm644 LICENSE* -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
}
