Skip to content

Install JDK 21 for JRuby 10 #22

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

Merged
merged 4 commits into from
Apr 18, 2025
Merged

Install JDK 21 for JRuby 10 #22

merged 4 commits into from
Apr 18, 2025

Conversation

ntkme
Copy link
Contributor

@ntkme ntkme commented Apr 15, 2025

This PR fixes the broken builds of jruby-10.0.0.0 due to inconsistent default JDK version on different runners.

@eregon
Copy link
Member

eregon commented Apr 17, 2025

It would be safest to use the same logic as in setup-ruby, i.e. reuse the JDKs already in the image, to ensure to not embed something from the downloaded JDK which won't be available once used in setup-ruby.

For instance the new JRuby startup optimization creates a file which is likely JDK-specific (not sure where though) which could be a problem if we end up with different JDKs at build and run time.

@ntkme
Copy link
Contributor Author

ntkme commented Apr 17, 2025

setup-java is actually what jruby-dev-builder uses currently.

@headius Any thoughts?

@eregon
Copy link
Member

eregon commented Apr 17, 2025

Right, since ruby/jruby-dev-builder@a4cdaa6 (which should have been a PR BTW).
It'd be good to be consistent between the two.

@headius is it safe to use different JDKs, potentially with the same version but different vendors at JRuby build time (e.g. used to install jruby-launcher) and run time? Where is the JRuby startup AppCDS stuff stored?

@headius
Copy link

headius commented Apr 17, 2025

@eregon Using any vendor JDK at either build time or runtime is fine. We generate the AppCDS archive on startup using the specific version in the runtime JDK.

@headius
Copy link

headius commented Apr 17, 2025

@ntkme If a specific version of Java is needed it is fine to use setup-java first. The setup-ruby logic detects if JAVA_HOME is not 21+ and only switches if that is the case.

@ntkme
Copy link
Contributor Author

ntkme commented Apr 17, 2025

@headius Also, do you have preference on JDK distribution? E.g. temurin vs zulu etc. I just noticed it is zulu in your change. I can update this PR to zulu if that is preferred.

@eregon
Copy link
Member

eregon commented Apr 18, 2025

Mmh, because it's a pain to rebuild releases I would like to be 100% safe here and also not have to choose which vendors but be consistent with what will be used at run time.

@ntkme Could you use a simplified version of the logic from setup-ruby, i.e. use JAVA_HOME_21_X64 or JAVA_HOME_21_arm64 (only for darwin-arm64, on linux-aarch64 the variable is still named _X64, see actions/runner-images#9266 (reply in thread))?
This should be one or a few lines of Bash so very simple, i.e. use JAVA_HOME_21_X64 if available otherwise use JAVA_HOME_21_arm64

@ntkme
Copy link
Contributor Author

ntkme commented Apr 18, 2025

@eregon My take is that in setup-ruby we do that for the convenience of end users, but for this internal build pipeline we should aim for better reliability, as it is not directly consumed by end users. The benefit of using setup-java is that it's independent from the specific runner environment, so it won't matter if GitHub decides to change how those convoluted variables work in the future.

By the way I explicitly use setup-java in my tests, so the logic of "same as runtime" does not apply for users like me: https://github.com/sass-contrib/sass-embedded-host-ruby/blob/f5d04333169fb04a8ca831084fc2b3020653c516/.github/workflows/build.yml#L159-L164

@eregon
Copy link
Member

eregon commented Apr 18, 2025

I was curious if setup-java uses the same JDK/path as the env vars but it seems not the case (unless there are some symlinks?):
https://github.com/sass-contrib/sass-embedded-host-ruby/actions/runs/14452594290/job/40530347945#step:6:23
vs
ruby/setup-ruby#721 (comment)

Although they are both temurin 21, but unsure if same exact version.

By the way I explicitly use setup-java in my tests, so the logic of "same as runtime" does not apply for users like me:

Mmh, indeed if people use setup-java for other purposes than JRuby it should still work. And if it doesn't it would be a JRuby bug.
Though I am not going to test that case or explicitly support it.

OTOH, it's JRuby's problem they don't ship a working Ruby implementation without installing/setting up a JDK21.
If there is any problem I do not want to get involved at all.
In fact I'm already annoyed to have to deal with this when CRuby and TruffleRuby just work (even more so during my holidays).

so it won't matter if GitHub decides to change how those convoluted variables work in the future.

If that happens (unlikely as it's an obvious breaking change and GitHub is well aware of it, see linked issue), it would be a problem for setup-ruby, so there is no value that it works here but not in setup-ruby.

I believe what is most important here is that we test with the exact same JDK here and in setup-ruby (we run very similar tests in both places, to ensure as much as possible that if it works here it also works in setup-ruby).
So for those reasons, please implement my suggestion above.

@ntkme
Copy link
Contributor Author

ntkme commented Apr 18, 2025

@eregon Done

Copy link
Member

@eregon eregon left a comment

Choose a reason for hiding this comment

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

Thanks!

@eregon eregon merged commit 79e6e92 into ruby:master Apr 18, 2025
@eregon
Copy link
Member

eregon commented Apr 18, 2025

https://github.com/ruby/ruby-builder/actions/runs/14529258375/job/40766251486#step:20:18 it looks like PATH needs to be set too, or probably better the check in ruby-build should be fixed to use JAVA_HOME if set and not always java from PATH (I guess, haven't checked the code there). Or that check could be removed.

Perfect example of additional annoying complications for JRuby leaking to many places

@ntkme
Copy link
Contributor Author

ntkme commented Apr 18, 2025

@eregon I think that check is done by ruby-build command, actually jruby itself does not require PATH to be set: https://github.com/jruby/jruby/blob/0a14a31bf54092b741a3805a8f8de151c5a69c0d/bin/jruby.sh#L458

@headius
Copy link

headius commented Apr 18, 2025

@ntkme My original suggestion was to reuse setup-java for setup-ruby with JRuby, but @eregon did not like that idea.

The vendor of JDK is not really important... they are not that different from each other. Temurin or zulu or corretto... all are fine and JRuby will work with all of them.

@eregon JRuby does not force users to run with a specific JVM version or vendor, and our users run on many different builds of OpenJDK on many different platforms. This is a key feature of JRuby, since as a normal JVM language, we can run anywhere Java runs. Sometimes it makes setup and deployment take a few more steps, but it is no different than requiring specific native libraries for CRuby and TruffleRuby (like openssl). Neither CRuby nor TruffleRuby "just work" if those libraries are not preinstalled.

If you do not want to continue to maintain setup-ruby for JRuby, then give me commit rights and I will do it as part of our release process.

@headius
Copy link

headius commented Apr 18, 2025

@ntkme @eregon Please let me know if I can help with any remaining issues. I am at RubyKaigi so I may not be able to respond quickly.

@eregon
Copy link
Member

eregon commented Apr 18, 2025

@eregon I think that check is done by ruby-build command, actually jruby itself does not require PATH to be set: https://github.com/jruby/jruby/blob/0a14a31bf54092b741a3805a8f8de151c5a69c0d/bin/jruby.sh#L458

Right, as I guessed, thanks for checking and good that JRuby itself doesn't require that $JAVA_HOME/bin to be in PATH.

Could one of you make a PR to ruby-build to fix the check?

@ntkme
Copy link
Contributor Author

ntkme commented Apr 18, 2025

rbenv/ruby-build#2523

@headius
Copy link

headius commented Apr 18, 2025

@ntkme Thank you!

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.

3 participants