Skip to content

Commit 1de1581

Browse files
yoshokumatzbot
authored andcommitted
[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. ruby/rubygems@68599bd107
1 parent a82aa08 commit 1de1581

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/bundler/templates/newgem/lib/newgem.rb.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require_relative "<%= File.basename(config[:namespaced_path]) %>/version"
44
<%- if config[:ext] -%>
5-
require_relative "<%= File.basename(config[:namespaced_path]) %>/<%= config[:underscored_name] %>"
5+
require "<%= File.basename(config[:namespaced_path]) %>/<%= config[:underscored_name] %>"
66
<%- end -%>
77

88
<%- config[:constant_array].each_with_index do |c, i| -%>

spec/bundler/commands/newgem_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,13 @@ def create_temporary_dir(dir)
16811681
expect(bundled_app("#{gem_name}/ext/#{gem_name}/#{gem_name}.c")).to exist
16821682
end
16831683

1684+
it "generates native extension loading code" do
1685+
expect(bundled_app("#{gem_name}/lib/#{gem_name}.rb").read).to include(<<~RUBY)
1686+
require_relative "test_gem/version"
1687+
require "#{gem_name}/#{gem_name}"
1688+
RUBY
1689+
end
1690+
16841691
it "includes rake-compiler, but no Rust related changes" do
16851692
expect(bundled_app("#{gem_name}/Gemfile").read).to include('gem "rake-compiler"')
16861693

0 commit comments

Comments
 (0)