Skip to content

Commit

Permalink
build GatingSet.pb as shared lib. fix #7
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejiang committed Mar 1, 2019
1 parent 837bf97 commit e865d69
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
28 changes: 24 additions & 4 deletions R/build.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@ pbCxxFlags <- function() {

# Return the linker flags requried for pb on this platform
pbLdFlags <- function(all = TRUE) {
gslibs <- system.file(file.path("lib", "GatingSet.pb.o"), package = "RProtoBufLib")
# gslibs <- system.file(file.path("lib", "GatingSet.pb.o"), package = "RProtoBufLib")
# on Windows and Solaris we need to explicitly link against pb.dll
if ((Sys.info()['sysname'] %in% c("Windows", "SunOS")) && !isSparc()) {
pb <- pbLibPath()
res <- paste("-L", asBuildPath(dirname(pb)), " -lprotobuf", sep = "")
gs <- gsLibPath()
res <- paste("-L", asBuildPath(dirname(pb)), asBuildPath(dirname(gs)), " -lprotobuf -lGatingSet.pb", sep = "")
} else {
res <- ""
}
if(all)
res <- paste(res, gslibs)
# if(all)
# res <- paste(res, gslibs)
res
}

Expand All @@ -70,6 +71,25 @@ pbLibPath <- function(suffix = "") {
NULL
}
}
gsLibPath <- function(suffix = "") {
sysname <- Sys.info()['sysname']
pbSupported <- list(
"Darwin" = paste("libGatingSet.pb", suffix, ".dylib", sep = ""),
"Linux" = paste("libGatingSet.pb", suffix, ".so", sep = ""),
"Windows" = paste("libGatingSet.pb", suffix, ".dll", sep = ""),
"SunOS" = paste("libGatingSet.pb", suffix, ".so", sep = "")
)
# browser()
if ((sysname %in% names(pbSupported)) && !isSparc()) {
libDir <- "lib/"
if (sysname == "Windows")
libDir <- paste(libDir, .Platform$r_arch, "/", sep="")
system.file(paste(libDir, pbSupported[[sysname]], sep = ""),
package = "RProtoBufLib")
} else {
NULL
}
}

isSparc <- function() {
Sys.info()['sysname'] == "SunOS" && Sys.info()[["machine"]] != "i86pc"
Expand Down
19 changes: 14 additions & 5 deletions R/hooks.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@ dllInfo <- NULL
pb <- pbLibPath()
if (!is.null(pb)) {
if (!file.exists(pb)) {
warning(paste("pb library", pb, "not found."))
warning(paste("libprotobuf library", pb, "not found."))
} else {
dllInfo <<- dyn.load(pb, local = FALSE, now = TRUE)
}
}

gs <- gsLibPath()
if (!is.null(gs)) {
if (!file.exists(gs)) {
warning(paste("libGatingSet.pb library", gs, "not found."))
} else {
dllInfo <<- c(dllInfo, dyn.load(gs, local = FALSE, now = TRUE))
}
}

# load the package library
# library.dynam("RProtoBufLib", pkgname, libname)

Expand All @@ -23,7 +31,8 @@ dllInfo <- NULL
# unload the package library
# library.dynam.unload("RProtoBufLib", libpath)

# unload pb if we loaded it
if (!is.null(dllInfo))
dyn.unload(dllInfo[["path"]])
# unload dll if we loaded it
for(dll in dllInfo)
if (!is.null(dll))
dyn.unload(dll[["path"]])
}
10 changes: 7 additions & 3 deletions src/Makevars.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ USER_INCLUDE = ${R_PACKAGE_DIR}/include
USER_LIB_DIR = ${R_PACKAGE_DIR}/lib${R_ARCH}/

#expose compiled object of GatingSet pb API for cytolib to link to
GS_LIB = GatingSet_pb_lib/GatingSet.pb.o
GS_LIB=libGatingSet.pb${SHLIB_EXT}
GS_LIB_DIR = GatingSet_pb_lib

all: copying


$(GS_LIB):
${SHLIB_CXXLD} ${SHLIB_CXXLDFLAGS} ${CXXPICFLAGS} ${PKG_CPPFLAGS} -o ${GS_LIB_DIR}/${GS_LIB} ${GS_LIB_DIR}/GatingSet.pb.cc

#copy hdf5 library headers to package include
copying: $(GS_LIB)
mkdir -p "${USER_INCLUDE}"
cp -r @PBBUILD@/include/google ${USER_INCLUDE}
mkdir -p "${USER_LIB_DIR}"
cp @PBBUILD@/lib/* ${USER_LIB_DIR}
cp $(GS_LIB) ${USER_LIB_DIR}/GatingSet.pb.o
cp ${GS_LIB_DIR}/$(GS_LIB) ${USER_LIB_DIR}/${GS_LIB}

0 comments on commit e865d69

Please sign in to comment.