Skip to content

Replace Unix launcher with simple wrapper that executes jruby.sh #48

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 3, 2025

Conversation

mrnoname1000
Copy link
Contributor

@mrnoname1000 mrnoname1000 commented Mar 31, 2025

This assumes jruby is located in $JRUBY_HOME, and if it is, it exec's jruby.sh. This is mainly to support shebangs with jruby as the target on non-Linux systems.

Fixes #47, but only on Unix.

@headius
Copy link
Member

headius commented Mar 31, 2025

I pushed to master a CI fix you can rebase.

@headius
Copy link
Member

headius commented Mar 31, 2025

I tested this out by pulling your branch and making a gem from it:

  1. update version in lib/jruby-launcher.rb
  2. run rake update_version to update the version in the header file
  3. run rake package to build the gem

The following sequence demonstrates the new launcher working properly, and supporting flags the original does not like --cache:

# running with shell script
[] jruby $ jruby -v
jruby 10.0.0.0-SNAPSHOT (3.4.2) 2025-03-31 b7ee3bb4ae OpenJDK 64-Bit Server VM 21.0.6+7-LTS on 21.0.6+7-LTS +indy +jit [arm64-darwin]

# install and run with existing native launcher
[] jruby $ gem install jruby-launcher
Building native extensions. This could take a while...
Successfully installed jruby-launcher-1.1.19-java
1 gem installed
[] jruby $ jruby -v
WARNING: Unknown module: org.jruby.dist specified to --add-opens
WARNING: Unknown module: org.jruby.dist specified to --add-opens
WARNING: Unknown module: org.jruby.dist specified to --add-opens
WARNING: Unknown module: org.jruby.dist specified to --add-opens
jruby 10.0.0.0-SNAPSHOT (3.4.2) 2025-03-31 b7ee3bb4ae OpenJDK 64-Bit Server VM 21.0.6+7-LTS on 21.0.6+7-LTS +indy +jit [arm64-darwin]

# install and run with new skinny launcher
# note the warnings do not seem to impede the installation
[] jruby $ gem install ../jruby-launcher/pkg/jruby-launcher-2.0.0.pr1-java.gem 
WARNING: Unknown module: org.jruby.dist specified to --add-opens
WARNING: Unknown module: org.jruby.dist specified to --add-opens
WARNING: Unknown module: org.jruby.dist specified to --add-opens
WARNING: Unknown module: org.jruby.dist specified to --add-opens
Building native extensions. This could take a while...
WARNING: Unknown module: org.jruby.dist specified to --add-opens
WARNING: Unknown module: org.jruby.dist specified to --add-opens
WARNING: Unknown module: org.jruby.dist specified to --add-opens
WARNING: Unknown module: org.jruby.dist specified to --add-opens
# These line gets substituted with the actual Config::CONFIG items location by extconf.rb
PREFIX = /Users/headius/work/jruby
BINDIR = /Users/headius/work/jruby/bin
JRUBY_VERSION = 10.0.0.0-SNAPSHOT
JRUBY_MODULE =
INSTALLDIR = $(PREFIX)/lib/ruby/shared/rubygems/defaults
INSTALLDIR9000 = $(PREFIX)/lib/ruby/stdlib/rubygems/defaults
OLDINSTALLDIR = $(PREFIX)/lib/ruby/site_ruby/1.8/rubygems/defaults

ifeq (true,$(shell test -x $(BINDIR)/jruby && echo true))
# NOTE: verbose output of build removed here
Successfully installed jruby-launcher-2.0.0.pr1-java
1 gem installed
[] jruby $ jruby -v
jruby 10.0.0.0-SNAPSHOT (3.4.2) 2025-03-31 b7ee3bb4ae OpenJDK 64-Bit Server VM 21.0.6+7-LTS on 21.0.6+7-LTS +indy +jit [arm64-darwin]
[] jruby $ file `which jruby`
/Users/headius/work/jruby/bin/jruby: Mach-O 64-bit executable arm64

