Forum: JRuby Gem Platform Issues

486ca04f06d968004643ce5b47376ded?d=identicon&s=25 Keith B. (keith_b)
on 2014-02-06 22:36
(Received via mailing list)
All -

I wrote a gem that calls a Java library using RVM if running under MRI
Ruby, and just calls the Java library in the same (J)Ruby VM when
running
in JRuby.

I've built the gem in JRuby, installed it, and required it in (a JRuby)
irb, successfully.

However, I have another gem that is dependent on it, and I can't get it
not
to try to build rjb.

I have a feeling it has something to do with the gemspec, but I'm not
sure.  Assuming my gem's name is 'cv' (it's not), here's what I think is
the relevant code in the gemspec:

  is_jruby = /java/ === RUBY_PLATFORM
  spec.platform = 'java' if is_jruby

  if is_jruby
    spec.add_dependency "cv", ">= 0.3.1"
  else
    spec.add_dependency "cv", ">= 0.1.0"
    spec.add_dependency "yajl-ruby"  # For JSON parsing
  end


Any idea what I might be doing wrong?  The error message I get when
running
bundler is below.

Thanks,
Keith



/Users/kbennett/.rvm/rubies/jruby-1.7.10/bin/jruby extconf.rb
/Users/kbennett/.rvm/rubies/jruby-1.7.10/lib/ruby/shared/mkmf.rb:14: Use
RbConfig instead of obsolete and deprecated Config.
mkmf.rb can't find header files for ruby at
/Users/kbennett/.rvm/rubies/jruby-1.7.10/lib/native/include/ruby/ruby.h

extconf failed, uncaught signal 1

Gem files will remain installed in
/Users/kbennett/.rvm/gems/jruby-1.7.10/gems/rjb-1.4.9 for inspection.
Results logged to
/Users/kbennett/.rvm/gems/jruby-1.7.10/extensions/universal-java-1.7/1.9/rjb-1.4.9/gem_make.out
An error occurred while installing rjb (1.4.9), and Bundler cannot
continue.
Make sure that `gem install rjb -v '1.4.9'` succeeds before bundling.
B05d3cbc64b0031a24c2887fb6ddc173?d=identicon&s=25 christian (Guest)
on 2014-02-07 12:22
(Received via mailing list)
On Thu, Feb 6, 2014 at 9:35 PM, Keith Bennett
<keithrbennett@gmail.com>wrote:

> spec.add_dependency "cv", ">= 0.3.1"
>   else
>     spec.add_dependency "cv", ">= 0.1.0"
>


both statements will use the latest cv gem, at least on clean local gem
repo.

are there two cv one for MRI and one for java, i.e. how does the
cv.gemspec
look like ?

the install of gem should honor the current platform and install the
respective platform gem if available.

- christian
2c0c4cf3ccc8da22f7c3b9586ce1cd70?d=identicon&s=25 Christian MICHON (Guest)
on 2014-02-07 12:49
(Received via mailing list)
Road to hell... Why don't you generate 2 versions? 1 MRI specific and 1
for
java platform.

If you've tests in your gems, you'll need also to handle RUBY_PLATFORM
and
run the tests for each platform, switching environments in your shell.
If
you use RVM, you might even confuse this more...

If you've 2 versions (one for each platform), you need to test on each
platform only what is specific.
486ca04f06d968004643ce5b47376ded?d=identicon&s=25 Keith B. (keith_b)
on 2014-02-07 17:58
(Received via mailing list)
Christian -

Thanks for responding.  The cv.gemspec includes:

  is_jruby = /java/ === RUBY_PLATFORM
  if is_jruby
    spec.platform = 'java'
  end
...
  unless is_jruby
    spec.add_dependency 'rjb'
    spec.add_development_dependency "pry-debugger"
  end

When I build the gem, the Java version is named cv-0.4.3-java.gem. (The
"-java" is appended automatically.)

In my other gemspec, do I have to explicitly specify that I want a Java
version of the gem, or should it automatically find it if spec.platform
==
'java'?

There are 2 separate versions of the gem created -- is that what you
meant
in your second message?

Thanks,
Keith
486ca04f06d968004643ce5b47376ded?d=identicon&s=25 Keith B. (keith_b)
on 2014-02-07 20:39
(Received via mailing list)
Never mind, it appears to work now.

Thanks for your help, Christian.

- Keith
2c0c4cf3ccc8da22f7c3b9586ce1cd70?d=identicon&s=25 Christian MICHON (Guest)
on 2014-02-07 22:27
(Received via mailing list)
The 2nd message is from me. 2 Christians replied.

Glad that the solution worked. And yes I meant for 2 versions of the gem
to
be created, instead of a generic.
B05d3cbc64b0031a24c2887fb6ddc173?d=identicon&s=25 christian (Guest)
on 2014-02-07 23:04
(Received via mailing list)
Christian is a very common name in my country
:)






On Fri, Feb 7, 2014 at 9:24 PM, Christian MICHON
<christian.michon@gmail.com
486ca04f06d968004643ce5b47376ded?d=identicon&s=25 Keith B. (keith_b)
on 2014-02-08 19:20
(Received via mailing list)
Oh!  Sorry, yes, I thought you were the same guy.

Anyway, thanks to both of you! ;)

- Keith
This topic is locked and can not be replied to.