Skip to content

[rust gem] Major improvements for gem scaffolding (rebased)#8455

Merged
hsbt merged 8 commits intoruby:masterfrom
gjtorikian:cargo-test-2
Feb 13, 2026
Merged

[rust gem] Major improvements for gem scaffolding (rebased)#8455
hsbt merged 8 commits intoruby:masterfrom
gjtorikian:cargo-test-2

Conversation

@gjtorikian
Copy link
Copy Markdown
Contributor

I heeded the call from @ianks in #7608 to rebase on top of master.

The one change I added was to bump the version of magnus to 0.7.

The one file diff not present is this one. I did not dig into the git blame, but it looks like at some point Gemfile.tt removed this block.

@deivid-rodriguez
Copy link
Copy Markdown
Contributor

The one file diff not present is this one. I did not dig into the git blame, but it looks like at some point Gemfile.tt removed this block.

Yes, there was some overlapping with another PR, which was already merged, so that part is already there 👍.

There's one test failure though that I'd say it's related since I've never seen it before, it may be intermittent given it only happened with MacOS + Ruby 3.1, but we should try to figure out the reason.

@deivid-rodriguez
Copy link
Copy Markdown
Contributor

It seems the failure was already noticed in the initial PR, see #7608 (comment).

Comment thread bundler/lib/bundler/templates/newgem/ext/newgem/Cargo.toml.tt Outdated
@ianks
Copy link
Copy Markdown
Contributor

ianks commented Feb 5, 2025

This is so helpful!! ❤️

@gjtorikian
Copy link
Copy Markdown
Contributor Author

There's one test failure though that I'd say it's related since I've never seen it before, it may be intermittent given it only happened with MacOS + Ruby 3.1, but we should try to figure out the reason.

What's Bundler's policy on supporting older rubies? Given that Ruby 3.1 is EOL in a month, can we get away with not fixing this?

@deivid-rodriguez
Copy link
Copy Markdown
Contributor

We'd be dropping support for Ruby 3.1 this year, so I'd be open to not fixing that error if it's just happening in Ruby 3.1. However, I think it may be affecting all rubies, because I believe @simi reproduced it locally with Ruby 3.3 as per #7608 (comment).

@simi
Copy link
Copy Markdown

simi commented Feb 10, 2025

Happy to test again if needed.

Comment thread bundler/lib/bundler/templates/newgem/github/workflows/build-gems.yml.tt Outdated
@deivid-rodriguez
Copy link
Copy Markdown
Contributor

@simi If you're able to confirm whether you still see the same issue locally, that'd be great!

Comment on lines -44 to -45
# Uncomment to register a new dependency of your gem
# spec.add_dependency "example-gem", "~> 1.0"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please restore these lines. They are not related Rust gem.

Copy link
Copy Markdown
Contributor

@deivid-rodriguez deivid-rodriguez Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can maybe move it to an else block, since in the case of config[:ext] == 'rust', it should be unnecessary to explain how to add a dependency?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be....but it's nice to do. :) I'll restore it.

it "can call into Rust" do
result = <%= config[:constant_name] %>.hello("world")

expect(result).to be("Hello earth, from Rust!")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs eq as these will be different objects I think

     Failure/Error: expect(result).to be("Hello earth, from Rust!")
     
       expected #<String:1640> => "Hello earth, from Rust!"
            got #<String:1648> => "Hello earth, from Rust!"
     
       Compared using equal?, which compares object identity,
       but expected and actual are not the same object. Use
       `expect(actual).to eq(expected)` if you don't care about
       object identity in this example.
Suggested change
expect(result).to be("Hello earth, from Rust!")
expect(result).to eq("Hello earth, from Rust!")
Suggested change
expect(result).to be("Hello earth, from Rust!")
expect(result).to eq("Hello world, from Rust!")

- name: Build gem
run: bundle exec rake build

- uses: actions/upload-artifact@v3
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gjtorikian
Copy link
Copy Markdown
Contributor Author

Humble bump to @simi to verify that this PR resolves the previously observed issue. 🙏

require_relative "<%= File.basename(config[:namespaced_path]) %>/version"
<%- if config[:ext] -%>
require_relative "<%= File.basename(config[:namespaced_path]) %>/<%= config[:underscored_name] %>"
# Attempt to load a versioned extension based on the Ruby version.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove these changes from template? That workaround is only for fat gem, not generally usage.

it "includes rake-compiler, rb_sys gems and required_rubygems_version constraint" do
it "includes rake-compiler constraint" do
expect(bundled_app("#{gem_name}/Gemfile").read).to include('gem "rake-compiler"')
expect(bundled_app("#{gem_name}/#{gem_name}.gemspec").read).to include('spec.add_dependency "rb_sys"')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove this?

@hsbt hsbt force-pushed the cargo-test-2 branch 2 times, most recently from e316bad to c07c4e0 Compare February 13, 2026 05:42
Copy link
Copy Markdown
Member

@hsbt hsbt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rebased with the current HEAD and squash some commits.

@hsbt hsbt enabled auto-merge February 13, 2026 05:57
@hsbt
Copy link
Copy Markdown
Member

hsbt commented Feb 13, 2026

@ianks @gjtorikian I will merge this with the current changes. If you have extra changes, feel free to open another PR. Thanks!

@hsbt hsbt merged commit 6b43b5e into ruby:master Feb 13, 2026
92 checks passed
hsbt added a commit that referenced this pull request Feb 24, 2026
[rust gem] Major improvements for gem scaffolding (rebased)

(cherry picked from commit 6b43b5e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants