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

_realname=wasm-tools
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.248.0
pkgrel=1
pkgdesc="Low level tooling for WebAssembly in Rust (mingw-w64)"
arch=("any")
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url="https://github.com/bytecodealliance/wasm-tools"
msys2_repository_url="https://github.com/bytecodealliance/wasm-tools"
license=('spdx:Apache-2.0 WITH LLVM-exception AND Apache-2.0 AND MIT')
# Update using ./retrieve-testsuite-commit.sh <pkgver>
_wasm_testsuite_commit=51279a9d02cbba193cb25142d115388d7b83299c
makedepends=("${MINGW_PACKAGE_PREFIX}-rust" "${MINGW_PACKAGE_PREFIX}-git")
source=(
  "https://github.com/bytecodealliance/${_realname}/archive/refs/tags/v${pkgver}/${_realname}-${pkgver}.tar.gz"
  "https://github.com/WebAssembly/testsuite/archive/${_wasm_testsuite_commit}/wasm-testsuite-${_wasm_testsuite_commit}.tar.gz"
)
sha256sums=('ad3222fba69e8ea8221e723dc024dee9e0e85aed63b29f1379e1f2e98b6e03cb'
            '1b3caa3fab5259b1e1cda8c66d14ee8c81f5e0dc6322f518964c0c6f6590d945')

prepare() {
  cd "${_realname}-${pkgver}"
  rm -r tests/testsuite
  cp -r "../testsuite-${_wasm_testsuite_commit}" tests/testsuite
  cargo fetch \
    --locked \
    --target "${RUST_CHOST}" \
    --config='net.git-fetch-with-cli=true'
}

build() {
  cd "${_realname}-${pkgver}"
  cargo build --frozen --release --all-features --bin wasm-tools
}

check() {
  cd "${_realname}-${pkgver}"
  cargo test --frozen --release --all-features
}

package() {
  cd "${_realname}-${pkgver}"
  install -Dm0755 -t "${pkgdir}${MINGW_PREFIX}/bin/" "target/release/${_realname}"
  install -Dm0644 -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}" LICENSE-*
}
