diff --git a/com.oracle.truffle.r.native/Makefile b/com.oracle.truffle.r.native/Makefile index b180b74236fec2bf279b73e9e96175e5ac3bf96b..98b258d4aea5ba43c0fee6400c68841d969967bf 100644 --- a/com.oracle.truffle.r.native/Makefile +++ b/com.oracle.truffle.r.native/Makefile @@ -27,6 +27,7 @@ export TOPDIR = $(CURDIR) export FASTR_R_HOME=$(abspath $(TOPDIR)/..) +export FASTR_LIB_DIR=$(FASTR_R_HOME)/lib export R_VERSION = 3.1.3 export GNUR_HOME = $(TOPDIR)/gnur/R-$(R_VERSION) diff --git a/com.oracle.truffle.r.native/builtinlibs/Makefile b/com.oracle.truffle.r.native/builtinlibs/Makefile index b1b3c2a1fb5f9464fce0f52ef0f93e9e1c034392..b6cb85fd5a18e174066322f0b3e5141ebdf4fd47 100644 --- a/com.oracle.truffle.r.native/builtinlibs/Makefile +++ b/com.oracle.truffle.r.native/builtinlibs/Makefile @@ -36,7 +36,7 @@ endif SRC = src OBJ = lib -LIBDIR = $(TOPDIR)/../lib +LIBDIR = $(abspath $(TOPDIR)/../lib) C_SOURCES := $(wildcard $(SRC)/*.c) @@ -56,17 +56,19 @@ $(C_OBJECTS): | $(OBJ) $(OBJ): mkdir -p $(OBJ) -# On Darwin we need to create a libR.dylib as the libRlapack library has a dependency on libR -# We also use this as the "entry library" and establish dependencies on all the shared libraries -# that we need +# On Darwin we need to create a libR.dylib in which xerbla goes +# as the libRlapack library has a dependency on libR and expecte xerbla to +# be defined there. We could fix this if we cared by not using the GnuR instance of the +# libRlapack and rebuilding it from scratch. + ifeq ($(OS_NAME), Darwin) LIB_R := $(LIBDIR)/libR$(DYLIB_EXT) libr: $(LIB_R) -$(LIB_R): $(OBJ)/rlib_dummy.o +$(LIB_R): $(OBJ)/xerbla.o mkdir -p $(LIBDIR) - $(DYLIB_LD) $(DYLIB_LDFLAGS) -o $(LIB_R) -current_version $(R_VERSION) -compatibility_version $(R_VERSION) $(OBJ)/rlib_dummy.o + $(DYLIB_LD) $(DYLIB_LDFLAGS) -o $(LIB_R) -current_version $(R_VERSION) -compatibility_version $(R_VERSION) $(OBJ)/xerbla.o cleanlibr: rm -f $(LIB_R) diff --git a/com.oracle.truffle.r.native/builtinlibs/src/rlib_dummy.c b/com.oracle.truffle.r.native/builtinlibs/src/rlib_dummy.c deleted file mode 100644 index bf7f62896adfa4b2725af0ad5ded724230b9fd88..0000000000000000000000000000000000000000 --- a/com.oracle.truffle.r.native/builtinlibs/src/rlib_dummy.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -// empty file for now diff --git a/com.oracle.truffle.r.native/gnur/Makefile.libs b/com.oracle.truffle.r.native/gnur/Makefile.libs index c13f94f972f3651ed2a8c019eea25fef36f57b48..b402a9cdfd2e2bca5c5327aa20e2cc51f98f09aa 100644 --- a/com.oracle.truffle.r.native/gnur/Makefile.libs +++ b/com.oracle.truffle.r.native/gnur/Makefile.libs @@ -27,7 +27,7 @@ ifneq ($(MAKECMDGOALS),clean) include $(TOPDIR)/platform.mk endif -TARGET_DIR := $(TOPDIR)/../lib +TARGET_DIR := $(abspath $(TOPDIR)/../lib) BLAS_TARGET := $(TARGET_DIR)/libRblas$(DYLIB_EXT) LAPACK_TARGET := $(TARGET_DIR)/libRlapack$(DYLIB_EXT) PCRE_TARGET := $(TARGET_DIR)/libpcre$(DYLIB_EXT) @@ -42,6 +42,10 @@ $(BLAS_TARGET): $(GNUR_HOME)/lib/libRblas$(DYLIB_EXT) $(LAPACK_TARGET): $(GNUR_HOME)/lib/libRlapack$(DYLIB_EXT) cp $(GNUR_HOME)/lib/libRlapack$(DYLIB_EXT) $(LAPACK_TARGET) +ifeq ($(OS_NAME),Darwin) + install_name_tool -change libRblas.dylib $(BLAS_TARGET) $(LAPACK_TARGET) + install_name_tool -change libR.dylib $(TARGET_DIR)/libR.dylib $(LAPACK_TARGET) +endif PCRE_OBJS := $(wildcard $(GNUR_HOME)/src/extra/pcre/pcre_*.o) diff --git a/com.oracle.truffle.r.native/library/Makefile b/com.oracle.truffle.r.native/library/Makefile index fd056e3f3666382b2072b7f53b1256064b7d5410..095d3a0226f166682be2bfee4b14e66f23cc549e 100644 --- a/com.oracle.truffle.r.native/library/Makefile +++ b/com.oracle.truffle.r.native/library/Makefile @@ -24,7 +24,7 @@ .PHONY: all clean libdir make_subdirs clean_subdirs SUBDIRS = base compiler datasets utils grDevices graphics grid parallel splines stats methods tools fastr -export FASTR_LIBDIR = $(TOPDIR)/../library +export FASTR_LIBRARY_DIR = $(abspath $(TOPDIR)/../library) all: libdir make_subdirs @@ -41,4 +41,4 @@ clean_subdirs: done libdir: - mkdir -p $(FASTR_LIBDIR) + mkdir -p $(FASTR_LIBRARY_DIR) diff --git a/com.oracle.truffle.r.native/library/base/Makefile b/com.oracle.truffle.r.native/library/base/Makefile index 40d232856123c9f8cdf290036e88594ba96db7c2..bc26992f4cd67d8734cbefa0daa60454deb4da29 100644 --- a/com.oracle.truffle.r.native/library/base/Makefile +++ b/com.oracle.truffle.r.native/library/base/Makefile @@ -21,7 +21,7 @@ # questions. # -RPROFILE := $(FASTR_LIBDIR)/base/R/Rprofile +RPROFILE := $(FASTR_LIBRARY_DIR)/base/R/Rprofile RPROFILE_ORIG := $(RPROFILE).orig LIB_PKG_POST = $(RPROFILE) diff --git a/com.oracle.truffle.r.native/library/fastr/Makefile b/com.oracle.truffle.r.native/library/fastr/Makefile index 3ceba8fe3cc308aae5f903c4cf4afe73d57885a3..65312e92888e3f6e8c2b4b656c53c4694af95f24 100644 --- a/com.oracle.truffle.r.native/library/fastr/Makefile +++ b/com.oracle.truffle.r.native/library/fastr/Makefile @@ -32,7 +32,7 @@ .PHONY: all PKG_FILES = $(shell find src/ -type f -name '*') -INSTALL_SENTINEL = $(FASTR_LIBDIR)/fastr/DESCRIPTION +INSTALL_SENTINEL = $(FASTR_LIBRARY_DIR)/fastr/DESCRIPTION PKG_TAR = lib/fastr.tar @@ -43,7 +43,7 @@ $(PKG_TAR): $(PKG_FILES) (cd src; tar cf ../$(PKG_TAR) *) $(INSTALL_SENTINEL): $(PKG_TAR) - $(GNUR_HOME)/bin/R CMD INSTALL --library=$(FASTR_LIBDIR) src + $(GNUR_HOME)/bin/R CMD INSTALL --library=$(FASTR_LIBRARY_DIR) src clean: rm -f $(PKG_TAR) diff --git a/com.oracle.truffle.r.native/library/lib.mk b/com.oracle.truffle.r.native/library/lib.mk index e525e23d1b065211101e7e71c6e9e55b9d803b13..6812f369bde1640fd37bfded38562670fe4825a4 100644 --- a/com.oracle.truffle.r.native/library/lib.mk +++ b/com.oracle.truffle.r.native/library/lib.mk @@ -25,7 +25,7 @@ # The common part of the archive (everything except the .so) is created # by copying the directory in the GnuR build. Then the FastR .so file is created # and overwrites the default. The libraries are stored in the directory denoted -# FASTR_LIBDIR. +# FASTR_LIBRARY_DIR. # A package that requires special processing before the library is built should # define LIB_PKG_PRE and for post processing define LIB_PKG_POST in its Makefile. @@ -66,7 +66,7 @@ FFI_INCLUDES = -I$(TOPDIR)/include -I$(TOPDIR)/include/R_ext INCLUDES := $(JNI_INCLUDES) $(FFI_INCLUDES) -PKGDIR := $(FASTR_LIBDIR)/$(PKG) +PKGDIR := $(FASTR_LIBRARY_DIR)/$(PKG) ifneq ($(C_SOURCES),) all: $(LIB_PKG_PRE) libcommon $(LIB_PKG) $(LIB_PKG_POST) @@ -77,8 +77,8 @@ endif libcommon: $(PKGDIR) $(PKGDIR): $(GNUR_HOME)/library/$(PKG) - (cd $(GNUR_HOME)/library; tar cf - $(PKG)) | (cd $(FASTR_LIBDIR); tar xf -) - touch $(FASTR_LIBDIR)/$(PKG) + (cd $(GNUR_HOME)/library; tar cf - $(PKG)) | (cd $(FASTR_LIBRARY_DIR); tar xf -) + touch $(FASTR_LIBRARY_DIR)/$(PKG) $(C_OBJECTS): | $(OBJ) @@ -90,8 +90,16 @@ $(OBJ): $(LIB_PKG): $(C_OBJECTS) $(F_OBJECTS) $(PKGDIR) mkdir -p $(LIBDIR) $(DYLIB_LD) $(DYLIB_LDFLAGS) -o $(LIB_PKG) $(C_OBJECTS) $(F_OBJECTS) $(PKG_LIBS) - mkdir -p $(FASTR_LIBDIR)/$(PKG)/libs - cp $(LIB_PKG) $(FASTR_LIBDIR)/$(PKG)/libs + mkdir -p $(FASTR_LIBRARY_DIR)/$(PKG)/libs + cp $(LIB_PKG) $(FASTR_LIBRARY_DIR)/$(PKG)/libs +# find a way to move into stats makefile (using LIB_PKG_POST) +ifeq ($(OS_NAME),Darwin) +ifeq ($(PACKAGE),stats) + install_name_tool -change libRblas.dylib $(FASTR_R_HOME)/lib/libRblas.dylib $(FASTR_LIBRARY_DIR)/$(PKG)/libs/$(PKG).so + install_name_tool -change libRlapack.dylib $(FASTR_R_HOME)/lib/libRlapack.dylib $(FASTR_LIBRARY_DIR)/$(PKG)/libs/$(PKG).so + install_name_tool -change libappl.dylib $(FASTR_R_HOME)/lib/libappl.dylib $(FASTR_LIBRARY_DIR)/$(PKG)/libs/$(PKG).so +endif +endif $(OBJ)/%.o: $(SRC)/%.c $(H_SOURCES) $(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@ @@ -101,5 +109,5 @@ $(OBJ)/%.o: $(SRC)/%.f clean: $(CLEAN_PKG) rm -rf $(LIBDIR)/* - rm -rf $(FASTR_LIBDIR)/$(PKG) + rm -rf $(FASTR_LIBRARY_DIR)/$(PKG) diff --git a/com.oracle.truffle.r.native/library/stats/Makefile b/com.oracle.truffle.r.native/library/stats/Makefile index a899a3382188a43d6788190e8b44f80683557c79..3b7c919081ec03e4f1fe3fc92dfa4038f56cc3a9 100644 --- a/com.oracle.truffle.r.native/library/stats/Makefile +++ b/com.oracle.truffle.r.native/library/stats/Makefile @@ -27,12 +27,13 @@ LIB_PKG_PRE = $(OBJ)/fft.o GNUR_FFT := $(GNUR_HOME)/src/library/stats/src/fft.c CLEAN_PKG := cleanfft -# have to incldue this here for PKG_LIBS + +# have to include this here for PKG_LIBS ifneq ($(MAKECMDGOALS),clean) include $(TOPDIR)/platform.mk endif -PKG_LIBS := $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) +PKG_LIBS := $(LAPACK_LIBS) $(BLAS_LIBS) -lappl -L$(FASTR_LIB_DIR) $(FLIBS) include ../lib.mk diff --git a/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/LibPaths.java b/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/LibPaths.java index 837c51379da8db9035fd84534e71f40cdb1f3a13..7a4cf8d4ab3623735571b88f65e7b18d06f2c243 100644 --- a/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/LibPaths.java +++ b/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/LibPaths.java @@ -29,6 +29,13 @@ import com.oracle.truffle.r.runtime.RPlatform.*; public class LibPaths { + /** + * Returns the absolute path to the directory containing the builtin libraries. + */ + public static String getBuiltinLibPath() { + return FileSystems.getDefault().getPath(REnvVars.rHome(), "lib").toString(); + } + /** * Returns the absolute path to the builtin library {@code libName} for use with * {@link System#load}. diff --git a/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jnr/JNR_Lapack.java b/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jnr/JNR_Lapack.java index fedfd56ad65c45322cb822f29f80139e04bfe08a..57d90fdb891c1539f8774602998bfef28cbbcbe3 100644 --- a/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jnr/JNR_Lapack.java +++ b/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jnr/JNR_Lapack.java @@ -82,7 +82,7 @@ public class JNR_Lapack implements LapackRFFI { } } - private static Lapack lapack() { + static Lapack lapack() { return LapackProvider.lapack(); } diff --git a/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jnr/JNR_RFFIFactory.java b/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jnr/JNR_RFFIFactory.java index 3f03f3bba58b8cdc98755abaf4e06813b2677d3e..2632720fd3bfcab9537a464a7e2f3757ea363823 100644 --- a/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jnr/JNR_RFFIFactory.java +++ b/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jnr/JNR_RFFIFactory.java @@ -22,6 +22,7 @@ */ package com.oracle.truffle.r.runtime.ffi.jnr; +import com.oracle.truffle.r.runtime.RPlatform; import com.oracle.truffle.r.runtime.context.*; import com.oracle.truffle.r.runtime.context.RContext.ContextState; import com.oracle.truffle.r.runtime.ffi.*; @@ -44,12 +45,19 @@ public class JNR_RFFIFactory extends RFFIFactory implements RFFI { * Some package C code calls these functions and, therefore, expects the linpack symbols to * be available, which will not be the case unless one of the functions has already been * called from R code. So we eagerly load the library to define the symbols. + * + * There is an additional problem when running without a *_LIBRARY_PATH being set which is + * mandated by Mac OSX El Capitan, which is we must tell JNR where to find the libraries. */ + String jnrLibPath = LibPaths.getBuiltinLibPath(); + if (RPlatform.getOSInfo().osName.equals("Mac OS X")) { + // Why this is necessary is a JNR mystery + jnrLibPath += ":/usr/lib"; + } + System.setProperty("jnr.ffi.library.path", jnrLibPath); JNR_RAppl.linpack(); - /* - * Same for Rlapack (used by stats). - */ - getLapackRFFI().ilaver(new int[3]); + JNR_Lapack.lapack(); + } /** diff --git a/mx.fastr/mx_fastr.py b/mx.fastr/mx_fastr.py index e5260fedd07ad57e0c396d79b8f0172bc99cbf7b..f28d431e1c63e10589b04f29462a6bd0a80de7c9 100644 --- a/mx.fastr/mx_fastr.py +++ b/mx.fastr/mx_fastr.py @@ -142,24 +142,21 @@ def _get_ldpaths(lib_env_name): def setREnvironment(): ''' If R is run via mx, then the library path will not be set, whereas if it is - run from 'bin/R' it will be, via etc/ldpaths. Except that in the latter case - on Darwin we still need to add /usr/lib to so that JNR can resolve libc for RFFI. + run from 'bin/R' it will be, via etc/ldpaths. + On Mac OS X El Capitan and beyond, this is moot as the variable is not + passed down. It is TBD if we can avoid this on Linux. ''' os.environ['R_HOME'] = _fastr_suite.dir osname = platform.system() - if osname == 'Darwin': - lib_env = 'DYLD_FALLBACK_LIBRARY_PATH' - else: + if osname != 'Darwin': lib_env = 'LD_LIBRARY_PATH' - if os.environ.has_key(lib_env): - lib_value = os.environ[lib_env] - else: - lib_value = _get_ldpaths(lib_env) + if os.environ.has_key(lib_env): + lib_value = os.environ[lib_env] + else: + lib_value = _get_ldpaths(lib_env) - if osname == 'Darwin': - lib_value = lib_value + os.pathsep + '/usr/lib' - os.environ[lib_env] = lib_value + os.environ[lib_env] = lib_value def get_default_jdk(): '''