Skip to content

Commit

Permalink
Merge pull request #17 from snoweye/master
Browse files Browse the repository at this point in the history
0.3-2
  • Loading branch information
snoweye authored Jan 28, 2018
2 parents 926260b + 3db1702 commit 8b94197
Show file tree
Hide file tree
Showing 9 changed files with 398 additions and 23 deletions.
12 changes: 10 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,20 @@ script:
# - ./travis-tool.sh run_tests
# - ./travis-tool.sh install_github snoweye/pbdZMQ
- R CMD INSTALL .
- mkdir ../Rlib
- export R_LIBS_USER=`pwd`/../Rlib
- cp -R /Library/Frameworks/R.framework/Versions/3.4/Resources/library/pbdZMQ ../Rlib
- otool -L ../Rlib/pbdZMQ/libs/pbdZMQ.so
- otool -L ../Rlib/pbdZMQ/libs/libzmq.5.dylib
- Rscript -e "pbdZMQ::get.zmq.cppflags()"
- otool -L ../Rlib/pbdZMQ/libs/libzmq.5.dylib
- Rscript -e "pbdZMQ::get.zmq.ldflags()"
- Rscript -e "pbdZMQ::get.pbdZMQ.ldflags()"
- Rscript -e "pbdZMQ::test.load.zmq()"
- otool -L /Library/Frameworks/R.framework/Versions/3.4/Resources/library/pbdZMQ/libs/pbdZMQ.so
- otool -L /Library/Frameworks/R.framework/Versions/3.4/Resources/library/pbdZMQ/libs/libzmq.5.dylib
- mv ../Rlib ../Rlib.new
- export R_LIBS_USER=`pwd`/../Rlib.new
- Rscript -e "library(pbdZMQ)"
- otool -L ../Rlib.new/pbdZMQ/libs/libzmq.5.dylib

after_failure:
# - ./travis-tool.sh dump_logs
Expand Down
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2018-01-27: Ver 0.3-2
* Add overwrite.shpkg.rpath() for osx.
* Adjust .onLoad() for osx with ZMQ static library.

2018-01-18: Ver 0.3-2
* Adjust .onLoad().
* Add back "src/pkg.m4".

2018-01-07: Ver 0.3-1
* Test with JuniperKernel.

