# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           R 1.0

R.setup             cran TileDB-Inc tiledb 0.30.2
revision            0
categories-append   databases
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
license             MIT
description         Universal storage engine for sparse and dense multidimensional arrays
long_description    {*}${description}
homepage            https://tiledb-inc.github.io/TileDB-R
checksums           rmd160  910db71856a945473075f89b766ed8fa16eb9138 \
                    sha256  649cdddd626e47d73043bcdb7573f984b4bce3823f23725661f7a6013c18c12c \
                    size    554990

depends_build-append \
                    path:bin/pkg-config:pkgconfig

depends_lib-append  port:tiledb \
                    port:R-nanoarrow \
                    port:R-nanotime \
                    port:R-Rcpp \
                    port:R-RcppInt64 \
                    port:R-spdl

compiler.cxx_standard 2017

# configure does silly stuff, which unsurprisingly breaks the build:
# Library not loaded: @rpath/libtiledb.dylib
# It also hardcodes macOS minimum version, uses incorrect checks for libatomic etc.
# Donʼt bother fixing it; instead, fix Makevars.in.
patchfiles-append   patch-unbreak-build.diff

post-patch {
    reinplace "s,@PREFIX@,${prefix},g" ${worksrcpath}/src/Makevars.in
}

depends_test-append port:R-arrow \
                    port:R-bit64 \
                    port:R-curl \
                    port:R-data.table \
                    port:R-nycflights13 \
                    port:R-palmerpenguins \
                    port:R-simplermarkdown \
                    port:R-tibble \
                    port:R-tinytest

# On ppc and likely i386 a number of tests will fail: it is a consequence of TilDB itself being broken.
# Until that is fixed, this port will not work correctly or at least reliably on 32-bit and/or Big-endian platforms.
# At the moment on ppc test_arrayschema.R tests pass, while test_arrayschemaevolution.R all fail with a familiar message:
# [TileDB::ArrayDirectory] Error: FilterCreate: Deserialization error; not enough data in buffer for metadata
# See also: https://github.com/TileDB-Inc/TileDB/issues/4096
test.run            yes
