Skip to content

Commit

Permalink
Fixes for C++ extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Nov 13, 2023
1 parent a9ac3bf commit 0d966be
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
4 changes: 3 additions & 1 deletion lib/cext/include/ruby/internal/core/rdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
* @return The passed object casted to ::RData.
*/
#ifdef TRUFFLERUBY
struct RData* rb_tr_rdata(VALUE object);
#define RDATA(obj) rb_tr_rdata(obj)
#else
#define RDATA(obj) RBIMPL_CAST((struct RData *)(obj))
Expand Down Expand Up @@ -158,6 +157,9 @@ struct RData {
};

RBIMPL_SYMBOL_EXPORT_BEGIN()
#ifdef TRUFFLERUBY
struct RData* rb_tr_rdata(VALUE object);
#endif

/**
* This is the primitive way to wrap an existing C struct into ::RData.
Expand Down
5 changes: 4 additions & 1 deletion lib/cext/include/ruby/internal/core/rtypeddata.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
* @return The passed object casted to ::RTypedData.
*/
#ifdef TRUFFLERUBY
struct RTypedData* rb_tr_rtypeddata(VALUE object);
#define RTYPEDDATA(obj) rb_tr_rtypeddata(obj)
#else
#define RTYPEDDATA(obj) RBIMPL_CAST((struct RTypedData *)(obj))
Expand Down Expand Up @@ -370,6 +369,10 @@ struct RTypedData {
};

RBIMPL_SYMBOL_EXPORT_BEGIN()
#ifdef TRUFFLERUBY
struct RTypedData* rb_tr_rtypeddata(VALUE object);
#endif

RBIMPL_ATTR_NONNULL((3))
/**
* This is the primitive way to wrap an existing C struct into ::RTypedData.
Expand Down
2 changes: 1 addition & 1 deletion lib/cext/include/ruby/internal/encoding/sprintf.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
#include "ruby/internal/encoding/encoding.h"
#include "ruby/internal/value.h"

RBIMPL_SYMBOL_EXPORT_BEGIN()
#ifdef TRUFFLERUBY
// We need to declare rb_enc_vsprintf() before rb_enc_sprintf()
RBIMPL_ATTR_NONNULL((2))
RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 0)
VALUE rb_enc_vsprintf(rb_encoding *enc, const char *fmt, va_list ap);
#endif

RBIMPL_SYMBOL_EXPORT_BEGIN()
RBIMPL_ATTR_NONNULL((2))
RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 2, 3)
/**
Expand Down
22 changes: 11 additions & 11 deletions lib/cext/include/truffleruby/truffleruby-pre.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
#ifndef TRUFFLERUBY_PRE_H
#define TRUFFLERUBY_PRE_H

#if defined(__cplusplus)
extern "C" {
#endif

RUBY_SYMBOL_EXPORT_BEGIN

// Configuration

// We disable USE_FLONUM, as we do not use pointer tagging for Float.
Expand All @@ -39,6 +33,17 @@ RUBY_SYMBOL_EXPORT_BEGIN
// Skip DTrace-generated code
#define DTRACE_PROBES_DISABLED 1

// Declare VALUE for below

#include "ruby/defines.h"
#include "ruby/internal/value.h"

#if defined(__cplusplus)
extern "C" {
#endif

RUBY_SYMBOL_EXPORT_BEGIN

// Support

#include <truffleruby/truffleruby-abi-version.h>
Expand All @@ -52,11 +57,6 @@ const char* rb_tr_abi_version(void) {
return TRUFFLERUBY_ABI_VERSION;
}

// Declare VALUE for below

#include "ruby/defines.h"
#include "ruby/internal/value.h"

// Helpers

#ifndef offsetof
Expand Down
5 changes: 4 additions & 1 deletion lib/mri/mkmf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2346,11 +2346,14 @@ def depend_rules(depend)
# +VPATH+ and added to the list of +INCFLAGS+.
#
def create_makefile(target, srcprefix = nil)
if defined?(::TruffleRuby) and $LIBRUBYARG == nil
if defined?(::TruffleRuby) and ($LIBRUBYARG == nil or !Truffle::Boot.get_option('building-core-cexts'))
# $LIBRUBYARG was explicitly unset, the built library is not a C extension but used with FFI (e.g., sassc does).
# Since $LIBRUBYARG is unset we won't link to libgraalvm-llvm.so, which is expected.
# In the case the library uses C++ code, libc++.so/libc++abi.so will be linked and needs to be found by NFI.
# The toolchain does not pass -rpath automatically for libc++.so/libc++abi.so, so we do it.
#
# We also add this rpath for C++ extensions (which have $LIBRUBYARG != nil)
# so that libc++.so/libc++abi.so can be found.
libcxx_dir = ::Truffle::Boot.toolchain_paths(:LD_LIBRARY_PATH)
raise 'libcxx_dir should not be empty' if libcxx_dir.empty?
$DLDFLAGS << " -rpath #{libcxx_dir}"
Expand Down

0 comments on commit 0d966be

Please sign in to comment.