From 3eb236f80c614af96c3a04409ed6188c488a9a67 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Mon, 11 Nov 2024 15:01:36 -0500 Subject: [PATCH] Provide access to TileDB shared libraries in downstream packages New helper function to provide access to `libtiledb` used by tiledb-r for downstream packages. This builds off the prototype code @LTLA provided resolves #780 --- R/Init.R | 5 ++++- R/Version.R | 42 ++++++++++++++++++++++++++++++++++++++++++ TileDB-R.Rproj | 3 +++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/R/Init.R b/R/Init.R index 3cb0894dba..8ae1f76329 100644 --- a/R/Init.R +++ b/R/Init.R @@ -53,6 +53,10 @@ ## set a preference for allocation size defaults .pkgenv[["allocation_size"]] <- load_allocation_size_preference() + # cache package name and path + .pkgenv[["pkgname"]] <- pkgname + .pkgenv[["libname"]] <- libname + ## call setter for Rcpp plugin support .set_compile_link_options() @@ -121,7 +125,6 @@ inlineCxxPlugin <- function(...) { } } - #' @importFrom utils read.table .getLinuxFlavor <- function() { res <- NA_character_ diff --git a/R/Version.R b/R/Version.R index 099d42c333..e6e6330838 100644 --- a/R/Version.R +++ b/R/Version.R @@ -41,3 +41,45 @@ tiledb_version <- function(compact = FALSE) { libtiledb_version() } } + +#' Compiler Arguments for Using \code{libtiledb} +#' +#' @param opt A single character value with the package configuration variable +#' to fetch; choose from +#' \itemize{ +#' \item \dQuote{\code{PKG_CXX_FLAGS}}: compiler flags for \code{libtiledb} +#' \item \dQuote{\code{PKG_CXX_LIBS}}: linking flags for \code{libtiledb} +#' } +#' +#' @return ... +#' +#' @keywords internal +#' +#' @export +#' +#' @examples +#' .pkg_config() +#' .pkg_config("PKG_CXX_LIBS") +#' +.pkg_config <- function(opt = c("PKG_CXX_FLAGS", "PKG_CXX_LIBS")) { + opt <- match.arg(opt) + if (nzchar(lib <- system.file("tiledb", package = .pkgenv$pkgname, lib.loc = .pkgenv$libname))) { + pkgdir <- system.file(package = .pkgenv$pkgname, lib.loc = .pkgenv$libname) + return(switch( + EXPR = opt, + PKG_CXX_FLAGS = sprintf("-I%s/include -I%s/include", pkgdir, lib), + PKG_CXX_LIBS = sprintf("-ltiledb -L%s/lib -L%s/lib", pkgdir, lib) + )) + } + if (nzchar(pkgconfig <- Sys.which("pkg-config"))) { + if (!system2(pkgconfig, args = c("--exists", "tiledb"))) { + flag <- switch(EXPR = opt, PKG_CXX_FLAGS = "--cflags", PKG_CXX_LIBS = "--libs") + return(system2(pkgconfig, args = c(flag, "tiledb"), stdout = TRUE)) + } + } + return(switch( + EXPR = opt, + PKG_CXX_FLAGS = "", + PKG_CXX_LIBS = "-ltiledb" + )) +} diff --git a/TileDB-R.Rproj b/TileDB-R.Rproj index e05cf5db3e..9fbba2861f 100644 --- a/TileDB-R.Rproj +++ b/TileDB-R.Rproj @@ -12,6 +12,9 @@ Encoding: UTF-8 RnwWeave: Sweave LaTeX: pdfLaTeX +AutoAppendNewline: Yes +StripTrailingWhitespace: Yes + BuildType: Package PackageUseDevtools: Yes PackageInstallArgs: --no-multiarch --with-keep.source --install-tests