Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't find RUBY_DESCRIPTION when using a native gem from rust #143

Open
pwoolcoc opened this issue Apr 12, 2021 · 1 comment
Open

Can't find RUBY_DESCRIPTION when using a native gem from rust #143

pwoolcoc opened this issue Apr 12, 2021 · 1 comment

Comments

@pwoolcoc
Copy link

When trying to use ruby inside a rust application, I'm having some issues with requiring gems with C extensions, in this case Nokogiri. When I VM::require("nokogiri"), I get an error from the VM: #<NameError: uninitialized constant RUBY_DESCRIPTION>.

To reproduce:

# Gemfile

# ...

gem "nokogiri"
// src/main.rs

use rutie::{VM, Object, NilClass};

fn main() {
    VM::init();
    VM::init_loadpath();
    VM::require("rubygems"); 

    if let Err(e) = VM::protect(|| {
        VM::require("nokogiri");
        NilClass::new().into()
    }) {
        let output = VM::error_info().unwrap();
        eprintln!("{}", output);
    }
}

I run the program with:

$ RUBYLIB=$(bundle exec ruby -e 'puts $LOAD_PATH' | tr '\n' ':') DYLD_LIBRARY_PATH=$(bundle exec ruby -e "puts RbConfig::CONFIG['libdir']") cargo run
@danielpclark
Copy link
Owner

@pwoolcoc You might need to initialize it first:

https://github.com/ruby/ruby/blob/d92f09a5eea009fa28cd046e9d0eb698e3d94c5c/version.c#L100

which provides

void
Init_ruby_description(void)
{
    VALUE description;

    if (MJIT_OPTS_ON) {
        description = MKSTR(description_with_jit);
    }
    else {
        description = MKSTR(description);
    }

    /*
     * The full ruby version string, like <tt>ruby -v</tt> prints
     */
    rb_define_global_const("RUBY_DESCRIPTION", /* MKSTR(description) */ description);
}

On many of these kinds of errors you can simply search the Ruby source code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants