danielpclark / rutie

“The Tie Between Ruby and Rust.”
MIT License
959 stars 61 forks source link

Semi-fixes static linking for Mac OS #58

Closed felix-d closed 5 years ago

felix-d commented 5 years ago

Fixes https://github.com/danielpclark/rutie/issues/57

danielpclark commented 5 years ago

Currently static linking is tested on Travis CI under allowed failures. After your updates it is still failing for Windows, Mac, and Linux. See builds here: https://travis-ci.org/danielpclark/rutie/builds/465793188

And the Mac static build specifically: https://travis-ci.org/danielpclark/rutie/jobs/465793208

felix-d commented 5 years ago

Oh interesting! Those tests actually pass on my machine. I can try to investigate a bit more what's going on.

Also, oddly enough, it does not find libruby.2.5.3-static.a in the Mac OS test suite.. Maybe it's because of the way Ruby is installed. It's strange because the ruby config does point to libruby.2.5.3-static.a.

This might be due to

#[cfg(not(target_os = "windows"))]
fn rvm_libruby_static_path() -> Option<String> {
    let pth = rvm_path();
    if pth.is_none() { return None; }

    let path = format!("{}/src/ruby-{}", pth.unwrap(), rbconfig("RUBY_PROGRAM_VERSION"));

    if !Path::new(&path).exists() { return None; }
    if !Path::new(&path).join("libruby-static.a").exists() { return None; }

    Some(path)
}
felix-d commented 5 years ago

Last change didn't seem to work for rvm. I'll investigate more closely what's going on.

felix-d commented 5 years ago

Now for a reason I ignore, those 3 tests started failing on my machine as well. That's good news, it'll be easier to fix, although I'm super confused as why it started failing.

failures:

---- src/class/string.rs - class::string::RString::is_valid_encoding (line 530) stdout ----
thread 'src/class/string.rs - class::string::RString::is_valid_encoding (line 530)' panicked at 'test executable failed:

dyld: lazy symbol binding failed: Symbol not found: _rb_encdb_declare
  Referenced from: /opt/rubies/ruby-2.5.3/lib/ruby/2.5.0/x86_64-darwin18/enc/encdb.bundle
  Expected in: flat namespace

dyld: Symbol not found: _rb_encdb_declare
  Referenced from: /opt/rubies/ruby-2.5.3/lib/ruby/2.5.0/x86_64-darwin18/enc/encdb.bundle
  Expected in: flat namespace

', librustdoc/test.rs:367:17
note: Run with `RUST_BACKTRACE=1` for a backtrace.

---- src/class/string.rs - class::string::RString::from_bytes (line 110) stdout ----
thread 'src/class/string.rs - class::string::RString::from_bytes (line 110)' panicked at 'test executable failed:

dyld: lazy symbol binding failed: Symbol not found: _rb_encdb_declare
  Referenced from: /opt/rubies/ruby-2.5.3/lib/ruby/2.5.0/x86_64-darwin18/enc/encdb.bundle
  Expected in: flat namespace

dyld: Symbol not found: _rb_encdb_declare
  Referenced from: /opt/rubies/ruby-2.5.3/lib/ruby/2.5.0/x86_64-darwin18/enc/encdb.bundle
  Expected in: flat namespace

', librustdoc/test.rs:367:17

---- src/class/vm.rs - class::vm::VM::init_loadpath (line 53) stdout ----
thread 'src/class/vm.rs - class::vm::VM::init_loadpath (line 53)' panicked at 'test executable failed:

dyld: lazy symbol binding failed: Symbol not found: _rb_encdb_declare
  Referenced from: /opt/rubies/ruby-2.5.3/lib/ruby/2.5.0/x86_64-darwin18/enc/encdb.bundle
  Expected in: flat namespace

dyld: Symbol not found: _rb_encdb_declare
  Referenced from: /opt/rubies/ruby-2.5.3/lib/ruby/2.5.0/x86_64-darwin18/enc/encdb.bundle
  Expected in: flat namespace

', librustdoc/test.rs:367:17

failures:
    src/class/string.rs - class::string::RString::from_bytes (line 110)
    src/class/string.rs - class::string::RString::is_valid_encoding (line 530)
    src/class/vm.rs - class::vm::VM::init_loadpath (line 53)

test result: FAILED. 181 passed; 3 failed; 3 ignored; 0 measured; 0 filtered out
felix-d commented 5 years ago

I'm currently just playing around with the code and Travis, I'll ping you again once I have a final PR. Basically I found out that Travis was never installing the static lib, only the dynamic one, so I'm trying to do a proper static installation using rvm. I don’t think this will fix the 3 tests failing, but at least it’s a step in the right direction

felix-d commented 5 years ago

@danielpclark alright, after a few tries, I managed to properly install the static library with rvm, compile it and link it in the tests.

I believe the previous build was probably linking the wrong lib as the build script was not doing the right thing to install the static version.

There is still the same 3 tests failing. However, as you can see, the test failure output is now different. You now have information on why it's failing:

---- src/class/string.rs - class::string::RString::from_bytes (line 110) stdout ----
thread 'src/class/string.rs - class::string::RString::from_bytes (line 110)' panicked at 'test executable failed:
/tmp/rustdoctestpXiTXC/rust_out: symbol lookup error: /home/travis/.rvm/rubies/ruby-2.5.3/lib/ruby/2.5.0/x86_64-linux/enc/encdb.so: undefined symbol: rb_encdb_declare

Now this reproduces the behaviour on my machine.

I believe this is ready to merge as a step in the right direction. Let me know if anything!

felix-d commented 5 years ago

@danielpclark rebased with the changes

danielpclark commented 5 years ago

Thank you for putting in the work! :grin:

felix-d commented 5 years ago

@danielpclark any time!