Replies: 29 comments 1 reply
-
Seems like a nice idea. Just curious, is this something that could be written as a plugin? Or is building too tightly integrated into the core? If it can be made as a plugin, maybe it would be best to refactor all of the rubygems builders as plugins so they could be installed as needed, and more easily maintained, while reducing the burden on core rubygems itself. |
Beta Was this translation helpful? Give feedback.
-
@djberg96 That could potentially work. The problem I see is that if the plug-in is not bundled by default, it could be burdensome for the end-user (installer-of-gem) if they had to remember to do something like We could perhaps have a git-submodule which is hosted elsewhere if this proves to be too burdensome on rubygems maintainers. I'd be interested to hear input from someone from the Cargo team on this. Maybe @alexcrichton could chime in 😀 |
Beta Was this translation helpful? Give feedback.
-
I suspect that something like this would be best to start out in the community, and if it becomes large enough and is agreed it should become official, this seems reasonable to host in the rust-lang organization and have a team of maintainers there (not necessarily the same set as cargo maintainers!). I suspect though we'd want support for something like this to bake in the ecosystem a bit before adding to rust-lang though. |
Beta Was this translation helpful? Give feedback.
-
@ianks I dunno, doesn't seem that burdensome to me, plus it would allow you full control over the code without having to get permission from the core rubygems team for every PR. Then once it's stable, we could consider merging into core. |
Beta Was this translation helpful? Give feedback.
-
@ianks Hi, I welcome to cargo builder to rubygems. But I'm not familiar with rust-lang. Can you provide the patch for this? Thanks. |
Beta Was this translation helpful? Give feedback.
-
Yes @hsbt I will look into this ASAP |
Beta Was this translation helpful? Give feedback.
-
I think this is a great idea. I just had all sorts of issues publishing a Helix-powered gem to rubygems due to gemspec templating problems. The rindy gem is a Ruby wrapper for the Hyperledger Indy SDK. Testing the gem locally, then to github-based deployment (in Gemfile), then to rubygems.org was a headache. |
Beta Was this translation helpful? Give feedback.
-
I reached out to @malept to see if they are interested in porting parts of https://github.com/malept/thermite directly into rubygems. I think this would be the best way to tackle the v1. Let's give it a week or so to see if they respond. |
Beta Was this translation helpful? Give feedback.
-
It's been a couple of weeks now so I'm going to assume that @malept may be too busy to do this right now. Does anyone want to tackle this issue? As mentioned earlier, https://github.com/malept/thermite is a great piece of prior art to reference, and we have support from some Rust developers to help review and make sure things are tidy. If you are interested, or know someone who may be, drop a comment here 😁 |
Beta Was this translation helpful? Give feedback.
-
Not directly apropos, but I have experience in Rust, and I've been using Ruby/Rails for a few months on the job now. I would like to participate and help out in this effort, whichever form it might take. |
Beta Was this translation helpful? Give feedback.
-
Maybe it would be easier to addd support of Rust into https://github.com/rake-compiler/rake-compiler, it seems that this gem already allows to easily build either C or Java extensions through coc approach. |
Beta Was this translation helpful? Give feedback.
-
@timmyjose Thank you for volunteering! 🙏🏻If you run into any road blocks, please post here and we’ll do best to make sure you get unblocked. |
Beta Was this translation helpful? Give feedback.
-
Long time Ruby user with several years of Rust experience (and an MRI commit) here, would love to help make this happen. |
Beta Was this translation helpful? Give feedback.
-
@tarcieri thank for volunteering! Since multiple people have volunteered, and I would hate to see this work duplicated, can someone commit to PRing the initial integration for the extension builder? After that, I think there are a few things we can do to make this experience more seamless for gem builders.
As you can see, there's plenty of exciting work here to go around. 😀 |
Beta Was this translation helpful? Give feedback.
-
I'm happy to take a backseat to anyone wanting to jump in right away. I can help review PRs, though. If there's one of the above items that no one wants to take on, I'd be happy to work on one of those. |
Beta Was this translation helpful? Give feedback.
-
I'd love to take a crack at Any suggestions where to get started? Which of the existing Rusty gem should I use as a sort of "template"? Any of them a "better" candidate than the others (and by "Better" I mean: more generic, more templatateable, etc.)? |
Beta Was this translation helpful? Give feedback.
-
If you'd like input on any WIP code you have for this I'm here. I'm the author of FasterPath and maintainer of Rutie. If you look at older FasterPath versions in the git history you can find builds pre Thermite. It was more of a hacky work around just to get it to work as I initially had a lot of trouble going the RakeBuilder route. And if I may suggest a different design pattern if Thermite code is being ported over… I would much prefer the composition pattern rather than the heavily coupled mixins currently being used. |
Beta Was this translation helpful? Give feedback.
-
Obviously from my lack of response, I haven't had a lot of time to devote to Rust/Ruby integration. However, I am happy to provide observations from my experiences and/or code review. I want to be clear that the primary use case for Thermite for me is to provide a transparent way to provide native extensions written in Rust for different platforms. I do not want to expect users of my Rust-written gems to have to install Rust/Cargo in order to utilize my gem in their app. If this sort of "binary cache" feature can be added to
This (and the initial comments about it on the Thermite issue tracker) are part of the reason why Thermite hasn't seen much development as of late. |
Beta Was this translation helpful? Give feedback.
-
@malept I apologize for my inconsiderate bikeshedding. Design patterns are very much subjective and I was inconsiderate towards you and the good work that you have done. Please forgive me. |
Beta Was this translation helpful? Give feedback.
-
This is incredibly important feature IMO. Thanks for highlighting that @malept. I'm hoping rake-compiler + |
Beta Was this translation helpful? Give feedback.
-
Ok, I did a quick mockup of what this might look like. (I also put together a quick demo gem) You can test this yourself:
Note that this will invoke If I understand correctly, Gem::Ext::Builder is only invoked during the gem installation process? Isn't something like I'll keep poking at Thermite but welcome any feedback in the meantime. |
Beta Was this translation helpful? Give feedback.
-
Great stuff @qubitrenegade! I'll test it out locally when I get a chance. As a general question, how should we handle linking? Should we link all the libraries that are typically linked when compiling a C extension? |
Beta Was this translation helpful? Give feedback.
-
The happy path for Rust is having Cargo handle linking The shortest path to victory for embedding Rust is having Cargo produce a static library The latter is probably the best place to start |
Beta Was this translation helpful? Give feedback.
-
From @tarcieri’s comment, I think it’s safe to say we should instruct cargo to link |
Beta Was this translation helpful? Give feedback.
-
What's the status on this so far? |
Beta Was this translation helpful? Give feedback.
-
If you have read this ticket, you know as much as anyone else does. |
Beta Was this translation helpful? Give feedback.
-
It looks like the work from @qubitrenegade is a good starting place, even if it requires cargo be installed on the users system. Where would be go from here? Is there a plan to upstream this work? |
Beta Was this translation helpful? Give feedback.
-
I'm not really sure what I'm doing, but I added some tests for building a minimal cargo project. I based it off of @qubitrenegade's branch and the existing There were some complications with bundler overwriting the |
Beta Was this translation helpful? Give feedback.
-
Any updates on this front? It's an exciting project with a lot of promises! |
Beta Was this translation helpful? Give feedback.
-
Over the past few years, Rust has proven to be an incredibly stable and accessible option for those wishing to write native extensions for Ruby. Rust is particularly well-suited for Ruby for a few reasons:
extern C
.One of the biggest pain points of creating a Gem with a Rust extension is integrating with
Gem::Ext::Builder
. There are currently a couple of solutions, and the rely on theRakeBulider
interface. I have personally used https://github.com/malept/thermite, which is a very good solution, but still requires and external dependency and does not integrate as well as native builders at the moment.Currently, Gem::Ext::Builder supports four builder types:
ExtConfBuilder
,ConfigureBuilder
,RakeBuilder
, andCmakeBuilder
. I propose we add a new builder,CargoBuilder
, which will detect aCargo.toml
file and build the gem native extensions usingcargo
. This ease the burden of developing and publishing Rust extensions for Ruby users.Potential Problems
If the user does not have cargo installed, building the extension will not work.
This is an issue, but is also an issue for the
CmakeBuilder
. One way to mitigate this issue would be to make it easier to build static binaries for Rust extensions.The lack of a standard ruby interface for Rust extensions might cause pain for developers.
Currently, many folks use https://github.com/steveklabnik/ruby-sys to interface with the C ruby API. It might make sense to make this "officially" supported at some point, but I don't think it has to be done immediately.
Please let me know your thoughts. I would be very excited to see Ruby take this step. I don't think I know enough about the Ruby extension building process or the Rust compilation process to actually implement this, so hopefully we could find a volunteer to step up. Thanks for reading :)
Notable Gems using Rust
Beta Was this translation helpful? Give feedback.
All reactions