oracle / truffleruby

A high performance implementation of the Ruby programming language, built on GraalVM.
https://www.graalvm.org/ruby/
Other
3.01k stars 184 forks source link

Truffleruby platform mismatch for Gemfile #3505

Closed djberg96 closed 6 months ago

djberg96 commented 6 months ago

truffleruby 24.0.0, like ruby 3.2.2, Oracle GraalVM Native [x86_64-darwin]

I was trying to update the multi_json gem to support java implementations in general (instead of only Jruby), and it defaults to using the 'gson' parser for JRuby. So I tried adding the platform but it fails.

Here's a simple example to demonstrate the issue:

# Gemfile
source 'https://rubygems.org'
gem 'gson', '>= 0.6', platforms: [:jruby, :truffleruby], require: false
gemspec

With JRuby it works. With Truffleruby I get:

Could not find gem 'gson (>= 0.6) jruby, truffleruby' with platforms 'x86_64-darwin-21', 'ruby' in rubygems repository
https://rubygems.org/ or installed locally.

The source contains the following gems matching 'gson (>= 0.6) jruby, truffleruby':
  * gson-0.6.0-java
  * gson-0.6.1-java

I'm thinking it's because JRuby defines RUBY_PLATFORM as "java" whereas Truffleruby is using the local platform, e.g. "x86_64-darwin20", but that's a guess.

andrykonchin commented 6 months ago

Thank you for the report!

eregon commented 6 months ago

The gson gem https://rubygems.org/gems/gson/versions/ https://github.com/avsej/gson.rb?tab=readme-ov-file only has releases with the "java" platform. That platform should really be called the jruby platform, because it means such a gem depends on JRuby-specific APIs, for example https://github.com/avsej/gson.rb/blob/7e2fc18be18da8fede00fac8bbc91e2d1a9fcd03/ext/gson_ext/GsonExtService.java#L20

So it is expected the gson gem cannot be installed on TruffleRuby, just like it cannot be installed on CRuby.

So

gem 'gson', '>= 0.6', platforms: [:jruby], require: false

should be the correct Gemfile line.

eregon commented 6 months ago

IOW, TruffleRuby does not support "java"-platform gems (which use e.g. import org.jruby.Ruby;).

TruffleRuby supports "ruby"-platform gems (which are either pure-Ruby or native extensions, there is no difference in RubyGems if the gem is not precompiled). Many gems with native extensions work on TruffleRuby.

djberg96 commented 6 months ago

@eregon Got it, thanks. I didn't dig into the guts of gson, so didn't realize it was JRuby-specific.