Shopify / ruby-lsp

An opinionated language server for Ruby
https://shopify.github.io/ruby-lsp/
MIT License
1.59k stars 156 forks source link

jruby installation broken since 0.17.3 #2292

Open rolandoam opened 4 months ago

rolandoam commented 4 months ago

Description

Reproduction steps

  1. Install the latest jruby (e.g. rbenv install jruby-9.4.8.0)
  2. Try to install the latest ruby-lsp: gem install ruby-lsp
  3. It will fail building the native extension

Code snippet or error message

Building native extensions. This could take a while...
ERROR:  Error installing ruby-lsp:
    ERROR: Failed to build gem native extension.

    current directory: /Users/rolando/.rbenv/versions/jruby-9.4.8.0/lib/ruby/gems/shared/gems/rbs-3.5.2/ext/rbs_extension
/Users/rolando/.rbenv/versions/jruby-9.4.8.0/bin/jruby -I /Users/rolando/.rbenv/versions/jruby-9.4.8.0/lib/ruby/stdlib extconf.rb
checking for whether -std=gnu99 is accepted as CFLAGS... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/rolando/.rbenv/versions/jruby-9.4.8.0/bin/jruby
RuntimeError: The compiler failed to generate an executable file.
You have to install development tools first.

         try_do at /Users/rolando/.rbenv/versions/jruby-9.4.8.0/lib/ruby/stdlib/mkmf.rb:456
    try_compile at /Users/rolando/.rbenv/versions/jruby-9.4.8.0/lib/ruby/stdlib/mkmf.rb:571
    with_werror at /Users/rolando/.rbenv/versions/jruby-9.4.8.0/lib/ruby/stdlib/mkmf.rb:522
    try_compile at /Users/rolando/.rbenv/versions/jruby-9.4.8.0/lib/ruby/stdlib/mkmf.rb:571
     try_cflags at /Users/rolando/.rbenv/versions/jruby-9.4.8.0/lib/ruby/stdlib/mkmf.rb:635
  append_cflags at /Users/rolando/.rbenv/versions/jruby-9.4.8.0/lib/ruby/stdlib/mkmf.rb:641
   checking_for at /Users/rolando/.rbenv/versions/jruby-9.4.8.0/lib/ruby/stdlib/mkmf.rb:942
       postpone at /Users/rolando/.rbenv/versions/jruby-9.4.8.0/lib/ruby/stdlib/mkmf.rb:350
           open at /Users/rolando/.rbenv/versions/jruby-9.4.8.0/lib/ruby/stdlib/mkmf.rb:320
       postpone at /Users/rolando/.rbenv/versions/jruby-9.4.8.0/lib/ruby/stdlib/mkmf.rb:350
           open at /Users/rolando/.rbenv/versions/jruby-9.4.8.0/lib/ruby/stdlib/mkmf.rb:320
       postpone at /Users/rolando/.rbenv/versions/jruby-9.4.8.0/lib/ruby/stdlib/mkmf.rb:346
   checking_for at /Users/rolando/.rbenv/versions/jruby-9.4.8.0/lib/ruby/stdlib/mkmf.rb:941
  append_cflags at /Users/rolando/.rbenv/versions/jruby-9.4.8.0/lib/ruby/stdlib/mkmf.rb:640
           each at org/jruby/RubyArray.java:1981
  append_cflags at /Users/rolando/.rbenv/versions/jruby-9.4.8.0/lib/ruby/stdlib/mkmf.rb:639
         <main> at extconf.rb:3

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/rolando/.rbenv/versions/jruby-9.4.8.0/lib/ruby/gems/shared/extensions/universal-java-22/3.1.0/rbs-3.5.2/mkmf.log

mkmf.log:

" -o conftest -I/include/universal-java22 -I/Users/rolando/.rbenv/versions/jruby-9.4.8.0/lib/ruby/include/ruby/backward -I/Users/rolando/.rbenv/versions/jruby-9.4.8.0/lib/ruby/include -I.  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE     -DTARGET_RT_MAC_CFM=0  -fno-omit-frame-pointer -fno-strict-aliasing  -fexceptions  conftest.c  -L. -L/Users/rolando/.rbenv/versions/jruby-9.4.8.0/lib    -arch arm64      "
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <ruby.h>
4: int main(int argc, char **argv)
5: {
6:   return 0;
7: }
/* end */

Last known version to build seems to be 0.17.2:

gem install ruby-lsp -v 0.17.2
Successfully installed ruby-lsp-0.17.2
Parsing documentation for ruby-lsp-0.17.2
Done installing documentation for ruby-lsp after 2 seconds
1 gem installed
github-actions[bot] commented 2 months ago

This issue is being marked as stale because there was no activity in the last 2 months

mrckzgl commented 2 weeks ago

Same error here. I figured out that -o conftest -I/include/universal-java22 is the command which is executed. But as one can see it does not include an executable, only command line options. Having gcc installed I figured that mkmf gem is (at least in this specific case) relying on the CC env variable to be present. So having export CC=gcc somewhere in a shell initialization script will get you further, but only to:

"gcc -o conftest -I/include/universal-java17 -I~/.rvm/rubies/jruby-9.4.8.0/lib/ruby/include/ruby/backward -I~/.rvm/rubies/jruby-9.4.8.0/lib/ruby/include -I.     -fno-omit-frame-pointer -fno-strict-aliasing  -fexceptions  conftest.c  -L. -L~/.rvm/rubies/jruby-9.4.8.0/lib    -m64      "
In file included from conftest.c:1:
~/.rvm/rubies/jruby-9.4.8.0/lib/ruby/include/ruby.h:1:2: error: #error JRuby does not support native extensions
    1 | #error JRuby does not support native extensions
      |  ^~~~~
In file included from conftest.c:3:
~/.rvm/rubies/jruby-9.4.8.0/lib/ruby/include/ruby.h:1:2: error: #error JRuby does not support native extensions
    1 | #error JRuby does not support native extensions
      |  ^~~~~
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <ruby.h>
4: int main(int argc, char **argv)
5: {
6:   return 0;
7: }
/* end */

So did ruby-lsp switch from not using a native extension to using one?

vinistock commented 2 weeks ago

We added a dependency on rbs otherwise there's no way to index core declarations from the language (e.g.: String, Integer and so on).

Unfortunately, rbs doesn't support JRuby yet (which we didn't realize when we introduced it). And Rubygems doesn't support conditional/optional runtime dependencies, so we have no way of saying that we can only depend on rbs for the mri platform.

To fix this, we are going to need to ensure that rbs can work with JRuby.

headius commented 2 weeks ago

A short term option would be a -java platform gem that removes the rbs dependency, but we also want to get rbs support for JRuby.