Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --ext=rust support to bundle gem for creating simple gems with Rust extensions #6149

Merged
merged 1 commit into from
Dec 21, 2022

Conversation

simi
Copy link
Member

@simi simi commented Dec 19, 2022

Supporting just raw Rust without magnus. I would like to add additional extension skeleton using magnus (like --ext=magnus).

based on combination of:

I would like to add another PR as followup to do something at least "almost usual" in generated extensions (for example define "hello" method and return "hello world") for both C and Rust variants (and potentially magnus as well once introduced).

@ianks feel free to review 馃檹

Copy link
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 added comment for cometic.

bundler/lib/bundler/cli/gem.rb Show resolved Hide resolved
bundler/lib/bundler/cli/gem.rb Show resolved Hide resolved
@ianks
Copy link
Collaborator

ianks commented Dec 19, 2022

This looks good for the most part. Great work @simi

Although I do really think we should default to Magnus (with the rb-sys-interop feature). Defaulting to rb-sys is not something I would encourage for gem authors. Are you open to doing that?

@ianks
Copy link
Collaborator

ianks commented Dec 19, 2022

So essentially the CLI interface I鈥檇 recommend would be like this:

  • ext=rust -> Magnus
  • ext=rb-sys -> rb-sys

@simi
Copy link
Member Author

simi commented Dec 19, 2022

So essentially the CLI interface I鈥檇 recommend would be like this:

  • ext=rust -> Magnus
  • ext=rb-sys -> rb-sys

What about following?

  • ext=magnus -> Magnus
  • ext=rb-sys -> rb-sys

@simi
Copy link
Member Author

simi commented Dec 19, 2022

I'm going to submit magnus implementation and we can decide on the naming later. We can use generic names like rust and rust-minimal or similar, so the underlying implementation is not important.

@hsbt
Copy link
Member

hsbt commented Dec 19, 2022

  • ext=magnus -> Magnus
  • ext=rb-sys -> rb-sys

Can we alias rust to rb-sys? I'm not sure which is the better recommendation for the Rubyists. I'm also okay to alias magnus.

@ianks
Copy link
Collaborator

ianks commented Dec 20, 2022

  • ext=magnus -> Magnus
  • ext=rb-sys -> rb-sys

Can we alias rust to rb-sys? I'm not sure which is the better recommendation for the Rubyists. I'm okay to alias magnus.

I'd prefer not to, because really gem authors should be using a high-level / safe library like magnus when writing gems. With magnus they also have the ability to opt-in to the low-level / unsafe bindings from rb-sys (via the rb-sys-interop feature) when they need to do, but the default should be safe.

@simi simi force-pushed the rust-ext branch 2 times, most recently from fa6ffed to 2fc1993 Compare December 20, 2022 06:24
@simi simi marked this pull request as ready for review December 20, 2022 06:25
@simi
Copy link
Member Author

simi commented Dec 20, 2022

@ianks ok, for now I decided to just got with --ext=rust and in docs mention currently it will generate code based on magnus. That should be enough to be able to change this in the future. I have used magnus crate only for now (following magnus README) to keep it as simple as possible.

Next to those changes, I have updated CIs to be able to compile Rust by default (when selected). I have used diferent approach per CI since each work in different way. At some of them I have opted-in to install latest RubyGems and Bundler, since bundler can now auto-switch. That seems the easiest option for now to keep it compatible accross various Rubies.

@simi
Copy link
Member Author

simi commented Dec 20, 2022

Also I have added required_rubygems_version constraint to rust extension gemspec, since older rubygems can't handle Rust extensions.

@@ -23,5 +23,8 @@ jobs:
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
<%- if config[:ext] == 'rust' -%>
rubygems: 'latest' # for best Rust extension support
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should use https://github.com/oxidize-rb/actions/blob/main/setup-ruby-and-rust/readme.md for CI on rust if possible. It鈥檚 well supported and this current configuration will probably not work in all scenarios, it also will be slow due to no caching etc

Copy link
Member Author

Choose a reason for hiding this comment

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

@ianks there is only v1 tag and that doesn't support needed rubygems option. Would it be possible to tag new version?

@simi
Copy link
Member Author

simi commented Dec 20, 2022

Can we keep CI improvement discussion out of this PR? I'll open following PR with all suggested improvements once merged.

@simi
Copy link
Member Author

simi commented Dec 20, 2022

@deivid-rodriguez I have reverted all changes into CI templates for this PR. I'll continue on improving those in following PR keeping in mind all suggestions from comments in here.

Copy link
Member

@deivid-rodriguez deivid-rodriguez left a comment

Choose a reason for hiding this comment

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

Awesome, thanks @simi!

@ianks
Copy link
Collaborator

ianks commented Dec 20, 2022

Looks good to me! Thanks so much @simi, this will have a huge impact. Let's give @matsadler a chance to chime in as well :)

@simi
Copy link
Member Author

simi commented Dec 20, 2022

@ianks cool, we would like to release this soon before Ruby 3.2 (to be included in there). I'm going to prepare followup (based on this one) for CI thingies meanwhile.

Also I would like to support this by upgrading guides and maybe writing small blog explaning how this works.

@matsadler
Copy link
Contributor

No comments from me apart from this is very cool.

Let me know if you'd like a hand with any documentation, like if you want examples of how to do something in particular with Magnus.

@simi
Copy link
Member Author

simi commented Dec 20, 2022

Should I squash, rebase and merge?

@hsbt
Copy link
Member

hsbt commented Dec 20, 2022

You can merge this without squash, I think.

@simi simi force-pushed the rust-ext branch 4 times, most recently from d6f5d71 to 6853738 Compare December 21, 2022 04:13
@simi
Copy link
Member Author

simi commented Dec 21, 2022

@deivid-rodriguez can you please check 6853738 is what you suggested? I can squash and merge once approved.

Copy link
Member

@deivid-rodriguez deivid-rodriguez left a comment

Choose a reason for hiding this comment

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

鉂わ笍

- generates simple Rust extension skeleton
- currently based on magnus rust crate
- limit to only supported RubyGems
@simi simi enabled auto-merge December 21, 2022 08:49
@simi simi merged commit 742cc95 into master Dec 21, 2022
@simi simi deleted the rust-ext branch December 21, 2022 10:29
@deivid-rodriguez deivid-rodriguez changed the title Add --ext=rust support for simple Rust extension. Add --ext=rust support to bundle gem for simple Rust extension. Dec 21, 2022
@deivid-rodriguez deivid-rodriguez changed the title Add --ext=rust support to bundle gem for simple Rust extension. Add --ext=rust support to bundle gem for creating simple gems with Rust extensions Dec 21, 2022
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.

None yet

5 participants