Skip to content

Commit a744bc0

Browse files
committed
[GR-25193] Fix rpath issues on MacOS.
PullRequest: fastr/2502
2 parents 9f1f167 + 53f6027 commit a744bc0

File tree

1 file changed

+23
-8
lines changed
  • com.oracle.truffle.r.native/fficall

1 file changed

+23
-8
lines changed

com.oracle.truffle.r.native/fficall/Makefile

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,23 +81,38 @@ ifeq ($(FASTR_RFFI),managed)
8181
# nop
8282
else
8383
ifeq ($(OS_NAME),Darwin)
84+
# On Darwin libRnative and libRllvm link to libR so that once they are loaded manually by FastR, libR is loaded
85+
# Moreover, libR links with libRblas and libRlapack, so those get loaded transitively too
86+
# Note that packages do not link with libR properly via @rpath, but that is OK since libR will be loaded explicitly by FastR
8487
$(DYLIB_LD) $(DYLIB_LDFLAGS) -Wl,-rpath,@loader_path/ -o $(R_LIB) -L$(FASTR_LIB_DIR) -lRblas -lRlapack $(VERSION_FLAGS)
8588
$(DYLIB_LD) $(DYLIB_LDFLAGS) -Wl,-rpath,@loader_path/ -Wl,-undefined,dynamic_lookup -o $(NFI_LIB) $(wildcard lib/nfi/*.o) $(wildcard lib/common/*.o) $(wildcard lib/JavaGD/*.o) -L$(FASTR_LIB_DIR) -ldl -lR -lpcre -lz $(F2C) -liconv $(VERSION_FLAGS)
8689
$(DYLIB_LD) $(DYLIB_LDFLAGS) -Wl,-rpath,@loader_path/ -Wl,-undefined,dynamic_lookup -o $(LLVM_LIB) $(wildcard lib/llvm/*.o) $(wildcard lib/common/*.o) $(wildcard lib/JavaGD/*.o) -L$(FASTR_LIB_DIR) -L$(LLVM_LIBS_DIR) -lpolyglot-mock -ldl -lR -lpcre -lz $(F2C) -liconv $(VERSION_FLAGS)
8790

91+
# make the libraries that we just created relocable
92+
install_name_tool -id @rpath/libR.dylib $(R_LIB)
93+
install_name_tool -id @rpath/$(NFI_LIBNAME) $(NFI_LIB)
94+
install_name_tool -id @rpath/$(LLVM_LIBNAME) $(LLVM_LIB)
95+
96+
# libRblas/lapack should resolve any "@path" placeholder in their dependencies list to the directory where they are located
8897
install_name_tool -add_rpath @loader_path/ $(FASTR_LIB_DIR)/libRblas.dylib
8998
install_name_tool -add_rpath @loader_path/ $(FASTR_LIB_DIR)/libRlapack.dylib
9099

100+
# fixup the dependency libR -> libRblas/lapack
101+
# we already configured libR to use its location for "@rpath" placeholder when building it,
102+
# now we need to switch the libRblas/lapack dependencies from absolute paths to "@rpath/..." paths
103+
install_name_tool -change libRblas.dylib @rpath/libRblas.dylib $(R_LIB)
104+
install_name_tool -change libRlapack.dylib @rpath/libRlapack.dylib $(R_LIB)
105+
install_name_tool -change libf2c.so @rpath/libf2c$(DYLIB_EXT) $(R_LIB)
106+
107+
# fixup the dependency libRnative/llvm -> libR in the same way as above
108+
install_name_tool -change $(FASTR_LIB_DIR)/libR.dylib @rpath/libR.dylib $(NFI_LIB)
109+
install_name_tool -change $(FASTR_LIB_DIR)/libR.dylib @rpath/libR.dylib $(LLVM_LIB)
110+
111+
# TODO: check if we really need this and linking with libpolyglot-mock
112+
# given that we use -Wl,-undefined,dynamic_lookup when building libRllvm
91113
install_name_tool -change bin/libpolyglot-mock.dylib $(LLVM_LIBS_DIR)/libpolyglot-mock.dylib $(LLVM_LIB)
92-
93-
install_name_tool -change libRblas.dylib @rpath/libRblas.dylib $(NFI_LIB)
94-
install_name_tool -change libRlapack.dylib @rpath/libRlapack.dylib $(NFI_LIB)
95-
install_name_tool -change libf2c.so @rpath/libf2c$(DYLIB_EXT) $(NFI_LIB)
96114

97-
install_name_tool -id @rpath/libR.dylib $(R_LIB)
98-
install_name_tool -id @rpath/$(NFI_LIBNAME) $(NFI_LIB)
99-
install_name_tool -id @rpath/$(LLVM_LIBNAME) $(LLVM_LIB)
100-
# check if we captured libpcre/libz, rpath those in libR
115+
# check if we captured libpcre/libz, rpath those in libR
101116
python $(FASTR_R_HOME)/mx.fastr/copylib.py updatelib $(FASTR_LIB_DIR) $(FASTR_R_HOME)
102117
else
103118
# not Darwin:

0 commit comments

Comments
 (0)