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

Support for shared built Rubies #43

Closed
kddnewton opened this issue Mar 28, 2020 · 10 comments
Closed

Support for shared built Rubies #43

kddnewton opened this issue Mar 28, 2020 · 10 comments
Assignees

Comments

@kddnewton
Copy link

In order to support embedding Ruby inside other C projects.

@MSP-Greg
Copy link
Collaborator

Any platforms in particular?

@kddnewton
Copy link
Author

Any and all really! Trying to support as many as I can, but at the moment if it's not shared it really be embedded.

@MSP-Greg
Copy link
Collaborator

I know of a commercial application that is using Window MinGW builds embedded, and I've hacked it to use an mswin build. Both work fine.

@kddnewton
Copy link
Author

So it works if it's got --enable-shared as part of the config, but when it's not I run into this: https://github.com/prettier/plugin-ruby/pull/512/checks?check_run_id=539737773#step:9:68. Copied from there:

/usr/bin/ld: /home/runner/.rubies/ruby-2.6.5/lib/libruby-static.a(array.o): relocation R_X86_64_PC32 against symbol `rb_cFalseClass' can not be used when making a shared object; recompile with -fPIC

@eregon
Copy link
Member

eregon commented Mar 29, 2020

OK, I'll try to use --enable-shared for Rubies built by ruby-builder and ruby-dev-builder (Ubuntu and macOS).
I'll start with ruby-dev-builder, so we can verify it fixes your use-case and limit the risks.

eregon added a commit to ruby/ruby-dev-builder that referenced this issue Mar 29, 2020
@eregon eregon self-assigned this Mar 29, 2020
@eregon
Copy link
Member

eregon commented Mar 29, 2020

ruby-head is now built with --enable-shared: https://github.com/ruby/ruby-dev-builder/releases

@kddeisz Could you try ruby-head in your PR/CI and see if that works?

@kddnewton
Copy link
Author

Interesting - I've got a new error now: https://github.com/prettier/plugin-ruby/pull/512/checks?check_run_id=543575032#step:11:14. Error: libruby.so.2.8: cannot open shared object file: No such file or directory

@eregon
Copy link
Member

eregon commented Mar 29, 2020

I assume you're trying to require or process.dlopen() the node extension you built, and that links to libruby? Probably it doesn't find libruby.so.2.8 at runtime (because it only looks in /usr/lib, /usr/local/lib, etc).
You should be able to see if this is the issue with ldd path/to/extension.so which would show libruby.so.2.8 is unresolved.

To fix that I think you need to pass -rpath #{RbConfig::CONFIG['libdir']} in LDFLAGS when building the extension.

eregon added a commit to ruby/ruby-builder that referenced this issue Mar 30, 2020
@eregon
Copy link
Member

eregon commented Mar 31, 2020

As of https://github.com/ruby/setup-ruby/releases/tag/v1.28.0 all Ruby builds use --enable-shared.
On Windows I believe this was already the case.

@eregon eregon closed this as completed Mar 31, 2020
@kddnewton
Copy link
Author

Thanks for this! It's compiling on everything now.

I still can't get it to actually find the .so file, but I'll keep trying configuration combinations.

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

No branches or pull requests

3 participants