# using the --cache flag with --logcache to prove it is working
[] jruby $ jruby --logcache --cache
[1.433s][warning][cds] Skipping org/jruby/org/objectweb/asm/ClassVisitor: Old class has been linked
[1.433s][warning][cds] Skipping org/joda/time/tz/ZoneInfoProvider: Old class has been linked
[1.433s][warning][cds] Skipping org/joda/time/chrono/AssembledChronology$Fields: Old class has been linked
...

This is looking very good so far, but it seems like some change in the makefile has triggered additional verbose output we need to clean up.

@headius
Copy link
Member

headius commented Mar 31, 2025

False alarm on that verbose output... running the jruby-launcher install again does NOT output the verbose build stuff. It may be something to do with the old launcher not setting up JRuby properly.

$ gem install ../jruby-launcher/pkg/jruby-launcher-2.0.0.pr1-java.gem
Building native extensions. This could take a while...
Successfully installed jruby-launcher-2.0.0.pr1-java
1 gem installed

@mrnoname1000 mrnoname1000 force-pushed the simple-unix-launcher branch from 82e9360 to 964a5a1 Compare March 31, 2025 22:24
@headius
Copy link
Member

headius commented Mar 31, 2025

@mrnoname1000 I see there are some failures to find the jruby.sh file now that tests are running. Other failures are possibly behavior changes in jruby.sh that were never reflected in the old launcher.

So one big thing I think might simplify this would be that the skinny launcher should only run the jruby.sh file that's right next to it in JRuby's bin dir. Perhaps that would help make sure it can find it? Perhaps the build can verify that the jruby.sh file is there?

@mrnoname1000
Copy link
Contributor Author

Are these tests that live in the main JRuby repo? It should just be resolving the path to itself, then executing the sibling jruby.sh but if it doesn't exist it'll error

@headius
Copy link
Member

headius commented Apr 1, 2025

@mrnoname1000 I believe they are all tests that live in this repository. Have a look at the failed jobs (and I will as well).

@headius
Copy link
Member

headius commented Apr 1, 2025

Looks like a number of these are failing because the test harness expects some native launcher-only debug flags to be used:

  38) JRuby native launcher should use --module-path on java9+ jruby 9.2.1+
      Failure/Error: jruby_launcher_args('').grep(/^--module-path=.*jruby.jar/).should_not be_empty
        expected `[].empty?` to be falsey, got true
      # ./spec/launcher_spec.rb:274:in `block in <main>'
      # ./spec/spec_helper.rb:56:in `with_environment'
      # ./spec/launcher_spec.rb:273:in `block in <main>'
      # ./spec/launcher_spec.rb:271:in `block in <main>'

jruby_launcher_args passes -Xcommand which is probably similar to --environment in the shell launcher (much of the work on this codebase was not done by me).

I'll try to get more of these passing locally.

@headius
Copy link
Member

headius commented Apr 1, 2025

Aha... and many of them expect to be able to run the launcher in the absence of JRuby! Obviously that won't work when it has to have the shell script.

I will also try to make those work better by putting the shell script near the executable.

@headius
Copy link
Member

headius commented Apr 1, 2025

Yeah we will need to fully reexamine these specs... I'm not sure any of them are valid or supportable directly with the new code.

I'm still figuring out where all the pieces are but basically this sets up a dummy JRuby home and then runs the launcher several ways without actually starting JRuby. So there's a jruby.jar, but it's a dummy, and it's in a lib dir but none of the standard library is present. It's only trying to validate that the launcher finds the JRuby jar and builds the proper command lines to exec... which is what the shell launcher does for us now.

So for the skinny launcher, the only things we really need to test is that it can locate the sibling jruby.sh file and launch it. We may also want to add some of the native launcher flags like -Xversion for the version of the launcher and -Xcommand to print out the command it is about to exec.

The specs are still valid for the Windows launcher, and may be needed for the Rust launcher when that's ready.

@headius
Copy link
Member

headius commented Apr 1, 2025

FWIW I ran some of our larger JRuby test suites with this new launcher and saw no failures related to the command line.

@headius
Copy link
Member

headius commented Apr 1, 2025

I have pushed this version as a preview gem, jruby-launcher 2.0.0.pr1, installable by gem install --pre jruby-launcher. It seems to work just fine for me.

