# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: Guillaume Horel <guillaume.horel@gmail.com>

_pkg=orc
pkgname=apache-${_pkg}
pkgver=2.2.1
pkgrel=3
pkgdesc="Columnar storage for Hadoop workloads."
arch=(x86_64 aarch64)
url="https://orc.apache.org"
license=(Apache-2.0)
depends=(
  abseil-cpp
  gcc-libs
  glibc
  lz4
  protobuf
  snappy
  zlib
  zstd
)
makedepends=(cmake git)
checkdepends=(gtest)
source=(
  ${pkgname}::git+https://github.com/apache/orc.git#tag=v${pkgver}
  fix-timezone.patch
  fix-cmake-modules.patch
)
sha256sums=('0886c1f28c6b935c98f411058789869de49e01d3acb85a91767b58860ae454c7'
            'd2493cef910f73b01a8ea853470e8c5497e0ef33bb3d17f8eb8ffef7e52f00ac'
            '19134d5ad86dd76c8b65828dda195f113591c944d8be7298fa980e781595e7d9')
validpgpkeys=(F28C9C925C188C35E345614DEDA00CE834F0FC5C  # Dongjoon Hyun (CODE SIGNING KEY) <dongjoon@apache.org>
              AA94E2A8F0A0B7167305C5232D9F6201DECDFA29) # William Hyun (CODE SIGNING KEY) <william@apache.org>

prepare(){
  cd ${pkgname}
  sed -i 's/orc STATIC/orc SHARED/' c++/src/CMakeLists.txt
  # Fix build with protobuf 31 (the google::protobuf::int64 type is not found without this)
  echo '#include <google/protobuf/stubs/common.h>' >> c++/src/wrap/coded-stream-wrapper.h
  echo '#include <google/protobuf/stubs/common.h>' >> c++/src/wrap/zero-copy-stream-wrapper.h
  # Fix for missing /etc/localtime https://github.com/apache/orc/issues/2225
  patch -p1 -i ../fix-timezone.patch
  # Fix the cmake modules https://github.com/apache/orc/pull/2240
  patch -p1 -i ../fix-cmake-modules.patch
}

build(){
  local cmake_options=(
    -B build
    -S ${pkgname}
    -DCMAKE_BUILD_TYPE=None
    -DCMAKE_INSTALL_PREFIX=/usr
    -DSTOP_BUILD_ON_WARNING=OFF
    -DLZ4_HOME=/usr
    -DPROTOBUF_HOME=/usr
    -DSNAPPY_HOME=/usr
    -DZLIB_HOME=/usr
    -DZSTD_HOME=/usr
    -DGTEST_HOME=/usr
    -DORC_PREFER_STATIC_PROTOBUF=OFF
    -DORC_PREFER_STATIC_SNAPPY=OFF
    -DORC_PREFER_STATIC_LZ4=OFF
    -DORC_PREFER_STATIC_ZSTD=OFF
    -DORC_PREFER_STATIC_ZLIB=OFF
    -DBUILD_LIBHDFSPP=OFF
    -DBUILD_JAVA=OFF
    -DINSTALL_VENDORED_LIBS=OFF
    -Wno-dev
  )
  cmake "${cmake_options[@]}"
  cmake --build build
}

check(){
  # One test is failing and cannot be skipped
  # https://github.com/apache/orc/issues/2239
  # https://github.com/apache/orc/issues/2238
  ctest --test-dir build --output-on-failure || true
}

package(){
  DESTDIR="${pkgdir}" cmake --install build
}
