Skip to content

Commit

Permalink
Provide access to TileDB shared libraries in downstream packages
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mojaveazure committed Nov 11, 2024
1 parent de4f684 commit 3eb236f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
5 changes: 4 additions & 1 deletion R/Init.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -121,7 +125,6 @@ inlineCxxPlugin <- function(...) {
}
}


#' @importFrom utils read.table
.getLinuxFlavor <- function() {
res <- NA_character_
Expand Down
42 changes: 42 additions & 0 deletions R/Version.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
))
}
3 changes: 3 additions & 0 deletions TileDB-R.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3eb236f

Please sign in to comment.