maintainer="Alexey Yerin <yyp@disroot.org>"
pkgname=wasm-tools
pkgver=1.230.0
_testsuite_commit=596a817f96bc6fb74a90794473604a0587acc585
pkgrel=0
pkgdesc="CLI for low-level manipulation of WebAssembly modules"
url="https://github.com/bytecodealliance/wasm-tools"
arch="all"
license="Apache-2.0 OR Apache-2.0 WITH LLVM-exception OR MIT"
makedepends="cargo"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/bytecodealliance/wasm-tools/archive/refs/tags/v$pkgver.tar.gz
	testsuite-$_testsuite_commit.tar.gz::https://github.com/WebAssembly/testsuite/archive/$_testsuite_commit.tar.gz
	"

prepare() {
	default_prepare

	rm -r tests/testsuite
	cp -r "$srcdir/testsuite-$_testsuite_commit" tests/testsuite

	cargo fetch --target="$CTARGET" --locked
}

build() {
	# Using regular cargo since cargo-auditable crashes while resolving dependencies, likely due to
	# https://github.com/rust-secure-code/cargo-auditable/issues/66
	cargo build --frozen --release --bin wasm-tools
}

check() {
	cargo test --frozen
}

package() {
	install -Dm755 target/release/wasm-tools "$pkgdir"/usr/bin/wasm-tools

	for license in LICENSE-APACHE LICENSE-Apache-2.0_WITH_LLVM-exception LICENSE-MIT; do
		install -Dm644 $license "$pkgdir"/usr/share/licenses/wasm-tools/$license
	done
}

sha512sums="
badcf076dbbcef55dff433a8a0cf03b716697547cc1685e62f0e928503443fcf380c99b19090cae626a586d50d217c87c1c2a4ade4ef43c81d60562fcf557d02  wasm-tools-1.230.0.tar.gz
75186953e08946f71f6c75bcc4bbe0d4f20cc5b5496a710c33c62b32cdb769732bceef43d3b147c33e1cee181889b2f71313a73a984daa2a7d52b746ccfbb38a  testsuite-596a817f96bc6fb74a90794473604a0587acc585.tar.gz
"
