oxidize-rb / rb-sys

Easily build Ruby native extensions in Rust
https://oxidize-rb.github.io/rb-sys/
Apache License 2.0
218 stars 34 forks source link

CargoBuilder JRuby support #285

Open uvlad7 opened 8 months ago

uvlad7 commented 8 months ago

rb_sys/mkmf can be used to compile not only rb_sys-based gems, but any gem that contains Rust code. I've found it useful to compile rust code used in JRuby through JNI, but it can also be used to compile Rust libraries called through FFI in both MRI and JRuby. However, I needed to make a small patch to make it compile on JRuby. So, the question is: would you accept a PR with these changes? It actually can require more patches as I only tested them on Ubuntu, dynamically linked Ruby 3.2.

ianks commented 8 months ago

I’m not opposed to the idea, the patch is hard to review though. If you can make a prototype PR with the code that would be great! If that looks solid, we can polish it up to ship.

uvlad7 commented 8 months ago

I need your help, I updated oxi-test gem to work with jruby for rb-sys CI tests, but env preparation fails and I don't understand why.

UPD: Just cargo-binstall action doesn't work on jruby

I tried to debug:

    File.write 'tmp1', response.body.bytes.inspect
    File.write 'tmp2', pipe_command("#{RbConfig.ruby} -e 'puts STDIN.read.bytes.inspect'", stdin: response.body)

and appears it can't handle long stdins:

3.0.2 :002 > arr1 = eval(File.read 'tmp1'); nil
 => nil 
3.0.2 :003 > arr2 = eval(File.read 'tmp2'); nil
3.0.2 :006 > arr1.size
 => 6290974 
3.0.2 :007 > arr2.size
 => 98304
3.0.2 :010 > arr1[0...arr2.size] == arr2
 => true 

And this problem reproduces only from time to time

uvlad7 commented 8 months ago

So, it works on ubuntu and macos, but I'm not able to make it work on windows

Here is a Makefile generated on Jruby, and here - on MRI. The first one fails. @ianks, can you take a look? I don't have Win installed, so it's painful to debug.