Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Skip native extension building on non-CRuby #146
Skip native extension building on non-CRuby #146
Changes from 2 commits
341265c
3f6ac2b
58193bd
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we revert this?
We don't need to use
rake default
with TruffleRuby.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On one side you seem to be asking a clean integration by upstraming the Fiddle TruffleRuby backend here soon, and on the other side you seem to dislike any change making incremental progress towards that (the changes in
test/run.rb
is similar, it makes it easier to run tests in order to make them pass).I don't see any point to revert this, it's useful to run
bundle exec rake
on TruffleRuby, and that's the standard way to run a gem's test suite.It's also for consistency with the logic in
extconf.rb
, this extension is a CRuby-only extension.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just want to keep 1 logical change in 1 PR. Is it strange?
I think that this PR focus on "workaround for bundled gem" not "upstreaming TruffleRuby implementation".
It's needless when we don't use
$LOAD_PATH.delete
approach.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we need to load fiddle.rb from the stdlib in TruffleRuby/JRuby, which works (it's tested in the TruffleRuby/JRuby repos), unlike the version of Fiddle in this repo which only works on CRuby (because of the C extension).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that changing
$LOAD_PATH
is a good approach because$LOAD_PATH
is one of global variables.Can we use another approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no other way (AFAIK). We need to make sure the Ruby files of this gem are not loaded because it's a different version than in stdlib. So we need to remove it from $LOAD_PATH.
It is the same approach as for older FFI versions: https://github.com/ffi/ffi/blob/85d0fabce6ab5ceb3848f7e09a265341672a272d/lib/ffi.rb#L19
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel that it's an ad-hoc approach.
Can we use https://github.com/oracle/truffleruby/blob/512427a658f29b222df9a6da1b3ffc12b46a3be6/lib/mri/fiddle.rb#L3-L4 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For completeness I tried and it doesn't work, the test suite fails during loading and just
ruby -Ilib -e 'require "fiddle"; require "fiddle/struct"'
fails with:OTOH
$LOAD_PATH.delete(__dir__)
works for thatruby
command and the test suite loads and runs all tests (not all passing, but at least they all load).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I understand. Correct.
We can detect it by adding more checks to CI. For example,
ruby -e 'require "fiddle"; require "fiddle/struct"'
instead ofruby -e 'require "fiddle"; require "fiddle/struct"'
as you showed.We can use TruffleRuby compatible change something like if we have a CI job for TruffleRuby:
We can release an empty gem for JRuby like other gems did. (Or I may work on #104.)
How about requiring
fiddle/struct
infiddle.rb
?Or we can update
fiddle/pack.rb
in ruby/fiddle to TruffleRuby compatible as I showed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kou I am not sure why you are suggesting more complex or brittle solutions.
(brittle because
ruby -e 'require "fiddle"; require "fiddle/struct"'
is not proper testing and only covers one example, there are other fiddle files that are not eagerly loaded)I have shown a solution that works reliably and I have shown the various solutions your proposed so far do not work.
That solution is generic, i.e. it works for other gems too, not just fiddle, and we'll need to do something similar for some other default/bundled extension gems too.
So I have no interest to have highly-fiddle-specific solution here, it's just making things more complicated and less consistent (but if it would work reliably, fine, I'd be OK with it).
Also the solution I propose is effectively equivalent to what is already done in
strscan
andstringio
, where there it works because there is no.rb
file, which is conceptually equivalent to not adding the gemlib/
dir to$LOAD_PATH
.It is natural for language implementations to reimplement some of the core & standard library based on what makes sense for them, and possibly upstream that if it is stable enough and does not rely on too many internals. This upstreaming is a significant time investment, it does not happen in days but typically takes weeks or months (as we have already seen). It also significantly hinders the ability of language implementations to optimize these parts of stdlib better because then that upstreamed code needs to care about compatibility e.g. with older TruffleRuby versions, etc.
What is a concrete objective problem with
$LOAD_PATH.delete(__dir__)
?It seems clear that "$LOAD_PATH is a global variable and shouldn't be changed" is not a good enough argument to reject that approach,
$LOAD_PATH
is part of the require API, it's the only way to influence whererequire
looks. It is the natural way to solve this issue (short-term), where the gem is unexpectedly shadowing the standard library (which worked fine until now, as very few gems/Gemfile depended onfiddle
).How is this any better? Am I missing something?
As far as I understand, it would require you to do more work by building + pushing + testing the extra java-platform gem (if forgotten it breaks things) and it's effectively exactly the same as
$LOAD_PATH.delete(__dir__)
.And #104 would also be more work for you as then you'd need to maintain a Java implementation.
This PR, once merged & released should require no work or effort from you at all. I thought you would like that.
Also to give you my point of view:
If there is still no progress on this PR, I guess one approach is to add some kind of patch in TruffleRuby to do
$LOAD_PATH.delete(fiddle_gem_lib_dir)
whenrequire 'fiddle'
to never load fiddle from the gem.I don't think that's a good approach/solution though because:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't understand why I need to say the same thing again and again:
I don't want to change any global variables by require "fiddle".
I can't understand why you say that it's not clear.
I already showed a solution for it. We can use it for other files.
In principal, your solution (ignore gem) isn't a good solution. If an user wants to use the specific version of A gem, the version information is just ignored with TruffleRuby. It just avoids
require
error. I pointed out this 2 years ago: ruby/strscan#35 (comment)It seems that you say that this is a "short-term" workaround but you don't think that this is a "short-term" workaround. At least strscan still uses this workaround. I don't think that it's "short-term".
Anyway, here are PRs that import JRuby and TruffleRuby implementations:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But without that, there is AFAIK no short-term solution to make it work (on existing TruffleRuby releases).
Hence while I understand you don't like to change
$LOAD_PATH
, since it is the only solution to fix existing releases (broken indirectly by the fiddle warning added in CRuby), I think it is a reasonable short-term solution.It does feel brittle as if a new file is added it could be missed there. I suppose we could use
Dir.glob
but anyway that snippet of code is just more complicated and feels more risky than$LOAD_PATH.delete(__dir__)
.With
$LOAD_PATH.delete(__dir__)
the behavior is clear, with the alternatives it's far more subtle and therefore prone to bugs.Yes that's a valid point.
However, a subset of the functionality working is much better than nothing working or even
require 'fiddle'
failing.The tension here is with:
And for example we found that synchronization for
stringio
is a huge overhead, and optimizing that would be much harder if TruffleRuby's stringio implementation lives in ruby/stringio and needs to support multiple truffleruby versions.Actually on September 12 I wrote to @andrykonchin in a private chat:
And there is the same concern with moving the code here.
Thank you, I didn't expect that.
There are some concerns we need to discuss before that can be merged, I'll reply on that PR.