-
Notifications
You must be signed in to change notification settings - Fork 17
feat: add rv-ruby support for prebuilt Ruby binaries #280
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
20dbda2 to
ba0c47f
Compare
p0deje
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working on this. It's amazing to finally see the precompiled Rubies land in rules_ruby. The code looks great to me overall, and I'll be happy to merge it as-is, especially since it's opt-in. I only have a few questions to clarify:
- How much effort would it take to make toolchains work for different platforms? E.g., make the same
rb_downloadautomatically download Ruby for the target platform. This would be handy in remote builds where the host can be macOS, while the target is Linux. - Would it be possible to fetch all prebuilt Ruby checksums and put them in a file (like
ruby/private/bundler_checksums.bzl)? This could be a first step to make prebuilt Rubies be used by default. We should, of course, keeprv_checksumsandrv_versionattributes for anyone who needed fresh/custom versions of Ruby. - What happens when we try to install prebuilt gems (e.g.,
date) on prebuilt Ruby? Does it error? - If we really should skip installing prebuilt gems, do you think we should create
excluded_gems.bzlthat keeps a map of Ruby version to prebuilt gems list? This can be automatically picked up byrb_bundle_fetch()so that users don't have to think twice about configuring theexcluded_gemsattribute.
Add support for installing prebuilt Ruby binaries from the rv-ruby project (https://github.com/spinel-coop/rv-ruby) using a version prefix format `rv-{release}-{ruby_version}`. New features: - `checksums` attribute for `ruby.toolchain()` to specify platform SHA256 checksums for rv-ruby downloads - `excluded_gems` attribute for `ruby.bundle_fetch()` to skip downloading default gems bundled with Ruby (e.g., psych) The rv-ruby approach provides faster, more reliable builds by using prebuilt portable Ruby binaries instead of compiling from source via ruby-build. Also updates the rails example to use rv-ruby and pins minitest to 5.x for Rails 8.0.x compatibility. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
Refactor rv-ruby support to use a cleaner API that maintains
compatibility with standard Ruby version files.
Changes:
- Replace `rv-{release}-{version}` version prefix with separate
`rv_version` attribute for the rv-ruby release date
- Rename `checksums` to `rv_checksums` for clarity
- Support reading Ruby version from `.ruby-version` file, which
remains compatible with rbenv, RuboCop, StandardRB, etc.
- Add Windows fallback: prints warning and uses RubyInstaller
when rv_version is set on Windows
New API:
```starlark
ruby.toolchain(
name = "ruby",
version_file = "//:.ruby-version", # contains "3.4.8"
rv_version = "20251225",
rv_checksums = { ... },
)
```
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <[email protected]>
Replace uname -m command execution with Bazel's native repository_ctx.os.arch for more reliable and portable architecture detection in rv-ruby installation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Remove redundant OS and architecture validation checks in favor of a single validation point against _RV_RUBY_PLATFORMS. This eliminates duplicate logic and provides comprehensive error messages showing detected platform, raw values, and all supported platforms when validation fails. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Document the nested directory structure of rv-ruby releases to clarify why stripPrefix is needed and make future maintenance easier if the tarball structure changes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Unpack registration tuple in two steps to keep all lines under 80 characters, improving readability and conforming to code style guidelines. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Add comprehensive documentation for rv-ruby prebuilt binaries as a faster alternative to compiling MRI from source. Includes: - WORKSPACE and Bzlmod configuration examples - Critical guidance on excluding default gems with C extensions - Platform support notes and Windows fallback behavior - Links to stdgems.org for finding default gems per Ruby version Also applies code formatting improvements (italics, table alignment, list style). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
0432837 to
89f4706
Compare
How would the Linux Ruby binaries be used in this scenario?
I considered this. That would require pinning rules_ruby to an rv-ruby release. It would be convenient for the out-of-the-box experience, but could be confusing when trying to upgrade to the latest and greatest. One thought that I considered was to implement a utility that generates the checksums for you based upon the rv-ruby version provided. I did something similar for buildifier-prebuilt. We can add this as a follow-on, if there is interest.
I saw version mismatch errors and I saw compilation errors.
This is a similar issue as the checksums. Perhaps, we should create a utility that generates the declarations based upon the Ruby version. |
Summary
checksumsattribute toruby.toolchain()for platform-specific SHA256 verificationexcluded_gemsattribute toruby.bundle_fetch()to skip downloading default gems bundled with RubyUsage
Performance Comparison
To evaluate the performance benefits of this change, the following command was run from the
examples/railsdirectory five times:The results were averaged and a percent diff was calcuated.
Note
For each test case (i.e., row in the table), the first execution of the test command was discarded. The intention of the tests was to measure the performance with the repository cache and disk cache being populated.
Commentary
There are several wins by using
rv-provided Ruby binaries vs building them using ruby build.rv, any build/test actions that depend on the toolchain are valid on subsequent runs. In other words, rebuilding Ruby from source invalidates the build graph.🤖 Generated with Claude Code
Related Slack thread.
Blocked by #281.