Description
I am trying to get the rice gem working with truffleruby. I know that rice leverges MRI internals, but I wanted to check if it was possible to make it work with truffleruby with a moderate development effort.
Unfortunately, before I even arrived to identify which MRI internal functions required by rice are missing in truffleruby, I got some very weird compilation errors. It seems that the linker does not find functions that should be in the truffleruby dynamic library. Here is an example of the (many) errors I get:
ld64.lld: error: undefined symbol: rb_type
>>> referenced by /Users/mauro/code/test/truffleruby-rice/rice/test/embed_ruby.cpp
>>> /tmp/lto.tmp:(symbol test__default_construct()+0x80)
>>> referenced by /Users/mauro/code/test/truffleruby-rice/rice/test/embed_ruby.cpp
>>> /tmp/lto.tmp:(symbol Rice::Module::Module(unsigned long)+0x40)
>>> referenced by /Users/mauro/code/test/truffleruby-rice/rice/test/embed_ruby.cpp
>>> /tmp/lto.tmp:(symbol Rice::Module::Module(unsigned long)+0x30)
>>> referenced 1694 more times
ld64.lld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors)
clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
I checked with nm and most of the symbols that the linker complains about are apparently in the truffleruby dynamic library:
~❯ nm /Users/mauro/code/git/truffleruby-ws/truffleruby/mxbuild/truffleruby-jvm-ce/languages/ruby/lib/cext/libtruffleruby.dylib | grep rb_type
000000000000dba4 T _rb_type
00000000000053bc T _rb_typeddata_inherited_p
00000000000053dc T _rb_typeddata_is_kind_of
Here is what I did, in details:
I compiled truffleruby using the instructions in the Truffleruby Contributor Workflow document:
cd ~/code/git
mkdir truffleruby-ws
cd truffleruby-ws
git clone https://github.com/oracle/truffleruby.git
cd truffleruby
alias jt=$(PWD)/bin/jt
jt build --env jvm-ce
I then did install the new version of truffleruby in rbenv for convenience:
cd .rbenv/versions
ln -s $(HOME)/code/git/truffleruby-ws/truffleruby/mxbuild/truffleruby-jvm-ce/languages/ruby truffleruby-jvm-ce
I downloaded rice and I set up rbenv to use truffleruby-jvm-ce:
cd ~/code/git
git clone https://github.com/jasonroelofs/rice.git
cd rice
rbenv local truffleruby-jvm-ce
I then tried to build rice:
bundle exec rake test
I am using the system compiler (clang) on a 2020 M1 MacbookPro:
> clang --version
Apple clang version 15.0.0 (clang-1500.0.40.1)
Target: arm64-apple-darwin23.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin