deivid-rodriguez / byebug

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

On Ruby 3.3.5: warning: fiddle was loaded from the standard library, but will no longer be part of the default gems starting from Ruby 3.5.0 #851

Open davidrunger opened 1 month ago

davidrunger commented 1 month ago

Problem description

A 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.

Expected behavior

No warning is printed.

Actual behavior

The aforementioned warning is printed.

Steps to reproduce the problem

Reproduction script

# 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: 'deivid-rodriguez/byebug', ref: '7e7384836defcfb40b675f5405428515b48eea9e'
end

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

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

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

byebug

Output

$ ruby run-byebug-from-inline-gemfile.rb
Ruby version: 3.3.5
Byebug version: 11.1.3
Fiddle version: 1.1.2
/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 issue is about the fact that those last two lines of warning output are printed. We don't want any warnings to be printed.

davidrunger commented 1 month ago

I believe that this issue is at least somewhat related to this Ruby bug: https://bugs.ruby-lang.org/issues/20714 . (I say that because the title of that Ruby bug is "Handle optional dependencies in bundled_gems.rb", and I think that fiddle is indeed (in at least some versions of Ruby) indirectly an "optional dependency" of byebug. byebug requires readline, which might try to require reline, which requires reline/terminfo, which "optionally" tries to require fiddle.)

That Ruby bug, in turn, has generated these two PRs:

  1. https://github.com/ruby/ruby/pull/11545
  2. https://github.com/ruby/ruby/pull/11550

However:

  1. I guess that, even if those PRs fix the issue in future versions of Ruby, this issue still exists (and presumably always will) in at least Ruby version 3.3.5.
  2. I am not sure that either of those PRs actually will fix the fundamental issue, even in future versions of Ruby. If byebug does need fiddle (though I have zero idea whether or not byebug actually does need fiddle), then I guess that what would happen if https://github.com/ruby/ruby/pull/11550 were to be merged, for example, is that we would no longer warn about the attempt to optionally require fiddle, but the attempt to require fiddle will start failing in future versions of Ruby that don't include fiddle in the standard library, and so byebug will not have the functionality that it needs from fiddle (which, again, I don't know whether or not there actually is any functionality from fiddle that byebug does need).
davidrunger commented 1 month ago

I have just submitted a PR that I think will fix this issue: https://github.com/deivid-rodriguez/byebug/pull/852 (though I don't really know whether or not it's a good idea to merge that PR).

davidrunger commented 1 month ago

Note: Looking at the path of requires that ultimately lead to requiring fiddle, I think that this bug will only occur if require "readline.#{RbConfig::CONFIG["DLEXT"]}" raises an exception? See here, where we only try to require reline (which then requires fiddle) if that require "readline.#{RbConfig::CONFIG["DLEXT"]}" attempt fails. On my machine, that require attempt does raise an exception, and so I do see these warnings on Ruby 3.3.5. But, for someone on whose machine require "readline.#{RbConfig::CONFIG["DLEXT"]}" succeeds, I guess that they won't see the warning that is the subject of this bug report.