-
Notifications
You must be signed in to change notification settings - Fork 43
Skip native extension building on non-CRuby #146
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,12 @@ namespace :version do | |
end | ||
end | ||
|
||
require 'rake/extensiontask' | ||
Rake::ExtensionTask.new("fiddle") | ||
Rake::ExtensionTask.new("-test-/memory_view") | ||
if RUBY_ENGINE == 'ruby' | ||
require 'rake/extensiontask' | ||
Rake::ExtensionTask.new("fiddle") | ||
Rake::ExtensionTask.new("-test-/memory_view") | ||
else | ||
task :compile | ||
end | ||
Comment on lines
-20
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we revert this? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 It's also for consistency with the logic in There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
It's needless when we don't use |
||
|
||
task :default => [:compile, :test] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'fiddle.so' | ||
if RUBY_ENGINE == "ruby" | ||
require 'fiddle.so' | ||
else | ||
$LOAD_PATH.delete(__dir__) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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).
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that changing There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel that it's an ad-hoc approach. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
OTOH
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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,
We can use TruffleRuby compatible change something like if we have a CI job for TruffleRuby: diff --git a/lib/fiddle/pack.rb b/lib/fiddle/pack.rb
index 81088f4..99e0742 100644
--- a/lib/fiddle/pack.rb
+++ b/lib/fiddle/pack.rb
@@ -15,8 +15,11 @@ module Fiddle
TYPE_USHORT => ALIGN_SHORT,
TYPE_UINT => ALIGN_INT,
TYPE_ULONG => ALIGN_LONG,
- TYPE_BOOL => ALIGN_BOOL,
}
+ # TruffleRuby doesn't have Fiddle::TYPE_BOOL yet.
+ if Fiddle.const_defined?(:TYPE_BOOL)
+ ALIGN_MAP[TYPE_BOOL] = ALIGN_BOOL
+ end
PACK_MAP = {
TYPE_VOIDP => "L!",
@@ -31,15 +34,18 @@ module Fiddle
TYPE_UINT => "I!",
TYPE_ULONG => "L!",
}
- case SIZEOF_BOOL
- when SIZEOF_CHAR
- PACK_MAP[TYPE_BOOL] = PACK_MAP[TYPE_UCHAR]
- when SIZEOF_SHORT
- PACK_MAP[TYPE_BOOL] = PACK_MAP[TYPE_USHORT]
- when SIZEOF_INT
- PACK_MAP[TYPE_BOOL] = PACK_MAP[TYPE_UINT]
- when SIZEOF_LONG
- PACK_MAP[TYPE_BOOL] = PACK_MAP[TYPE_ULONG]
+ # TruffleRuby doesn't have Fiddle::SIZEOF_BOOL yet.
+ if Fiddle.const_defined?(:SIZEOF_BOOL)
+ case SIZEOF_BOOL
+ when SIZEOF_CHAR
+ PACK_MAP[TYPE_BOOL] = PACK_MAP[TYPE_UCHAR]
+ when SIZEOF_SHORT
+ PACK_MAP[TYPE_BOOL] = PACK_MAP[TYPE_USHORT]
+ when SIZEOF_INT
+ PACK_MAP[TYPE_BOOL] = PACK_MAP[TYPE_UINT]
+ when SIZEOF_LONG
+ PACK_MAP[TYPE_BOOL] = PACK_MAP[TYPE_ULONG]
+ end
end
SIZE_MAP = {
@@ -54,8 +60,11 @@ module Fiddle
TYPE_USHORT => SIZEOF_SHORT,
TYPE_UINT => SIZEOF_INT,
TYPE_ULONG => SIZEOF_LONG,
- TYPE_BOOL => SIZEOF_BOOL,
}
+ # TruffleRuby doesn't have Fiddle::TYPE_BOOL yet.
+ if Fiddle.const_defined?(:TYPE_BOOL)
+ SIZE_MAP[TYPE_BOOL] = SIZEOF_BOOL
+ end
if defined?(TYPE_LONG_LONG)
ALIGN_MAP[TYPE_LONG_LONG] = ALIGN_MAP[TYPE_ULONG_LONG] = ALIGN_LONG_LONG
PACK_MAP[TYPE_LONG_LONG] = "q"
We can release an empty gem for JRuby like other gems did. (Or I may work on #104.)
How about requiring stdlib = RbConfig::CONFIG["rubylibdir"]
$LOAD_PATH.prepend(stdlib)
begin
require 'fiddle'
require 'fiddle/struct'
ensure
if $LOAD_PATH.first == stdlib
$LOAD_PATH.shift
else
raise 'fiddle files unexpectedly modified the $LOAD_PATH'
end
end Or we can update There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. Also the solution I propose is effectively equivalent to what is already done in 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 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,
How is this any better? Am I missing something? 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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 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 commentThe 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).
It does feel brittle as if a new file is added it could be missed there. I suppose we could use
Yes that's a valid point.
And for example we found that synchronization for
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. |
||
require 'fiddle' # load from stdlib | ||
return | ||
end | ||
|
||
require 'fiddle/closure' | ||
require 'fiddle/function' | ||
require 'fiddle/version' | ||
|
Uh oh!
There was an error while loading. Please reload this page.