jruby-launcher icon indicating copy to clipboard operation
jruby-launcher copied to clipboard

Provide ruby.exe so it's a drop-in replacement for MRI

Open eregon opened this issue 5 years ago • 18 comments

See https://github.com/jruby/jruby/issues/6042#issuecomment-576437707

Currently it's not obvious how to make ruby ... work on Windows. On Unix this is usually done easily with ln -s jruby ruby, but on Windows the only way I could find is to create a ruby.bat with:

@ECHO OFF
@"%~dp0jruby.exe" %*

(I also tried mklink on Windows, that doesn't work)

It would be nice if this could be simplified and e.g. JRuby already ships with that ruby.bat and ruby files.

gem, rake, etc already conflict with MRI binaries so the only way to use a Ruby is to add it to PATH anyway. Not having something for ruby ... means there is a the danger to use MRI for that one, but not for other commands such as gem and rake, which is never intended.

eregon avatar Jan 20 '20 21:01 eregon

Having a 64-bit jruby.exe launcher would also be valuable: https://github.com/jruby/jruby/issues/6042#issuecomment-576463011

eregon avatar Jan 23 '20 13:01 eregon

@headius This became a problem again, see https://github.com/ruby/setup-ruby/issues/18#issuecomment-583770151

I'll copy the comments here for convenience: Various issues here, once again with how to provide a ruby alias for jruby that works in both PowerShell and Bash:

  • ruby -v in bash just fails on Windows if there is only ruby.bat: https://github.com/eregon/setup-ruby-test/runs/433780474?check_suite_focus=true
  • cp jruby.sh ruby fails because JRuby's .sh launcher is broken on Windows in JRuby 9.2.9.0: https://github.com/eregon/setup-ruby-test/runs/433786338?check_suite_focus=true
  • cp jruby.exe ruby.exe fails in PwSh: https://github.com/eregon/setup-ruby-test/runs/433787577?check_suite_focus=true
  • cp jruby.bash ruby kind of works but incorrectly deals with double quotes ("), which is fairly confusing: https://github.com/eregon/setup-ruby-test/runs/433791906?check_suite_focus=true MRI handles the double quotes fine: https://github.com/eregon/setup-ruby-test/runs/433791899?check_suite_focus=true

Could we have a ruby.exe or make cp jruby.exe ruby.exe work? .bat files are ignored in Bash on Windows. So I think only .exe files work in both PwSh and Bash.

eregon avatar Feb 08 '20 20:02 eregon

Here are the executables provided on MRI built by RubyInstaller2:

$ ls -l rubyinstaller-2.5.7-1-x64/bin
total 3.3M
-rwxr-xr-x. 1 eregon eregon 4.8K Oct  2 00:54 erb
-rw-r--r--. 1 eregon eregon 4.9K Oct  2 00:54 erb.cmd
-rwxr-xr-x. 1 eregon eregon  546 Oct  2 00:54 gem
-rw-r--r--. 1 eregon eregon  688 Oct  2 00:54 gem.cmd
-rwxr-xr-x. 1 eregon eregon  190 Oct  2 00:54 irb
-rw-r--r--. 1 eregon eregon  360 Oct  2 00:54 irb.cmd
-rw-r--r--. 1 eregon eregon  729 Oct  2 00:54 rake
-rw-r--r--. 1 eregon eregon  153 Oct  2 00:54 rake.cmd
-rwxr-xr-x. 1 eregon eregon  938 Oct  2 00:54 rdoc
-rw-r--r--. 1 eregon eregon 1.1K Oct  2 00:54 rdoc.cmd
-rwxr-xr-x. 1 eregon eregon  188 Oct  2 00:54 ri
-rw-r--r--. 1 eregon eregon  330 Oct  2 00:54 ri.cmd
-rw-r--r--. 1 eregon eregon  694 Oct  2 00:54 ridk.cmd
-rw-r--r--. 1 eregon eregon  870 Oct  2 00:54 ridk.ps1
drwxr-xr-x. 2 eregon eregon 4.0K Oct  2 00:54 ruby_builtin_dlls
-rwxr-xr-x. 1 eregon eregon  35K Oct  2 00:54 ruby.exe
-rwxr-xr-x. 1 eregon eregon  35K Oct  2 00:54 rubyw.exe
-rw-r--r--. 1 eregon eregon  312 Oct  2 00:54 setrbvars.cmd
-rwxr-xr-x. 1 eregon eregon 3.1M Oct  2 00:54 x64-msvcrt-ruby250.dll

So having a ruby.exe seems the key. And cp jruby.exe ruby.exe doesn't work currently unfortunately.

eregon avatar Feb 08 '20 20:02 eregon

Is this only affecting Windows?

Most of the time we do not want to depend on the native launcher when the bash script works. If we could get rid of the native launcher we would, but it's needed on a few platforms (Darwin, Solaris) that don't support putting scripts into shebang lines.

headius avatar Feb 10 '20 19:02 headius

FWIW I would be fine with JRuby publishing ruby as the primary executable (bash or native) with jruby just a script that launches it. There's almost never a good reason to have both jruby and an unrelated ruby in PATH.

headius avatar Feb 10 '20 19:02 headius

Yes, it's only on Windows. In PowerShell, the bash script would never be picked by ruby .... So we need a reliable way to have ruby ... work in PowerShell for JRuby in Windows CIs.

The Bash script should also work with Bash on Windows, but currently it doesn't deal with quotes correctly.

My current workaround is copying the jruby Bash script to ruby, and adding ruby.bat but it's not perfect and it feels hacky I have to mess with the launchers manually: https://github.com/ruby/ruby-builder/blob/b4e83abd2f97c1374f0e54cde134b359947df550/.github/workflows/build.yml#L108-L111

Could we maybe fix whatever in jruby.exe assumes the executable to be named jruby.exe? Then at least we could copy it to ruby.exe and that would hopefully work. Even better would be to provide ruby.exe out of the box.

eregon avatar Feb 10 '20 19:02 eregon

A trivial fix would be to have the launcher build and install both jruby.exe and ruby.exe.

Someone's going to have to get the launcher updated to support our .java_opts files very soon so this should get fixed at the same time.

headius avatar Feb 12 '20 04:02 headius

Another reason is the latest jruby snapshot currently generates this for bundle.bat after gem install bundler:

@ECHO OFF
@"%~dp0ruby.exe" "%~dpn0" %*

Which is ruby.exe, not jruby.exe, so bundle probably doesn't work at all on Windows with the latest jruby snapshot: https://oss.sonatype.org/content/repositories/snapshots/org/jruby/jruby-dist/9.2.10.0-SNAPSHOT/jruby-dist-9.2.10.0-20200214.210645-79-bin.tar.gz

https://github.com/ruby/jruby-dev-builder/runs/448860418

eregon avatar Feb 16 '20 12:02 eregon

We do not generate those stubs... it's almost certainly something that has changed in RubyGems.

headius avatar Feb 16 '20 13:02 headius

This is rubygems issue https://github.com/rubygems/rubygems/issues/2873 (a 3.0 specific regression caused by https://github.com/rubygems/rubygems/pull/2119). It was fixed by https://github.com/rubygems/rubygems/pull/2876, which is present in the latest rubygems but it was never backported to rubygems 3.0 (although it's been scheduled for backport to rubygems 3.0.7).

@hsbt Do you still intend to release rubygems 3.0.7 including https://github.com/rubygems/rubygems/pull/2876?

deivid-rodriguez avatar Feb 16 '20 13:02 deivid-rodriguez

If we can get RubyGems 3.0.7 I can update it for JRuby 9.2.10, due out VERY SOON.

headius avatar Feb 16 '20 15:02 headius

@hsbt Do you still intend to release rubygems 3.0.7 including rubygems/rubygems#2876?

I will release RG 3.0.7 in this week.

hsbt avatar Feb 18 '20 00:02 hsbt

Released https://blog.rubygems.org/2020/02/18/3.0.7-released.html

hsbt avatar Feb 18 '20 12:02 hsbt

Thanks for releasing so quickly @hsbt!

Unfortunately there's a regression in 3.0.7, could you have a look at https://github.com/rubygems/rubygems/issues/3139?

deivid-rodriguez avatar Feb 18 '20 15:02 deivid-rodriguez

Also released 3.0.8

https://blog.rubygems.org/2020/02/19/3.0.8-released.html

@deivid-rodriguez Thanks for ping me.

hsbt avatar Feb 19 '20 03:02 hsbt

Thanks for the quick turnaround :purple_heart:! Unfortunately I don't think it made it into the jruby release, but it's good to have this fixed on the 3.x line :)

deivid-rodriguez avatar Feb 19 '20 09:02 deivid-rodriguez

Since we are spinning 9.2.11 I will look at 3.0.8 and check that there's no other regressions.

headius avatar Feb 20 '20 03:02 headius

FWIW, I pushed a quick fix for that issue to JRuby master, and looks like it made it in 9.2.10: https://github.com/jruby/jruby/commit/4f5b1d6c5aacdac01f085a65e2ca86aee652086e. Still would be better to use the fix from upstream of course.

eregon avatar Feb 21 '20 09:02 eregon