@headius
Copy link
Member

headius commented Apr 1, 2025

This patch excludes the specs when not running on Windows. No specs run, but none of them are really valid with the skinny launcher anyway.

diff --git a/spec/launcher_spec.rb b/spec/launcher_spec.rb
index 79573c1..1478292 100644
--- a/spec/launcher_spec.rb
+++ b/spec/launcher_spec.rb
@@ -2,7 +2,7 @@ require 'tmpdir'
 require File.expand_path('../spec_helper.rb', __FILE__)
 load File.expand_path('../../lib/jruby-launcher.rb', __FILE__)
 
-describe "JRuby native launcher" do
+describe "JRuby native launcher", if: /Windows/.match?(ENV_JAVA['os.name']) do
   it "should run org.jruby.Main" do
     jruby_launcher_args("").last.should == "org/jruby/Main"
   end

@Earlopain
Copy link

I gave it a shot on 9.4 and after installing it it broke my rbenv jruby install:

$ ruby -v
jruby 9.4.12.0 (3.1.4) 2025-02-11 f4ab75096a OpenJDK 64-Bit Server VM 21.0.6+7 on 21.0.6+7 +jit [x86_64-linux]

$ gem install --pre jruby-launcher
Fetching jruby-launcher-2.0.0.pr1-java.gem
Building native extensions. This could take a while...
Successfully installed jruby-launcher-2.0.0.pr1-java
Parsing documentation for jruby-launcher-2.0.0.pr1-java
Installing ri documentation for jruby-launcher-2.0.0.pr1-java
Done installing documentation for jruby-launcher after 1 seconds
1 gem installed

$ ruby -v
ruby: No such file or directory: /home/user/.rbenv/versions/jruby-9.4.12.0/bin/jruby.sh

I wanted to test jruby-10-snapshot first but I can't install it there because it needs the fixed launcher for that I think (bad file description error)

@headius
Copy link
Member

headius commented Apr 2, 2025

@Earlopain Thanks for the report! Can you confirm that the file it claims is missing exists? It really should be there.

@Earlopain
Copy link

Nah, it's definitly gone https://github.com/rbenv/ruby-build/blob/2334633d60b78124fc99dedb32728605f44a4e56/bin/ruby-build#L938

That code has been there since forever rbenv/ruby-build#1. Looks like that PR was the one to add the very first jruby version to ruby-build.

@headius
Copy link
Member

headius commented Apr 2, 2025

Ugh, why is it deleting the shell script? That basically makes it possible to go back to the script and serves no purpose I can see. It's not a Windows file either so I'm not sure why it's deleted in this function.

They need to stop doing that, but the damage is done for anyone with a current installation. I'm going to have to figure out a workaround.

headius added a commit to headius/ruby-build that referenced this pull request Apr 2, 2025
I'm not sure why this file was being deleted but this code dates way back! Unfortunately deleting this interferes with a new version of the native JRuby launcher we want to release which is dependent on the shell script being present. This PR removes jruby.sh from the `remove_windows_files` function so it can be used by the new launcher.

See jruby/jruby-launcher#48 (comment)
@headius
Copy link
Member

headius commented Apr 2, 2025

I just pushed rbenv/ruby-build#2517 to stop deleting the jruby.sh file. That logic is old enough that I would not be surprised if I younger, more naive version of me told them it was okay to do. In any case, it needs to stop.

I have also proposed in the past that this launcher gem ship the shell script as well, so that users can update both the native and the shell launchers if a blocking issue is found. We may need to revisit that idea.

@headius
Copy link
Member

headius commented Apr 2, 2025

@Earlopain perhaps you can manually apply my rbenv patch and confirm it fixes the issue with the skinny launcher? And comment on my pr?

@Earlopain
Copy link

Yeah, that seems to work OK. I'll comment on the PR

@headius
Copy link
Member

headius commented Apr 3, 2025

I'm going to merge and make the additional changes.

@headius headius merged commit 10d4e56 into jruby:master Apr 3, 2025
0 of 2 checks passed
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.

Launcher has fallen very far behind the shell script
3 participants