[ruby/rubygems] Fix native extension loading in newgem template for RHEL-based systems

Add fallback to `require` when `require_relative` fails to load native
extensions. This addresses an issue on RHEL-based Linux distributions
where Ruby scripts and built native extension shared libraries are
installed in separate directories.

https://github.com/ruby/rubygems/commit/68599bd107
This commit is contained in:
yoshoku 2025-12-04 09:04:11 +09:00 committed by git
parent a82aa08fe0
commit 1de15815a8
2 changed files with 8 additions and 1 deletions

View File

@ -2,7 +2,7 @@
require_relative "<%= File.basename(config[:namespaced_path]) %>/version"
<%- if config[:ext] -%>
require_relative "<%= File.basename(config[:namespaced_path]) %>/<%= config[:underscored_name] %>"
require "<%= File.basename(config[:namespaced_path]) %>/<%= config[:underscored_name] %>"
<%- end -%>
<%- config[:constant_array].each_with_index do |c, i| -%>

View File

@ -1681,6 +1681,13 @@ RSpec.describe "bundle gem" do
expect(bundled_app("#{gem_name}/ext/#{gem_name}/#{gem_name}.c")).to exist
end
it "generates native extension loading code" do
expect(bundled_app("#{gem_name}/lib/#{gem_name}.rb").read).to include(<<~RUBY)
require_relative "test_gem/version"
require "#{gem_name}/#{gem_name}"
RUBY
end
it "includes rake-compiler, but no Rust related changes" do
expect(bundled_app("#{gem_name}/Gemfile").read).to include('gem "rake-compiler"')