deivid-rodriguez / byebug

Debugging in Ruby 2
BSD 2-Clause "Simplified" License
3.34k stars 328 forks source link

Add 'fiddle' gem as a runtime dependency #852

Open davidrunger opened 1 month ago

davidrunger commented 1 month ago

Fixes deivid-rodriguez/byebug#851

The following warning is printed to stderr when using byebug on Ruby 3.3.5:

/home/david/.rbenv/versions/3.3.5/lib/ruby/3.3.0/reline.rb:9: warning: fiddle was loaded from the standard library, but will no longer be part of the default gems starting from Ruby 3.5.0.

You can add fiddle to your Gemfile or gemspec to silence this warning.

This change aims to cause that warning no longer to appear, by implementing one of the suggestions in the warning message, i.e. by adding the fiddle gem to byebug's gemspec as a runtime dependency.

davidrunger commented 1 month ago

Here's the reproduction script from issue #851, but modified to use this branch, rather than the master branch of this repo:

# File: run-byebug-from-inline-gemfile.rb
# Run with: `ruby run-byebug-from-inline-gemfile.rb`

require 'bundler/inline'

gemfile do
  ruby '3.3.5'
  source 'https://rubygems.org'
  gem 'byebug', github: 'davidrunger/byebug', ref: '731e9dc15eee40bde99f46c12c68c32f09f0d806'
end

puts("Ruby version: #{RUBY_VERSION}")

require 'byebug/version'
puts("Byebug version: #{Byebug::VERSION}")

require 'fiddle/version'
puts("Fiddle version: #{Fiddle::VERSION}")

byebug

When executed, that modified version of the script does not print the warning about fiddle that is documented in the issue report; it just prints this:

$ ruby run-byebug-from-inline-gemfile.rb
Ruby version: 3.3.5
Byebug version: 11.1.3
Fiddle version: 1.1.2
davidrunger commented 1 month ago

Caveat :exclamation:

This PR should probably only be merged if byebug actually needs (or at least benefits from) something that is provided by the fiddle gem.

(Unfortunately, I personally have no idea whether or not that is the case.)

If byebug does not need any of the functionality of fiddle, then it might be / probably is possible and maybe also worthwhile to figure out some other solution to #851 that does not entail adding fiddle as a not-actually-needed dependency.

Earlopain commented 1 month ago

This warning is comming from the reline gem, which itself has an optional dependency on fiddle. The warning will be gone in Ruby 3.3.6 because of https://github.com/ruby/ruby/pull/11558. Also see https://github.com/ruby/reline/pull/721. Ruby decided to backport warnings for a few gems (why?)

On the other hand, reline should be added as a runtime dependency because you will get a warning for that with Ruby 3.4 (byebug requires readline but it is just an alias): https://github.com/ruby/ruby/pull/11560

davidrunger commented 1 month ago

@Earlopain Thank you for all of those helpful pointers/links!

This warning is comming from the reline gem, which itself has an optional dependency on fiddle.

FWIW, I think that this is not technically quite true. At least, in my reproduction script, I think that reline is sourced from the Ruby 3.3.5 standard library, rather than coming from the reline gem.

If I add this content to the script:

require 'reline/version'
puts("Reline version: #{Reline::VERSION}")
puts("Reline version source: #{Reline.const_source_location(:VERSION)}")

Then it prints this:

Reline version: 0.5.7
Reline version source: ["/home/david/.rbenv/versions/3.3.5/lib/ruby/3.3.0/reline/version.rb", 2]

which seems to reference a path in the Ruby 3.3.5 standard library.

If I add to the gemfile block of the reproduction script this line:

gem 'reline'

then this gets printed:

Reline version: 0.5.10
Reline version source: ["/home/david/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/reline-0.5.10/lib/reline/version.rb", 2]

In that case, we can see that the path is from the gem version of reline (and also that the version is more up to date, because it comes from the latest version of the gem, rather than the outdated Ruby 3.3.5 standard library version).

Maybe this little detail doesn't matter much, but I mention it for clarity, and in case it does somehow matter.

The warning will be gone in Ruby 3.3.6 because of https://github.com/ruby/ruby/pull/11558.

That's very helpful info. I guess maybe it's acceptable, if 3.3.5 is the only Ruby version that will see these warnings? Maybe just close this PR and take no action to try to suppress that warning on Ruby 3.3.5?

Maybe it's worth mentioning that a number of my projects that use byebug actually don't ultimately print this warning, because there is some other gem in the project's bundle that requires the reline gem, even though byebug itself doesn't request the reline gem as a dependency. In that case, I think that having reline in the Gemfile dependency tree at all causes all require "reline" statements to pull from the reline gem (rather than from the standard library), which avoids this warning (due to https://github.com/ruby/reline/pull/721, as you kindly linked to), even when the require is ultimately triggered from byebug, which doesn't explicitly have reline or fiddle as a dependency.

While pulling in the reline gem will suppress the warning about fiddle, it won't actually ensure that fiddle is made available, right? I still don't know whether or not there is any value in making sure that we actually do include fiddle (i.e. what this PR does), and it seems relevant, to help inform the best way forward. I think that I might have heard some mention somewhere that fiddle is necessary in order for things to work correctly on Windows?

Earlopain commented 1 month ago

FWIW, I think that this is not technically quite true. At least, in my reproduction script, I think that reline is sourced from the Ruby 3.3.5 standard library, rather than coming from the reline gem.

It is using the standard library version, yes. In ruby 3.3.5 some warnings were backported, but the standard library versions did not get appropriately updated, which means ruby's own standard library is now emitting these warnings. It is rather unfortunate, reline is not the only gem this happened to.

Even in the standard library I would still call it a gem, but the semantics don't really matter.

I guess maybe it's acceptable, if 3.3.5 is the only Ruby version that will see these warnings? Maybe just close this PR and take no action to try to suppress that warning on Ruby 3.3.5

I'd love for ruby to release 3.3.6 right now but I doubt this is going to happen. There was no release when 3.3.3 broke net-pop bundler resolution. Personally, I don't think libraries should work around ruby deficiencies like this, and it is just a warning. The next release will be in about ~2 months.

Maybe it's worth mentioning that a number of my projects that use byebug actually don't ultimately print this warning

Yes, if even just one direct/transient dependency pulls it in, the warnings will not show. I don't find it optimal but it is the way it is, and to be fair it has worked rather ok for now with previous warnings. You just need one person to alert the library author.

While pulling in the reline gem will suppress the warning about fiddle, it won't actually ensure that fiddle is made available, right?

That's correct, yes. I would think if any functionality actually relies on it, then reline would bump its major version instead of dropping that in a patch version. But that's just a guess, I'm as clueless as you in that regard.