Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[r] Provide reference to libtiledbsoma source via soft-link #1372

Merged
merged 4 commits into from
May 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apis/r/.Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@

# build artifacts with libtiledbsoma
src/include
src/libtiledbsoma
tiledbsoma/libtiledbsoma.tar.gz.current
tiledb.tar.gz
tiledbsoma.tar.gz

# subdirectories of soft-linked libtiledbsoma
src/libtiledbsoma/build
src/libtiledbsoma/test

# vscode
^\.vscode$
^\.devcontainer$
Expand Down
2 changes: 1 addition & 1 deletion apis/r/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Title: TileDB SOMA
Description: Interface for working with 'TileDB'-based Stack of Matrices,
Annotated ('SOMA'): an open data model for representing annotated matrices,
like those commonly used for single cell data analysis.
Version: 0.0.0.9023
Version: 0.0.0.9024
Authors@R: c(
person(given = "Aaron",
family = "Wolen",
Expand Down
6 changes: 3 additions & 3 deletions apis/r/cleanup
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ rm -r -f \
src/include/ \
src/lib \
src/cmake_log.txt \
src/build \
src/libtiledbsoma \
src/bin
src/libtiledbsoma/build-lib \
src/bin \
tools/build_libtiledbsoma.sh
25 changes: 22 additions & 3 deletions apis/r/configure
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,30 @@ if [ $? -eq 0 ]; then
src/Makevars.in > src/Makevars

echo "** updated src/Makevars for system library via pkg-config"

## we can exit now as we have a working setup
exit 0
fi
fi

## If we are still here `pkg-config` alone did not work.
## So download tiledb (pre-made) and tiledbsoma (source, for now; then build)
## This
${R_HOME}/bin/Rscript tools/get_tarballs.R

## Download tiledb pre-made
${R_HOME}/bin/Rscript tools/get_tarball.R

## Check for cmake and git
${R_HOME}/bin/Rscript tools/check_cmake_and_git.R

## Make libtiledbsoma library using cmake (and an added git dependency)
tools/build_libtiledbsoma.sh

pkgincl="-I../inst/tiledb/include -I../inst/tiledbsoma/include"
pkglibs="-ltiledb -L../inst/tiledb/lib -ltiledbsoma -L../inst/tiledbsoma/lib"
rpath="-Wl,-rpath,'\$\$ORIGIN/../tiledb/lib' -Wl,-rpath,'\$\$ORIGIN/../tiledbsoma/lib'"
macosver=`${R_HOME}/bin/Rscript -e 'if (Sys.info()["machine"] == "x86_64" && Sys.info()["sysname"] == "Darwin") cat("-mmacosx-version-min=10.14") else cat("")'`

sed -e "s|@tiledb_include@|$pkgincl |" \
-e "s|@tiledb_libs@|$pkglibs|" \
-e "s|@tiledb_rpath@|$rpath|" \
-e "s|@cxx17_macos@|$macosver|" \
src/Makevars.in > src/Makevars
9 changes: 4 additions & 5 deletions apis/r/src/Makevars.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ CXX_STD = CXX17
PKG_CPPFLAGS = -I. -I../inst/include/ @tiledb_include@ @cxx17_macos@ -Iinclude

## When this becomes a CRAN package we may have to remove this. For now it keeps the noise down
PKG_CXX17FLAGS = -Wno-deprecated-declarations
PKG_CXXFLAGS = -Wno-deprecated-declarations

## We also need the TileDB library
PKG_LIBS = @cxx17_macos@ @tiledb_libs@ @tiledb_rpath@

all: $(SHLIB)
# If we are:
# - on macOS aka Darwin which needs this
# - the library is present (implying non-system library use)
# then let us call install_name_tool
# On macOS aka Darwin we call install_name_tool
# Case one: If we had a downloaded TileDB Core artifact, adjust zlib path and add to @rpath
# Case two: If we see the system libraries (on macOS) ensure /usr/local/lib rpath is considered
if [ `uname -s` = 'Darwin' ] && [ -f tiledbsoma.so ]; then \
if [ -f ../inst/tiledb/lib/libtiledb.dylib ] ; then \
install_name_tool -change libz.1.dylib @rpath/libz.1.dylib ../inst/tiledb/lib/libtiledb.dylib; \
Expand Down
1 change: 1 addition & 0 deletions apis/r/src/libtiledbsoma
23 changes: 0 additions & 23 deletions apis/r/tools/build_libtiledbsoma.sh

This file was deleted.

28 changes: 28 additions & 0 deletions apis/r/tools/build_libtiledbsoma.sh.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh

if [ ! -d src/libtiledbsoma ]; then
echo "No 'src/libtiledbsoma' directory. Exiting."
exit 1
fi

if [ ! -d src/libtiledbsoma/build-lib ]; then
mkdir src/libtiledbsoma/build-lib
fi

cwd=`pwd`

cd src/libtiledbsoma/build-lib

## The placeholder is filled in by check_cmake_and_git.R
@cmake@ \
-DDOWNLOAD_TILEDB_PREBUILT=ON \
-DTILEDBSOMA_BUILD_CLI=OFF \
-DTILEDBSOMA_ENABLE_TESTING=OFF \
-DOVERRIDE_INSTALL_PREFIX=OFF \
-DCMAKE_INSTALL_PREFIX=${cwd}/inst/tiledbsoma ..

make

make install-libtiledbsoma

rm -rf src/libtiledbsoma/build-lib
19 changes: 19 additions & 0 deletions apis/r/tools/check_cmake_and_git.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@


cmake_bin <- Sys.which("cmake")
if (cmake_bin == "" && file.exists("/Applications/CMake.app/Contents/bin/cmake"))
cmake_bin <- "/Applications/CMake.app/Contents/bin/cmake"

if (cmake_bin == "") {
stop("No 'cmake' binary found", call. = FALSE)
}

git_bin <- Sys.which("git")
if (git_bin == "") {
stop("No 'git' binary found", call. = FALSE)
}

lines <- readLines("tools/build_libtiledbsoma.sh.in")
lines <- gsub("@cmake@", cmake_bin, lines)
writeLines(lines, "tools/build_libtiledbsoma.sh")
Sys.chmod("tools/build_libtiledbsoma.sh", mode="0755")
31 changes: 31 additions & 0 deletions apis/r/tools/get_tarball.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env Rscript

## version pinning info
tiledb_core_version <- "2.15.2"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to minimize keystroking on future dependency-upgrade PRs, @gspowley wrote a very nice scripts/update-tiledb-version.py:

it looks like that script might not update this current script as-is -- ?

updating that script to handle this file might be done on this PR, or on a follow-up PR

Copy link
Contributor Author

@eddelbuettel eddelbuettel May 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wondered about that too but I thought the above was better because we only to change once for version and sha1 rather than three times (with largely redundant long URLs):

if (isMac) {
if (isX86) {
url <- "https://github.com/TileDB-Inc/TileDB/releases/download/2.15.2/tiledb-macos-x86_64-2.15.2-90f30eb.tar.gz"
macosver <- "-mmacosx-version-min=10.14"
} else {
url <- "https://github.com/TileDB-Inc/TileDB/releases/download/2.15.2/tiledb-macos-arm64-2.15.2-90f30eb.tar.gz"
}
} else if (isLinux) {
url <- "https://github.com/TileDB-Inc/TileDB/releases/download/2.15.2/tiledb-linux-x86_64-2.15.2-90f30eb.tar.gz"
} else {
stop("Unsupported platform for downloading artifacts. Please have TileDB Core installed locally.")
}

Easy enough to revert if that is what we prefer. In tiledb-r I actually update two-line text 'key: value' text file that is then read (via a DCF reader R has in base so no need to worry about jaml or json...):

https://github.com/TileDB-Inc/TileDB-R/blob/870f9343bd4fab056e8e46ee83b23acfb47b423d/tools/tiledbVersion.txt#L1-L2

tiledb_core_sha1 <- "90f30eb"

if ( ! dir.exists("inst/") ) {
stop("No 'inst/' directory. Exiting.", call. = FALSE)
}

makeUrl <- function(arch, ver=tiledb_core_version, sha1=tiledb_core_sha1) {
sprintf("https://github.com/TileDB-Inc/TileDB/releases/download/%s/tiledb-%s-%s-%s.tar.gz", ver, arch, ver, sha1)
}

isX86 <- Sys.info()["machine"] == "x86_64"
isMac <- Sys.info()["sysname"] == "Darwin"
isLinux <- Sys.info()["sysname"] == "Linux"

if (isMac && isX86) {
url <- makeUrl("macos-x86_64")
} else if (isMac && !isX86) {
url <- makeUrl("macos-arm64")
} else if (isLinux) {
url <- makeUrl("linux-x86_64")
} else {
stop("Unsupported platform for downloading artifacts. Please have TileDB Core installed locally.")
}

tarball <- "tiledb.tar.gz"
if (!file.exists(tarball)) download.file(url, tarball, quiet=TRUE)
if (!dir.exists("inst/tiledb")) untar(tarball, exdir="inst/tiledb")
40 changes: 0 additions & 40 deletions apis/r/tools/get_tarballs.R

This file was deleted.

1 change: 1 addition & 0 deletions apis/r/tools/r-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ BootstrapLinuxOptions() {
# InstallPandoc 'linux/debian/x86_64'
#fi
if [[ "${USE_BSPM}" != "FALSE" ]]; then
echo "options(bspm.sudo = TRUE)" | sudo tee --append /etc/R/Rprofile.site >/dev/null
echo "suppressMessages(bspm::enable())" | sudo tee --append /etc/R/Rprofile.site >/dev/null
echo "options(bspm.version.check=FALSE)" | sudo tee --append /etc/R/Rprofile.site >/dev/null
fi
Expand Down