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

pkgname=arrow
pkgver=17.0.0
pkgrel=5
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 patchutils rapidjson xsimd)
source=(https://archive.apache.org/dist/${pkgname}/${pkgname}-${pkgver}/apache-${pkgname}-${pkgver}.tar.gz{,.asc}
        https://github.com/apache/arrow/commit/58415d1fac50cb829b3dcf08526033d6db8c30db.patch # [PATCH] GH-38183: [CI][Python] Use pipx to install GCS testbench (#43852)
        https://github.com/apache/arrow/commit/57ac40ca23ebcaa4d42ae808137033689d3be9b1.patch # [PATCH] GH-43164: [C++] Fix CMake link order for AWS SDK (#43230)
        https://github.com/apache/arrow/commit/8836535785ba3dd4ba335818a34e0479929b70e6.patch # [PATCH] GH-43702: [C++][FS][Azure] Use the latest Azurite and update the bundled Azure SDK for C++ to azure-identity_1.9.0 (#43723)
        https://github.com/apache/arrow/commit/69bce8f0cd02297ecc31caef22db67e654c16e28.patch # [PATCH] GH-43677: [C++][FlightRPC] Move the FlightTestServer to its own .cc and .h files (#43678)
        https://github.com/apache/arrow/commit/00d357674002b4e2e08b9d76b5d52530e723c4eb.patch # [PATCH] GH-43746: [C++] Add support for Boost 1.86 (#43766)
        git+https://github.com/apache/parquet-testing.git
        git+https://github.com/apache/arrow-testing.git
        lz4-cmake.patch)
sha512sums=('4e2a617b8deeb9f94ee085653a721904a75696f0827bcba82b535cc7f4f723066a09914c7fa83c593e51a8a4031e8bf99e563cac1ebb1d89604cb406975d4864'
            'SKIP'
            '533e985c350ddbd1b0666b460615a55f058919be4a6cf9b38777358fe9a91ef9bc8cc5c3b34128c75ccbe53bb31f713780f79799552f324093a9031b383ddeae'
            '8cdb5e3eb766786875dbd918ebf512dd834043dfb8ebff19f2fdad1a8ff81842b8b82cedd0e5ae1e87a08094ddda7f37035df805a439fc44febf42df40e023c4'
            '6cbbfd785bb613cfb87a83e73b65f9a40221b99aa20ad84e616cc410ed0073a621d9a37fa56772c4e6e89ffb6b13bd01950b78163f6b18122c3fac544a94a45d'
            '320d4863486cbcfb2f7c45d4f67dcf22502792ac2ac2f5b7d2713bd0b64d6f11a89f041e6341945eb0efb775b3d794fc25ce45a1b9d750d521a533f861295841'
            'b4479a02f17585e4a8c8b809d22244720bc2f3be94463cd57c16e967aaa16348d3e3871ea64adfddd96392ffa967ec6822863efc29b5ab3ddf55f35b5807c626'
            '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
  filterdiff -x .github/workflows/cpp.yml -x 'ci/*' -p1 58415d1fac50cb829b3dcf08526033d6db8c30db.patch \
    | patch -d apache-${pkgname}-${pkgver} -p1
  patch -d apache-${pkgname}-${pkgver} -p1 < 57ac40ca23ebcaa4d42ae808137033689d3be9b1.patch
  patch -d apache-${pkgname}-${pkgver} -p1 < 8836535785ba3dd4ba335818a34e0479929b70e6.patch
  patch -d apache-${pkgname}-${pkgver} -p1 < 69bce8f0cd02297ecc31caef22db67e654c16e28.patch
  patch -d apache-${pkgname}-${pkgver} -p1 < 00d357674002b4e2e08b9d76b5d52530e723c4eb.patch
}

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
}