Expand Down
10 changes: 5 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: pbdZMQ
Version: 0.3-1
Date: 2018-01-05
Title: Programming with Big Data -- Interface to ZeroMQ
Version: 0.3-2
Date: 2018-01-11
Title: Programming with Big Data -- Interface to 'ZeroMQ'
Authors@R: c(person("Wei-Chen", "Chen", role = c("aut", "cre"), email =
"wccsnow@gmail.com"),
person("Drew", "Schmidt", role = "aut"),
Expand All @@ -21,8 +21,8 @@ Depends: R (>= 3.2.0)
LazyLoad: yes
LazyData: yes
Copyright: See files AUTHORS, COPYING, COPYING.LESSER, and MAINTAINERS
in 'pbdZMQ/inst/zmq_copyright/' for the ZeroMQ source files in
'src/zmq_src/' which are under GPL-3.
in 'pbdZMQ/inst/zmq_copyright/' for the 'ZeroMQ' source files
in 'src/zmq_src/' which are under GPL-3.
Description: 'ZeroMQ' is a well-known library for high-performance
asynchronous messaging in scalable, distributed applications. This
package provides high level R wrapper functions to easily utilize
Expand Down
27 changes: 24 additions & 3 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,45 @@
--configure-args="--enable-internal-zmq"

--- 'pbdZMQ' installation with external ZeroMQ library such as version 4.2.2:
0. Minimum steps for installing ZeroMQ 4.2.2 library
0. Minimum steps for installing ZeroMQ 4.2.2 shared library

> ./configure \
--prefix=/usr/local/zmq \
--enable-static=no \
--enable-shared=yes \
--with-poller=select \
--without-documentation \
--without-libsodium
> make -j 4; make install

1. Steps for pbdZMQ with the external ZeroMQ static library.
or ZeroMQ 4.2.2 static library

> ./configure \
--prefix=/usr/local/zmq \
--with-pic=yes \
--enable-static=yes \
--enable-shared=no \
--with-poller=select \
--without-documentation \
--without-libsodium
> make -j 4; make install

1. Steps for pbdZMQ with the external ZeroMQ shared library

> R CMD INSTALL pbdZMQ_0.3-0.tar.gz \
--configure-vars="ZMQ_INCLUDE='-I/usr/local/zmq/include' \
ZMQ_LDFLAGS='-L/usr/local/zmq/lib -lzmq'"

or with the external ZeroMQ static library

> R CMD INSTALL pbdZMQ_0.3-0.tar.gz \
--configure-vars="ZMQ_INCLUDE='-I/usr/local/zmq/include' \
ZMQ_LDFLAGS='/usr/local/zmq/lib/libzmq.a'"

provided the external library is installed at "/usr/local/zmq" where
"include/" subdirectory contains "zmq.h" and "lib/" subdirectory contains
the shared library such as "libzmq.so".
the shared library such as "libzmq.so" or the static library such as
"libzmq.a".

--- Testing:
Suppose 'pbdZMQ' is installed correctly. I can run the next from one
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export(get.zmq.ldflags)
export(init.context)
export(init.socket)
export(ls)
export(overwrite.shpkg.rpath)
export(pbd_opt)
export(random_open_port)
export(random_port)
Expand Down
93 changes: 93 additions & 0 deletions R/overwrite_shpkg.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#' Overwrite rpath of linked shared library in osx
#'
#' Overwrite rpath of linked shared library
#' (e.g. \code{JuniperKernel/libs/JuniperKernel.so}
#' in osx only.
#' Typically, it is called by \code{.onLoad()} to update rpath if
#' \code{pbdZMQ} or \code{pbdZMQ/libs/libzmq.*.dylib} was moved to
#' a personal directory
#' (e.g. the binary package was installed to a none default path).
#' The commands \code{otool} and \code{install_name_tool} are required.
#' Permission may be needed (e.g. \code{sudo}) to overwrite the shared
#' library.
#'
#' @param mylib
#' the path where \code{mypkg} was installed (default \code{NULL} that will
#' search from R's path)
#' @param mypkg
#' the package for where \code{mypkg.so} will be checked or updated
#' @param linkingto
#' the package for where \code{libshpkg*.dylib} is located
#' @param shlib
#' name of shlib to be searched for
#'
#' @author Wei-Chen Chen \email{wccsnow@@gmail.com}.
#'
#' Programming with Big Data in R Website: \url{http://r-pbd.org/}
#'
#' @examples
#' \dontrun{
#' ### Called by .onLoad() within "JuniperKernel/R/zzz.R"
#' overwrite.shpkg.rpath(mypkg = "JuniperKernel",
#' linkingto = "pbdZMQ",
#' shlib = "zmq")
#' }
#'
#' @keywords compile
#' @rdname zz_overwrite_shpkg
#' @name Overwrite shpkg
NULL


#' @rdname zz_overwrite_shpkg
#' @export
overwrite.shpkg.rpath <- function(mylib = NULL,
mypkg = "JuniperKernel", linkingto = "pbdZMQ", shlib = "zmq"){
if(Sys.info()[['sysname']] == "Darwin"){
cmd.ot <- system("which otool", intern = TRUE)

### Find mylib if NULL.
if(is.null(mylib)){
mylib <- tools::file_path_as_absolute(system.file(package = mypkg))
}

### Get rpath from mypkg's shared library.
fn.so <- paste(mylib, "/", mypkg, "/libs/", mypkg, ".so", sep = "")
rpath <- system(paste(cmd.ot, " -L ", fn.so, sep = ""), intern = TRUE)

### Get the installed dylib from mypkg's rpath.
ptn1 <- paste("^\\t(.*/", linkingto, "/libs/lib", shlib, ".*\\.dylib) .*$",
sep = "")
i.rpath <- grep(ptn1, rpath)

### 0 means external shlib was linked.
### 1 means internal shlib was built.
if(length(i.rpath) == 1){
fn.dylib <- gsub(ptn1, "\\1", rpath[i.rpath])

### Check if the file were moved to somewhere.
if(!file.exists(fn.dylib)){
### Search the new location from R's library path.
dn <- tools::file_path_as_absolute(
system.file("./libs", package = linkingto))
ptn2 <- paste("lib", shlib, ".*\\.dylib", sep = "")
fn <- list.files(path = dn, pattern = ptn2)

### Install the new location to the mypkg's shared library.
if(length(fn) == 1){
cmd.int <- system("which install_name_tool", intern = TRUE)

new.fn.dylib <- paste(dn, "/", fn, sep = "")
cmd <- paste(cmd.int, " -change ", fn.dylib, " ", new.fn.dylib,
" ", fn.so,
sep = "")
system(cmd)
} else{
stop("The internal shlib can not be identified in linkingto.")
}
}
}
}

return(invisible())
} # End of overwrite.shpkg().
67 changes: 54 additions & 13 deletions R/zzz.r.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,55 @@
}
}

