Skip to content

Conversation

@hsbt
Copy link
Member

@hsbt hsbt commented Feb 19, 2025

What was the end-user or developer problem that led to this PR?

I'm working to provide shared GEM_HOME for all of Ruby versions and platforms.

If I used CRuby and jruby-launcher gem with that environment, RubyGems warns the following:

Source locally installed gems is ignoring #<Bundler::StubSpecification name=jruby-launcher version=1.1.19 platform=java> because it is missing extensions

In another case, I use JRuby and run gem -v. RubyGems warns all of C extension gem:

Ignoring RedCloth-4.3.4 because its extensions are not built. Try: gem pristine RedCloth --version 4.3.4
Ignoring RedCloth-4.3.3 because its extensions are not built. Try: gem pristine RedCloth --version 4.3.3
Ignoring RedCloth-4.3.2 because its extensions are not built. Try: gem pristine RedCloth --version 4.3.2
Ignoring aliyun-sdk-0.8.0 because its extensions are not built. Try: gem pristine aliyun-sdk --version 0.8.0
Ignoring amatch-0.4.1 because its extensions are not built. Try: gem pristine amatch --version 0.4.1
...

What is your fix for the problem, implemented in this PR?

I skip to warn with these cases.

TODO

write test code and consider to another cases.

Make sure the following tasks are checked

@deivid-rodriguez
Copy link
Contributor

This sounds like #3520. A plan for making this work was sketched at #7372, just never implemented.

@hsbt hsbt force-pushed the ignore-spec-different-platfroms branch 4 times, most recently from c316ba9 to c5b7fb4 Compare February 20, 2025 07:33
@hsbt hsbt marked this pull request as ready for review February 20, 2025 08:16
@hsbt
Copy link
Member Author

hsbt commented Feb 20, 2025

/cc @headius

@deivid-rodriguez
Copy link
Contributor

For what it's worth, I don't think this is the right fix because it will hide all instances of this warning in JRuby, not just the ones that are actually false positives. I'd prefer that we work on a proper solution.

@hsbt
Copy link
Member Author

hsbt commented Feb 20, 2025

I don't imagine missing_extension? is true with JRuby platform. Do you have example for that?

@deivid-rodriguez
Copy link
Contributor

If a extension builds specific artifacts only under JRuby, but does not build those artifacts when installed under a different implementation, then if you switch to JRuby, you can't use the installation as is, but the artifacts will need to be built for JRuby, right?

For example, will jruby-launcher extension work on JRuby if installed under non-jruby?

warn "Source #{source} is ignoring #{self} because it is missing extensions"
# If we share GEM_HOME for all of Ruby platform, the platform specific gem always warn that specification.
# ex `jruby-launcher` and CRuby
if platform == Gem::Platform::RUBY && RUBY_ENGINE != "jruby"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this only limited to jruby?

@headius
Copy link
Contributor

headius commented Apr 9, 2025

Sorry I missed this for a while. Answers to some questions:

I don't think this is the right fix because it will hide all instances of this warning in JRuby

In general, extensions built for one configuration of JRuby (JRuby version plus Java version) will work on any other configuration. We do not expose a version-specific C API, so there's nothing to recompile, and Java-based extensions are shipped in a pre-built form. Unless an extension is using Java version-specific APIs (I don't know of any that do this), we do not need separate builds for each configuration.

For example, will jruby-launcher extension work on JRuby if installed under non-jruby?

jruby-launcher is a "-java" platform gem, so I don't expect CRuby users will ever install it. But even if they did, it just builds a plain C-based executable that has no dependencies on a specific JRuby or JVM version.

Why is this only limited to jruby?

Basically, this extension warning makes no sense for JRuby, because:

  • Gems that contain Java extensions should ship them pre-compiled. Changing JRuby or Java version should have no effect on these.
  • Gems that actually build something when installed in JRuby don't depend on any version-specific API like they do in CRuby. Usually, they produce a standalone dll or executable that will work across JRuby+Java configurations.
  • Gems that generate a stub makefile (and build nothing) obviously don't need this check at all.

Basically, gems with native code installed on JRuby should work on just about any supported configuration of JRuby + Java. The warning is (almost always?) useless for us.

I got sick of seeing these warnings again today and was about to monkey-patch RubyGems to stop producing this warning, but this PR would probably be a better option.

(Edit: "exceptions" => "extensions")

@headius
Copy link
Contributor

headius commented Apr 9, 2025

The jruby-launcher gem actually exposes another problem with this warning: it does not actually create an extension for the missing_extension? check to find. Instead, it just builds an executable that it installs in $JRUBY_HOME/bin/jruby:

[] tmp $ gem install jruby-launcher
Fetching jruby-launcher-2.0.0-java.gem
Building native extensions. This could take a while...
Successfully installed jruby-launcher-2.0.0-java
Parsing documentation for jruby-launcher-2.0.0-java
Installing ri documentation for jruby-launcher-2.0.0-java
Done installing documentation for jruby-launcher after 1 seconds
1 gem installed
[] tmp $ bundle                    
Source locally installed gems is ignoring #<Bundler::StubSpecification name=jruby-launcher version=2.0.0.pre2 platform=java> because it is missing extensions
Bundle complete! 1 Gemfile dependency, 2 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

So there's basically no way to avoid this warning when using bundler and the jruby-launcher gem.

@headius
Copy link
Contributor

headius commented Apr 9, 2025

So there's basically no way to avoid this warning when using bundler and the jruby-launcher gem.

Oops, I did not notice it was complaining about the "2.0.0.pre2" version of the jruby-launcher gem, so that was a red herring. But it is still a problem when switching Java versions, even though the installed executable works just fine:

[] tmp $ jruby -v                  
jruby 10.0.0.0-SNAPSHOT (3.4.2) 2025-04-09 e2909f9baf OpenJDK 64-Bit Server VM 21.0.5+11-LTS on 21.0.5+11-LTS +indy +jit [arm64-darwin]
[] tmp $ gem install jruby-launcher
Building native extensions. This could take a while...
Successfully installed jruby-launcher-2.0.0-java
Parsing documentation for jruby-launcher-2.0.0-java
Done installing documentation for jruby-launcher after 0 seconds
1 gem installed
[] tmp $ bundle   
Bundle complete! 1 Gemfile dependency, 2 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
[] tmp $ pickjdk 24
/Library/Java/JavaVirtualMachines/jdk-24.jdk/Contents/Home
[] tmp $ bundle
Fetching gem metadata from https://rubygems.org/.
Source rubygems repository https://rubygems.org/ or installed locally is ignoring #<Bundler::StubSpecification name=resolv version=0.6.0 platform=ruby> because it is missing extensions
Source rubygems repository https://rubygems.org/ or installed locally is ignoring #<Bundler::StubSpecification name=jruby-launcher version=2.0.0 platform=java> because it is missing extensions
Source rubygems repository https://rubygems.org/ or installed locally is ignoring #<Bundler::StubSpecification name=bindex version=0.8.1 platform=ruby> because it is missing extensions
Resolving dependencies...
Installing resolv 0.6.0 with native extensions
Bundle complete! 1 Gemfile dependency, 2 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

The main problem is when switching Java version, since that version gets baked into the extension dir and used for the missing check.

@hsbt hsbt force-pushed the ignore-spec-different-platfroms branch 4 times, most recently from 743b51b to ea0266e Compare June 12, 2025 08:59
@hsbt hsbt force-pushed the ignore-spec-different-platfroms branch from ea0266e to 8cca385 Compare June 27, 2025 04:51
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

Successfully merging this pull request may close these issues.

4 participants