Skip to content

Commit 42b0be6

Browse files
committed
Add libc++.so/libc++abi.so to rpath only when needed
1 parent 9c9d8d0 commit 42b0be6

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

lib/mri/mkmf.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2302,6 +2302,16 @@ def depend_rules(depend)
23022302
# +VPATH+ and added to the list of +INCFLAGS+.
23032303
#
23042304
def create_makefile(target, srcprefix = nil)
2305+
if defined?(::TruffleRuby) and $LIBRUBYARG.to_s.strip.empty?
2306+
# $LIBRUBYARG was explicitly unset, the built library is not a C extension but used with FFI (e.g., sassc does).
2307+
# Since $LIBRUBYARG is unset we won't link to libgraalvm-llvm.so, which is wanted.
2308+
# In the case the library uses C++ code, libc++.so/libc++abi.so will be linked and needs to be found by NFI.
2309+
# The toolchain does not pass -rpath automatically for libc++.so/libc++abi.so, so we do it.
2310+
libcxx_dir = ::Truffle::Boot.toolchain_paths(:LD_LIBRARY_PATH)
2311+
raise 'libcxx_dir should not be empty' if libcxx_dir.empty?
2312+
$DLDFLAGS << " -rpath #{libcxx_dir}"
2313+
end
2314+
23052315
$target = target
23062316
libpath = $DEFLIBPATH|$LIBPATH
23072317
message "creating Makefile\n"
@@ -2650,7 +2660,9 @@ def init_mkmf(config = CONFIG, rbconfig = RbConfig::CONFIG)
26502660
$LIBRUBYARG = ""
26512661
$LIBRUBYARG_STATIC = config['LIBRUBYARG_STATIC']
26522662
$LIBRUBYARG_SHARED = config['LIBRUBYARG_SHARED']
2653-
$DEFLIBPATH = [$extmk ? "$(topdir)" : "$(#{config["libdirname"] || "libdir"})"]
2663+
# TruffleRuby: no need to add libdir to rpath of C exts, since we do not link to libtruffleruby (GR-29448)
2664+
# That way, C extensions do not depend on a specific TruffleRuby build.
2665+
$DEFLIBPATH = defined?(::TruffleRuby) ? [] : [$extmk ? "$(topdir)" : "$(#{config["libdirname"] || "libdir"})"]
26542666
$DEFLIBPATH.unshift(".")
26552667
$LIBPATH = []
26562668
$INSTALLFILES = []

lib/truffle/rbconfig.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,6 @@ module RbConfig
117117
warnflags << '-Werror' # Make sure there are no warnings in core C extensions
118118
else
119119
libtruffleruby = "#{cext_dir}/libtruffleruby.#{dlext}"
120-
121-
# Needed to find libc++.so when using NFI on the library since the toolchain does not pass -rpath automatically
122-
libcxx_dir = Truffle::Boot.toolchain_paths(:LD_LIBRARY_PATH)
123-
raise 'libcxx_dir should not be empty' if libcxx_dir.empty?
124-
rpath_libcxx = " -rpath #{libcxx_dir}"
125-
ldflags << rpath_libcxx
126-
dldflags << rpath_libcxx
127120
end
128121

129122
# We do not link to libtruffleruby here to workaround GR-29448

0 commit comments

Comments
 (0)