Skip to content

Commit eecb04d

Browse files
committed
Do not distribute GCC runtime libraries in FastR
1 parent 1478987 commit eecb04d

File tree

2 files changed

+247
-5
lines changed

2 files changed

+247
-5
lines changed

com.oracle.truffle.r.native/gnur/Makefile.libs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ LAPACK_TARGET := $(FASTR_LIB_DIR)/libRlapack$(DYLIB_EXT)
3636
# at a minimum we need to know where libpcre/libz/libgfortran/libquadmath are located,
3737
# to keep the Java side simpler, we (may) copy them to $(FASTR_LIB_DIR) unless
3838
# they were found in the standard system locations
39-
OTHER_LIB_TARGETS = pcre z gfortran quadmath gcc_s
39+
# Note: removed gfortran quadmath gcc_s for the time being
40+
OTHER_LIB_TARGETS = pcre z
4041

4142
.PHONY: all
4243

com.oracle.truffle.r.native/run/fastr_tools/configure_fastr

Lines changed: 245 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
#
3-
# Copyright (c) 2019, 2019, Oracle and/or its affiliates. All rights reserved.
3+
# Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
44
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
#
66
# This code is free software; you can redistribute it and/or modify it
@@ -22,6 +22,247 @@
2222
# questions.
2323
#
2424

