d-unsed / ruru

Native Ruby extensions written in Rust
MIT License
831 stars 40 forks source link

Build native extensions as static libraries #50

Open d-unsed opened 7 years ago

d-unsed commented 7 years ago

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)

seven1m commented 7 years ago

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

danielpclark commented 6 years ago

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:

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)'
sbeckeriv commented 6 years ago

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

malept commented 6 years ago

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