### Load ZMQ.
files <- c("libzmq.so", "libzmq.so.dSYM", "libzmq.dylib", "libzmq.4.dylib",
"libzmq.5.dylib", "libzmq.dll")
### Find ZMQ shared libraries.
if(Sys.info()[['sysname']] == "Darwin"){
files <- list.files(path = dn, pattern = "libzmq.*\\.dylib")

### Make sure the rpath is correct, otherwise overwrite it.
if(ext.libs == "$(R_ZMQ)"){
### By default, there is only one libzmq.*.dylib.
if(length(files) == 1){
cmd.int <- system("which install_name_tool", intern = TRUE)
cmd.ot <- system("which otool", intern = TRUE)

### Get id from libzmq.*.dylib.
fn.dylib <- paste(dn, files, sep = "")
id <- system(paste(cmd.ot, " -D ", fn.dylib, sep = ""),
intern = TRUE)

### Overwrite for new rpath.
if(id[2] != fn.dylib){
# cat("\nBefore install_name_tool: (zzz.r & libzmq.dylib & id)\n")
# print(id)

cmd <- paste(cmd.int, " -id ", fn.dylib, " ", fn.dylib,
sep = "")
system(cmd)

# id <- system(paste(cmd.ot, " -D ", fn.dylib, sep = ""),
# intern = TRUE)
# cat("\nAfter install_name_tool: (zzz.r & libzmq.dylib & id)\n")
# print(id)
}
} else{
stop(paste("More than one libzmq*.dylib found:",
paste(files, collapse = ", "), sep = " "))
}
}
} else{
files <- c("libzmq.so", "libzmq.so.dSYM")
}

### Load "libzmq.*".
for(i.file in files){
fn <- paste(dn, i.file, sep = "")
if(file.exists(fn)){
### Load "libzmq.*".
test <- try(dyn.load(fn, local = FALSE), silent = TRUE)
dn.file <- paste(dn, i.file, sep = "")
if(file.exists(dn.file)){
test <- try(dyn.load(dn.file, local = FALSE), silent = TRUE)
if(class(test) == "try-error"){
stop(paste("Could not load ", fn, sep = ""))
stop(paste("Could not load ", dn.file, ":",
paste(test, collapse = ", "), sep = " "))
}
break
}
}

Expand Down Expand Up @@ -56,13 +94,16 @@
}

### Unload ZMQ.
files <- c("libzmq.so", "libzmq.so.dSYM", "libzmq.dylib", "libzmq.4.dylib",
"libzmq.5.dylib", "libzmq.dll")
if(Sys.info()[['sysname']] == "Darwin"){
files <- list.files(path = dn, pattern = "libzmq.*\\.dylib")
} else{
files <- c("libzmq.so", "libzmq.so.dSYM")
}
files <- paste(dn, files, sep = "")
for(i.file in files){
fn <- paste(dn, i.file, sep = "")
if(file.exists(fn)){
if(file.exists(i.file)){
### Unload "libzmq.so".
test <- try(dyn.unload(fn), silent = TRUE)
test <- try(dyn.unload(i.file), silent = TRUE)
}
}

Expand Down
47 changes: 47 additions & 0 deletions man/zz_overwrite_shpkg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8b94197

Please sign in to comment.