25-
echo "This script has been deprecated."
26-
echo "Issues with FastR configuration for building R packages and suggestions how to fix them should now be displayed during package installation process."
27-
echo "See https://www.graalvm.org/docs/reference-manual/languages/r/ for more details."
25+
# This script is deployed as <FASTR>/bin/configure_fastr.sh
26+
27+
source="${BASH_SOURCE[0]}"
28+
# "un-link" the source path
29+
while [ -h "$source" ] ; do
30+
prev_source="$source"
31+
source="$(readlink "$source")";
32+
if [[ "$source" != /* ]]; then
33+
# if the link was relative, it was relative to where it came from
34+
dir="$( cd -P "$( dirname "$prev_source" )" && pwd )"
35+
source="$dir/$source"
36+
fi
37+
done
38+
39+
function printHelp {
40+
if [[ "$OSTYPE" == "darwin"* ]]; then
41+
echo "Checks presence of FastR dependencies and configures the paths in dynamic libraries accordingly."
42+
echo "usage: configure_fastr [--help] [--macos-no-homebrew] [--gcc-lib-path <path>]"
43+
else
44+
echo "Checks presence of FastR dependencies."
45+
echo "usage: configure_fastr [--help]"
46+
fi
47+
48+
if [[ "$OSTYPE" == "darwin"* ]]; then
49+
echo ""
50+
echo "optional arguments:"
51+
echo " --gcc-lib-path <path> Use the <path> to locate the required gfortran libraries."
52+
echo " --macos-no-homebrew Allows the script to proceed even if the target system does not have homebrew"
53+
fi
54+
}
55+
56+
GCC_LIB_PATH=""
57+
NO_BREW=0
58+
while [[ $# -gt 0 ]]; do
59+
case $1 in
60+
--help)
61+
printHelp
62+
exit 0
63+
;;
64+
--gcc-lib-path)
65+
shift
66+
GCC_LIB_PATH=$1
67+
;;
68+
--macos-no-homebrew)
69+
NO_BREW=1
70+
;;
71+
*)
72+
>&2 echo "Unknown option '$1'"
73+
printHelp
74+
exit 1
75+
;;
76+
esac
77+
shift
78+
done
79+
80+
(
81+
if [[ "$OSTYPE" == "linux-gnu" ]]; then
82+
if ! command -v ldconfig>/dev/null; then
83+
>&2 echo "Tool 'ldconfig' is not available. Maybe you need to run this as a root?"
84+
exit 2
85+
fi
86+
res=0
87+
for lib in libgfortran.so.3 libquadmath.so.0 libgcc_s.so.1; do
88+
if ! ldconfig -p | grep --quiet $lib; then
89+
echo "Error: could not find gfortran3 runtime library: $lib"
90+
echo "Please install the gfortran3 runtime libraries:"
91+
echo " On Debian based systems: apt-get install libgfortran3"
92+
echo " On Oracle Linux 7: yum install libgfortran"
93+
echo " On Oracle Linux 8: yum install compat-libgfortran-48"
94+
res=1
95+
break
96+
fi
97+
done
98+
if ! ldconfig -p | grep --quiet "libgomp.so.1"; then
99+
echo "Error: could not find OpenMP runtime library: libgomp.so.1"
100+
echo "Please install the OpenMP runtime library runtime libraries:"
101+
echo " On Debian based systems: apt-get install libgomp1"
102+
echo " On Oracle Linux 7 and 8: yum install libgomp"
103+
echo " Note: Oracle Linux 8 should contain libgomp by default"
104+
res=1
105+
fi
106+
if which gfortran > /dev/null 2> /dev/null; then
107+
echo "Note: if you intend to install R packages you may need additional packages."
108+
echo "The following packages should cover the most commonly used R packages:"
109+
echo " On Debian based systems: apt-get install build-essential gfortran libxml2 libc++-dev"
110+
echo " On Oracle Linux 7 and 8: yum groupinstall 'Development Tools'"
111+
if [[ $res != 0 ]]; then
112+
echo "Caution: you still need to install gfortran3 runtime libraries on all systems where this version is not the default (Ubuntu 18 or higher, Oracle Linux 8 or higher)."
113+
fi
114+
fi
115+
if [[ $res != 0 ]]; then
116+
echo "The basic configuration of FastR failed."
117+
echo "To learn more:"
118+
echo " run this script with '--help'"
119+
echo " visit https://www.graalvm.org/docs/reference-manual/languages/r"
120+
exit 1
121+
else
122+
echo "The basic configuration of FastR was successfull."
123+
fi
124+
elif [[ "$OSTYPE" == "darwin"* ]]; then
125+
126+
if which brew; then
127+
GCC_DARWIN_HOME=/usr/local/Cellar/[email protected]/4.9.4_1/lib/gcc/4.9
128+
129+
if [ -d "$GCC_DARWIN_HOME" ] ; then
130+
echo "gcc 4.9 installation found."
131+
132+
cd -P "$( dirname "$source" )/../lib"
133+
# correct paths on Mac OSX
134+
GFORTRAN_LIBRARIES="libgfortran.3.dylib libquadmath.0.dylib libgomp.1.dylib libgcc_s.1.dylib"
135+
TARGET_LIBRARIES="`find ../library/* | grep "\(\.dylib\|\.so\)$"` `find * | grep "\(\.dylib\|\.so\)$"`"
136+
for GFORTRAN_LIB in $GFORTRAN_LIBRARIES
137+
do
138+
LIB_LOCATION="${GCC_DARWIN_HOME}/${GFORTRAN_LIB}"
139+
for TARGET_LIB in $TARGET_LIBRARIES
140+
do
141+
# don't look at symlinks
142+
if [ ! -L "${TARGET_LIB}" ] ; then
143+
# grep for the current path of this gfortran library in this library's linking info
144+
CURRENT_LIB_NAME=`otool -L ${TARGET_LIB} | grep -o "\t.*${GFORTRAN_LIB}"`
145+
if [ ! -z "$CURRENT_LIB_NAME" ] ; then
146+
if [ "$CURRENT_LIB_NAME" != "$LIB_LOCATION" ] ; then
147+
# change to the new location
148+
echo "changing path to ${GFORTRAN_LIB} in ${TARGET_LIB} to $LIB_LOCATION"
149+
install_name_tool -change $CURRENT_LIB_NAME $LIB_LOCATION ${TARGET_LIB}
150+
fi
151+
fi
152+
fi
153+
done
154+
done
155+
else
156+
echo "No Homebrew gcc 4.9 installation found."
157+
echo "Please ensure that you have gcc installed on your system using the homebrew command:"
158+
echo " brew install [email protected]"
159+
160+
HOMEBREW_PREFIX_OUT=`brew config | grep HOMEBREW_PREFIX`
161+
HOMEBREW_PREFIX=${HOMEBREW_PREFIX_OUT##*: }
162+
if [[ "$HOMEBREW_PREFIX" != "/usr/local" ]]; then
163+
echo "Your Homebrew uses other than the default installation directory prefix (i.e. /usr/local)."\
164+
"Since FastR assumes the default prefix, use the following command to create a symbolic link to your Homebrew installations:"
165+
echo " sudo ln -s $HOMEBREW_PREFIX/Cellar /usr/local/Cellar"
166+
fi
167+
168+
exit 1
169+
fi
170+
else # not "which brew"
171+
if [ $NO_BREW = 0 ]; then
172+
echo "FastR depends on GFortran 3 runtime libraries."
173+
echo "It appears that this system does not use the homebrew package manager."
174+
echo "We suggest to use homebrew and install the necessary dependencies with:"
175+
echo " brew install [email protected]"
176+
echo "If you want to use another installation of GFortran 3 libraries, re-run this script with '--macos-no-homebrew'."
177+
exit 2
178+
fi
179+
180+
cd -P "$( dirname "$source" )/../lib"
181+
# correct paths on Mac OSX
182+
GFORTRAN_LIBRARIES="libgfortran.3.dylib libquadmath.0.dylib libgomp.1.dylib libgcc_s.1.dylib"
183+
# This allows determining if all libraries were found after the main loop
184+
GFORTRAN_LIBRARIES_CHECK="libgfortran libquadmath libgomp libgcc_s"
185+
GFORTRAN_LOCATIONS="$GCC_LIB_PATH /opt/local/lib /opt/local/lib/libgcc /usr/local/gfortran/lib"
186+
TARGET_LIBRARIES="`find ../library/* | grep "\(\.dylib\|\.so\)$"` `find * | grep "\(\.dylib\|\.so\)$"`"
187+
FOUND=""
188+
FOUND_FULL=""
189+
LAST_FOUND=""
190+
for GFORTRAN_LIB in $GFORTRAN_LIBRARIES
191+
do
192+
# Remove the 'dylib' extension
193+
GFORTRAN_LIB_BASE=${GFORTRAN_LIB%.*}
194+
# Remove the number extension
195+
GFORTRAN_LIB_BASE=${GFORTRAN_LIB_BASE%.*}
196+
if [ "$LAST_FOUND" = "$GFORTRAN_LIB_BASE" ] ; then
197+
# A previous version of the current library has already been found
198+
echo "skipping $GFORTRAN_LIB"
199+
continue;
200+
fi
201+
for LOCATION in $GFORTRAN_LOCATIONS
202+
do
203+
if test -f "${LOCATION}/${GFORTRAN_LIB}"; then
204+
LIB_LOCATION="${LOCATION}/${GFORTRAN_LIB}"
205+
FOUND="$FOUND $GFORTRAN_LIB_BASE"
206+
LAST_FOUND=$GFORTRAN_LIB_BASE
207+
echo "${GFORTRAN_LIB} found at ${LIB_LOCATION}"
208+
for TARGET_LIB in $TARGET_LIBRARIES
209+
do
210+
# don't look at symlinks
211+
if [ ! -L "${TARGET_LIB}" ] ; then
212+
# grep for the current path of this gfortran library in this library's linking info
213+
CURRENT_LIB_NAME=`otool -L ${TARGET_LIB} | grep -o "\t.*${GFORTRAN_LIB_BASE}[^ ]*"`
214+
if [ ! -z "$CURRENT_LIB_NAME" ] ; then
215+
if [ "$CURRENT_LIB_NAME" != "$LIB_LOCATION" ] ; then
216+
# change to the new location
217+
echo "changing path to ${GFORTRAN_LIB} in ${TARGET_LIB} to $LIB_LOCATION"
218+
FOUND_FULL="${FOUND_FULL}\n ${LIB_LOCATION}"
219+
install_name_tool -change $CURRENT_LIB_NAME $LIB_LOCATION ${TARGET_LIB}
220+
fi
221+
fi
222+
fi
223+
done
224+
break
225+
fi
226+
done
227+
done
228+
229+
if [ "$FOUND" != " $GFORTRAN_LIBRARIES_CHECK" ] ; then
230+
echo "From expected libraries '$GFORTRAN_LIBRARIES_CHECK' found only '$FOUND'."
231+
echo "Please ensure that you have GFortran 3 installed on your system."
232+
echo "We suggest to use homebrew and install the necessary dependencies with:"
233+
echo " brew install [email protected]"
234+
echo "If the GFortran 3 runtime libraries are installed in a non-standard location, you can specify that location using the '--gcc-lib-path' parameter."
235+
exit 1
236+
else
237+
echo "Succesfully updated FastR installation to use the GFortran 3 system libraries."
238+
FASTR_HOME=$(cd ..; pwd -P )
239+
echo "The fortran compiler flags in $FASTR_HOME/etc/Makeconf (variable FLIBS) were not updated and must be adjusted manually!"
240+
fi
241+
fi # which brew
242+
else
243+
echo "Unknown operating system."
244+
echo "FastR may still work."
245+
echo "Make sure that GCC including gfortran and OpenMP is installed on your system."
246+
fi
247+
248+
if [[ $CONFIGURE_ETC = 1 ]]; then
249+
export GRAALVM_VERSION=`grep -o 'GRAALVM_VERSION=.*' "../../../../release" | cut -d= -f2`
250+
cd ../etc
251+
echo "Running the configure script..."
252+
./configure --with-x=no --with-aqua=no --enable-memory-profiling FFLAGS=-O2 $CONFIGURE_ARGS > configure.log 2>&1
253+
res=$?
254+
if [[ $res != 0 ]]; then
255+
echo "The configuration step failed."
256+
echo "The log was saved into ${PWD}/configure.log"
257+
echo "FastR may still work, but compilation of some R packages may fail"
258+
exit 1
259+
fi
260+
ed Makeconf < edMakeconf.etc > /dev/null 2>/dev/null
261+
export R_DEFAULT_PACKAGES=base
262+
R_LIBS_USER=`"../bin/R" --slave -e 'cat(path.expand(Sys.getenv("R_LIBS_USER")))'`
263+
echo "Creating user specific library directory: $R_LIBS_USER"
264+
mkdir -p "$R_LIBS_USER"
265+
echo "DONE"
266+
fi
267+
268+
)

0 commit comments

Comments
 (0)