Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question] Can I install JRuby/CRuby specific gem with add_dependency? #1492

Closed
hiroyuki-sato opened this issue Feb 17, 2016 · 4 comments
Closed

Comments

@hiroyuki-sato
Copy link

Hello

Is it possible to write gemspec like the following.

  • On JRuby, install 'jrjackson' gem.
  • On CRuby, install 'oj' gem.

The develop wrote following code, But I got following error on JRuby platform.
It install Oj gem.

https://github.com/sisimai/rb-Sisimai

gemspec file.

  if RUBY_PLATFORM =~ /java/
    spec.add_runtime_dependency 'jrjackson', '>= 0.3.8'
  else
    spec.add_runtime_dependency 'oj', '>= 2.14.4'
  end
gem install sisimai
Building native extensions.  This could take a while...
ERROR:  Error installing sisimai:
    ERROR: Failed to build gem native extension.

    /path/to/home/.rbenv/versions/jruby-9.0.4.0/bin/jruby -r ./siteconf20160216-35142-198flf6.rb extconf.rb
NotImplementedError: C extensions are not supported
    <top> at /path/to/home/.rbenv/versions/jruby-9.0.4.0/lib/ruby/stdlib/mkmf.rb:1
  require at org/jruby/RubyKernel.java:939
   (root) at /path/to/home/.rbenv/versions/jruby-9.0.4.0/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:1
    <top> at extconf.rb:1

extconf failed, exit code 1

Gem files will remain installed in /path/to/home/.rbenv/gems/2.2.0/gems/oj-2.14.4 for inspection.
Results logged to /path/to/home/.rbenv/gems/2.2.0/extensions/universal-java-1.8/2.2.0/oj-2.14.4/gem_make.out

Current workaround, write Gemfile the following.

gem 'oj', '>= 2.14.4', :platform => :ruby
gem 'jrjackson', '>= 0.3.8', :platform => :jruby

It worked but, does not install 'oj' or 'jrjackson' gem.

Gem version is 2.5.2.

Any idea?

@segiddins
Copy link
Member

This is currently a limitation of RubyGems -- if you want platform-specific dependencies, you will have to release platform-specific versions of your own gem

@hiroyuki-sato
Copy link
Author

@segiddins Thanks. I understand.

Please tell me one more thing.
Do you have any idea or example to make two gems in single project?
Like the following

  • project.gemspec generate project.gem
  • project-java.gemspec generate project-java.gem

Thanks.

@copiousfreetime
Copy link
Contributor

@hiroyuki-sato the easiest way, you would have 2 .gemspec files, one for the ruby gem and one for the java gem. Then you would build them gems like:

  • gem build project.gemspec would create project.gem
  • gem build project-java.gemspec would create project-java.gem

The two gemspecs would be virtually identical except in the ruby one would have:

spec.add_dependency('oj', '~> 2.14')

and the jruby one would have

 spec.add_dependency( 'jrjackson', '~> 0.3') 
 spec.platform = "java"

@hiroyuki-sato
Copy link
Author

@chancancode Thank you for your advice. I created two gem files.
I'm using bundler. but bundler don't support multiple gemspec files in same directory.
I'll check gem command for publish gem without bundler .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants