Skip to content
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

Add support for JRuby #11

Merged
merged 6 commits into from Jan 16, 2021
Merged

Add support for JRuby #11

merged 6 commits into from Jan 16, 2021

Conversation

headius
Copy link
Contributor

@headius headius commented Jan 6, 2020

This PR contains the JRuby implementation of io/console based on FFI. It should be pushed as a java platform gem any time the io-console gem is updated.

Fixes #10.

@headius
Copy link
Contributor Author

headius commented Jan 6, 2020

One bit of process I'm not sure about: this -java gem can only be built with JRuby, and likewise the standard gem can't be build on JRuby, because the gemspec uses RUBY_ENGINE. This could be modified to allow building both versions on any impl, since they're just packaging files (i.e. there's no compile step required for either JRuby or MRI).

@hsbt hsbt requested a review from nobu January 7, 2020 04:42
@nobu
Copy link
Member

nobu commented Jan 10, 2020

Do you want io-console to include the Java version?
Otherwise, it would be possible to install a stub file for JRuby, I think, like https://github.com/ruby/io-console/tree/jruby-support

@headius
Copy link
Contributor Author

headius commented Jan 10, 2020

@nobu I think it would be best for the gem to actually contain our version of the library, as we already do for psych, json, racc, and other libraries. We will have to push a -java platform gem either way, and moving the sources from JRuby into the gem means we can maintain it alongside the CRuby version.

We want to match CRuby's use of default/preinstalled gems as closely as possible going forward.

@headius
Copy link
Contributor Author

headius commented Jan 10, 2020

Your addition of --platform will allow any implementation to build either platform gem, so I like that part.

headius added a commit to headius/jruby that referenced this pull request Jan 13, 2020
This commit makes the following changes:

* Move JRuby-specific console logic to io/console/jruby
* Add console.rb to load appropriate impl for the current engine
* Adjust tags to match passing tests
* Add test_io_console to MRI stdlib suite

See ruby/io-console#11
headius added a commit to headius/jruby that referenced this pull request Jan 13, 2020
This commit makes the following changes:

* Move JRuby-specific console logic to io/console/jruby
* Add console.rb to load appropriate impl for the current engine
* Adjust tags to match passing tests
* Add test_io_console to MRI stdlib suite

See ruby/io-console#11
@headius
Copy link
Contributor Author

headius commented Jan 13, 2020

I have re-pushed the primary commit with paths fixed. This version is now also live in JRuby proper and passing CI.

I also pushed a second commit that fixes a broken test on JRuby. The path to the "rubybin" executable was tweaked to substitute /ruby/ for the name of the TTY-less executable, which caused the jruby executable to become jjruby. The test works as before on MRI.

nobu and others added 4 commits January 28, 2020 10:09
Add `--platform` option tentatively.
This fixes ruby#10. Whenever a gem is pushed for the default platform
a gem must be pushed for the 'java' platform to avoid breaking
JRuby users.
@eregon
Copy link
Member

eregon commented Feb 12, 2020

I'd like to have this FFI implementation work on TruffleRuby too, see ruby/reline#124 and oracle/truffleruby#1904 (comment).

I think using the java platform wouldn't work for that, but simply use the default ruby platform and skip compilation on JRuby/TruffleRuby in extconf.rb.

t[:c_lflag] &= ~(LibC::ECHOE|LibC::ECHOK)
end

def raw(*, &block)
Copy link
Member

Choose a reason for hiding this comment

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

The options are not supported.

Copy link
Member

Choose a reason for hiding this comment

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

I mean min, time and intr options which are supported by IO#raw.

@nobu
Copy link
Member

nobu commented Feb 17, 2020

Isn't it better to place these files under a different name, e.g. "ffilib/", if truffleruby will use them too?

@nobu
Copy link
Member

nobu commented Feb 17, 2020

I meant "not only for jruby".

@nobu
Copy link
Member

nobu commented Feb 17, 2020

I'm thinking of installing/moving ffi-version files by extconf.rb.

@eregon
Copy link
Member

eregon commented Feb 17, 2020

@nobu I think there should be a single gem push for simplicity, so a single platform.
I'd suggest having the files under lib/io/console/ffi, and always ship them.

@nobu
Copy link
Member

nobu commented Feb 18, 2020

I pushed 0.5.6, which just skips the extension on other than CRuby.
Merger of ffi version will be after it catches 0.5 up.

@eregon
Copy link
Member

eregon commented Feb 18, 2020

@nobu Thanks, I can confirm gem install reline works on TruffleRuby now.

@aycabta
Copy link
Member

aycabta commented Feb 19, 2020

I can confirm gem install reline works on TruffleRuby now.

Great! I guess that it's possible to install on JRuby too.

And, I think the intr: option should be supported by the io-console of other platforms because it's used when users press Ctrl-C to reset an inputting text.

@headius
Copy link
Contributor Author

headius commented Sep 22, 2020

So the issue with reline was resolved. The remaining issue would be io-console getting installed by a JRuby user, possibly through a transitive dependency. I would still like to see this gem contain the FFI implementation, so it could be shared across non-CRuby implementations. The FFI would be the fallback for platforms or runtimes that do not build the C extension. Some day, perhaps it could replace the C extension?

@eregon
Copy link
Member

eregon commented Sep 22, 2020

I agree it would be good to have the FFI implementation here too.

I think @nobu had some concern in #11 (comment) and @aycabta in #11 (comment). @headius Could you try to address them so it's fully compatible with the C extension?

@headius
Copy link
Contributor Author

headius commented Sep 22, 2020

I should be clear: this code was not originally written by me. I am hoping through this PR to release it into the public trust, so we can collaborate on making it a drop-in replacement for io/console.

I would welcome suggestions and patches for concrete improvements to make.

@nobu What do you mean "the options are not supported?" Are you referring to the LibC flags you linked? Or something like the intr: option @aycabta mentioned?

@aycabta Yes I agree this should match the C extension as closely as possible, but I'm not familiar with the intr: option.

@headius
Copy link
Contributor Author

headius commented Jan 15, 2021

I updated my branch to include the changes @nobu made as well as one fix from @aardvark179. Not much has changed since the original discussion of this PR (e.g. the intr: option is still not supported.

@headius
Copy link
Contributor Author

headius commented Jan 15, 2021

In the short term, can we get a -java gem release that includes the FFI logic but not the C extension?

At the moment we can't install reline on Windows because of the io-console requirement, which forces users to have a make command installed even though nothing will be built on JRuby.

Our users have been ok with this version for many years, even if it does not have all features and does not pass all tests. We will take responsibility for the code and bug reports against the FFI logic (which will probably be filed with JRuby rather than io-console).

@nobu nobu merged commit 7b7681b into ruby:master Jan 16, 2021
@headius headius deleted the jruby-support branch January 26, 2021 19:54
@headius
Copy link
Contributor Author

headius commented Feb 4, 2021

For others following along...

I have implemented the missing functionality in the FFI io/console and it now runs green on CRuby. It also runs green on JRuby with the exception of a few tests that require PTY.spawn to produce a child process with its own TTY, which is broken on JRuby (jruby/jruby#6552).

The FFI implementation can be shipped now, I believe.

See #22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

JRuby support
5 participants