danielpclark / rutie

“The Tie Between Ruby and Rust.”
MIT License
940 stars 62 forks source link

[WIP] static linking #111

Closed michael-groble closed 4 years ago

michael-groble commented 4 years ago

this is an exploration that makes the problem class::vm::VM::init_loadpath test from #45 pass.

It does this by explicitly calling the methods that are being reported as "lazy symbol binding failed" until there are no such errors remaining.

There are two potential problems with this.

  1. I'm trying to do the minimum to make these work, but they lead to warnings such as
    stderr:
    ruby: warning: already initialized constant Encoding::ASCII_8BIT
    /Users/mike/.rbenv/versions/2.6.3/lib/ruby/2.6.0/x86_64-darwin18/enc/encdb.bundle: warning: already initialized constant Encoding::ASCII_8BIT
  2. init_loadpath passes, but the string tests now fail in a worse way:

    /Users/mike/.rbenv/versions/2.6.3/lib/ruby/2.6.0/x86_64-darwin18/enc/utf_32be.bundle: [BUG] vm_call_cfunc: cfp consistency error (0x000000010cdabf90, 0x000000010cdabf58)
    ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]
    
    -- Crash Report log information --------------------------------------------
      See Crash Report log file under the one of following:
        * ~/Library/Logs/DiagnosticReports
        * /Library/Logs/DiagnosticReports
      for more details.
    Don't forget to include the above Crash Report log file in bug reports.
    
    -- Control frame information -----------------------------------------------
    c:0004 p:-17529622890518 s:0014 e:000013 TOP    [FINISH]
    c:0003 p:---- s:0011 e:000010 CFUNC  :force_encoding
    c:0002 p:0007 s:0006 e:000005 EVAL   eval:1 [FINISH]
    c:0001 p:0000 s:0003 E:001360 (none) [FINISH]

I see that the build is failing on travis: error: could not find native static library 'ruby.2.6-static', perhaps an -L flag is missing?. To build locally, I did the following:

RUSTFLAGS="-L /Users/mike/.rbenv/versions/2.6.3/lib" RUBY_STATIC=true BUILD_RUBY_VERSION=2.6.3 cargo test -vv
danielpclark commented 4 years ago

This is exciting work! Thanks for sharing what you have this far. :smiley:

michael-groble commented 4 years ago

closing this for now. I can't figure out why I can make things work on mac and not linux.

In both cases, the rb_encdb_declare function is defined in the static ruby library and is an undefined symbol in the enc/encdb module (lib/ruby/2.6.0/x86_64-darwin18/enc/encdb.bundle on mac and lib/ruby/2.6.0/x86_64-linux/enc/encdb.so on linux).

On the mac, explicitly calling them in force_loading was enough to get them to pass. While in linux, I get that they are undefined (from the module):

stderr:
/tmp/rustdoctestyTvq1l/rust_out: symbol lookup error: /usr/local/lib/ruby/2.6.0/x86_64-linux/enc/encdb.so: undefined symbol: rb_encdb_declare