# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: Guillaume Horel <guillaume.horel@gmail.com>

pkgname=arrow
pkgver=16.1.0
pkgrel=2
pkgdesc="Columnar in-memory analytics layer for big data."
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
url="https://arrow.apache.org"
license=(Apache)
depends=(apache-orc brotli bzip2 gflags grpc google-glog libutf8proc
         lz4 openssl protobuf re2 snappy thrift zlib zstd)
provides=(parquet-cpp)
conflicts=(parquet-cpp)
makedepends=(boost clang cmake flatbuffers git gmock rapidjson xsimd)
source=(https://archive.apache.org/dist/${pkgname}/${pkgname}-${pkgver}/apache-${pkgname}-${pkgver}.tar.gz{,.asc}
        git+https://github.com/apache/parquet-testing.git
        git+https://github.com/apache/arrow-testing.git
        lz4-cmake.patch)
sha512sums=('28975f59e1fdde2dba4afaf4a5ba934b63db3a7f27656e2aa0af0f0d2a046c9dbfa9a6082de94629c36d03809b296566a37ea65ec5a2fc17fedac7d21e272d31'
            'SKIP'
            'SKIP'
            'SKIP'
            '35af7cafbc83f02ab7fb219accda890ca1c233b0393bd2e91c07f3673a5a34e41752c5db071ab61fcc9e7154fafaca1394dd481de7e03e06856864c4197c52d6')
validpgpkeys=(265F80AB84FE03127E14F01125BCCA5220D84079  # Krisztian Szucs (apache) <szucs.krisztian@gmail.com>
              08D3564B7C6A9CAFBFF6A66791D18FCF079F8007  # Kouhei Sutou <kou@cozmixng.org>
              AF6AADA4C9835B75973FF5DA275C532289DD0F4A) # Raúl Cumplido Domínguez (CODE SIGNING KEY) <raulcd@apache.org>

prepare() {
  patch -d apache-${pkgname}-${pkgver} -p1 < lz4-cmake.patch # Fix build when lz4 is built with cmake
}

build(){
  BUILD_TESTS='ON'
  case "${CARCH}" in
    powerpc64le) _cmake_options+=(-DARROW_SIMD_LEVEL=NONE) ;;
    powerpc64)
      _cmake_options+=(-DARROW_SIMD_LEVEL=NONE);
      BUILD_TESTS='OFF'
    ;;
    powerpc|riscv64) _cmake_options+=(-DCMAKE_CXX_FLAGS="-latomic" -DARROW_SIMD_LEVEL=NONE) ;;
    x86_64)
      _cmake_options+=(-DARROW_SIMD_LEVEL=AVX2)
      export CC=clang
      export CXX=clang++
    ;;
  esac

  cmake \
    -B build -S apache-${pkgname}-${pkgver}/cpp \
    -DCMAKE_INSTALL_PREFIX="/usr" \
    -DCMAKE_INSTALL_LIBDIR="lib" \
    -DCMAKE_BUILD_TYPE=Release \
    -DARROW_BUILD_STATIC=OFF \
    -DARROW_DEPENDENCY_SOURCE=SYSTEM \
    -DARROW_BUILD_TESTS=${BUILD_TESTS} \
    -DARROW_COMPUTE=ON \
    -DARROW_CSV=ON \
    -DARROW_SUBSTRAIT=ON \
    -DARROW_FLIGHT=ON \
    -DARROW_FLIGHT_SQL=ON \
    -DARROW_GANDIVA=OFF \
    -DARROW_HDFS=ON \
    -DARROW_IPC=ON \
    -DARROW_JEMALLOC=ON \
    -DARROW_ORC=ON \
    -DARROW_PARQUET=ON \
    -DARROW_TENSORFLOW=ON \
    -DARROW_USE_GLOG=ON \
    -DARROW_WITH_BROTLI=ON \
    -DARROW_WITH_BZ2=ON \
    -DARROW_WITH_LZ4=ON \
    -DARROW_WITH_SNAPPY=ON \
    -DARROW_WITH_ZLIB=ON \
    -DARROW_WITH_ZSTD=ON \
    -DPARQUET_REQUIRE_ENCRYPTION=ON \
    -Wno-dev ${_cmake_options[@]}
  make -C build
}

check(){
  PARQUET_TEST_DATA="${srcdir}"/parquet-testing/data \
  ARROW_TEST_DATA="${srcdir}"/arrow-testing/data \
  ctest --test-dir build --output-on-failure
}

package(){
  DESTDIR="$pkgdir" cmake --install build
  find "${pkgdir}"/usr/lib/ -name '*testing*' -delete
}
