# Maintainer: Xeonacid <h.dwwwwww@gmail.com>

pkgname=evmone
pkgver=0.22.0
pkgrel=1
pkgdesc="Fast Ethereum Virtual Machine implementation"
arch=(x86_64)
url="https://github.com/ethereum/$pkgname"
license=(Apache-2.0)
depends=(gcc-libs glibc)
makedepends=(cmake git)
source=(git+$url.git#tag=v$pkgver
        git+https://github.com/ethereum/evmc.git
        git+https://github.com/ipsilon/evm-benchmarks.git)
sha256sums=('f0b782b1a4d2935187b538b09069153a78fb175c44767bfe7fa127415e74206e'
            'SKIP'
            'SKIP')

prepare() {
  cd $pkgname
  git submodule init
  git config submodule.evmc.url ../evmc
  git config submodule.evm-benchmarks.url ../evm-benchmarks
  git -c protocol.file.allow=always submodule update
}

build() {
  local cmake_options=(
    -B build
    -S $pkgname
    -W no-dev
    -D CMAKE_BUILD_TYPE=None
    -D CMAKE_INSTALL_PREFIX=/usr
    -D EVMONE_TESTING=ON
    -D EVMONE_X86_64_ARCH_LEVEL=1
    # https://github.com/ethereum/evmone/issues/1183
    -D CMAKE_POLICY_VERSION_MINIMUM=3.5
  )
  cmake "${cmake_options[@]}"
  cmake --build build
}

check() {
  local excluded_tests=""
  local ctest_flags=(
    --test-dir build
    # show the stdout and stderr when the test fails
    --output-on-failure
    # execute tests in parallel
    --parallel $(nproc)
    # exclude problematic tests
    --exclude-regex "$excluded_tests"
  )
  ctest "${ctest_flags[@]}"
}

package() {
  DESTDIR="$pkgdir" cmake --install build
  cd $pkgname
  install -Dm644 README.md -t "$pkgdir/usr/share/doc/$pkgname"
  cp -r docs "$pkgdir/usr/share/doc/$pkgname"
}
