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

_realname=wasm-tools
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.245.1
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=e999a1051925895022ab06abc25b23ca300ab0d0
makedepends=("${MINGW_PACKAGE_PREFIX}-rust" '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=('f8fc02ceec50f0188e4128159535e6c4195594e74c56ecc1db3113e62feb477d'
            'e289c03b4586b92f5e59e30078c4ea96d79fbdc59d993e866c694893473c315c')

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-*
}
