ruru icon indicating copy to clipboard operation
ruru copied to clipboard

Build native extensions as static libraries

Open d-unsed opened this issue 8 years ago • 4 comments

RbConfig::CONFIG provides all the required information for linking with static libraries. But Cargo does not allow to use all the flags, for example -framework CoreFoundation on Mac OS X.

Investigate thermite + RbConfig::CONFIG + gcc as a final (optional) step while building an extension.

This allows to use MRI without --enable-shared option (emk/heroku-buildpack-rust#15)

d-unsed avatar Jan 03 '17 21:01 d-unsed

Ruru is such an awesome project. Getting rid of the need for --enable-shared would get much ❤️ ❤️ ❤️ from me. 😄

seven1m avatar Jan 26 '17 02:01 seven1m

Here's some info that may prove useful. My build complains when I run the bundle exec test suite from VIM about libruby.so.2.4 missing, but if I copy that file into my target/debug/deps folder then everything works. Cargo builds work outside of VIM for me without the lib copied as the RVM environment variables seem to be enough.

Here are the relevant RbConfig variables:

  • RbConfig::CONFIG["libdir"]
  • RbConfig::CONFIG["LIBRUBY_ALIASES"].split(" ").first
require "fileutils"
FileUtils.cp(
  File.join(
    RbConfig::CONFIG["libdir"],
    RbConfig::CONFIG["LIBRUBY_ALIASES"].split(" ").first
  ),
  File.join(FileUtils.pwd, "target/debug/deps")
)

If the build is failing for people otherwise you can do the same copy as above but change it to target release dependencies target/release/deps.

For those who want to use the command line to get the path for the libruby file you can use the following.

ruby -e 'puts File.join(RbConfig::CONFIG["libdir"], RbConfig::CONFIG["LIBRUBY_ALIASES"].split(" ").first)'

danielpclark avatar Sep 11 '17 12:09 danielpclark

@seven1m checkout https://github.com/malept/thermite/pull/41

sbeckeriv avatar Oct 06 '17 18:10 sbeckeriv

Still doesn't work on Windows. I'd need help with that.

malept avatar Oct 06 '17 22:10 malept