This repository hosts Ruby language ruleset for Bazel.
The ruleset is known to work with:
The fastest way to try this in an empty project is to click the green "Use this template" button on https://github.com/bazel-starters/ruby.
# WORKSPACE
load("@rules_ruby//ruby:deps.bzl", "rb_register_toolchains")
rb_register_toolchains(
version = "3.3.9",
# alternatively, load version from .ruby-version file
# version_file = "//:.ruby-version",
)
# WORKSPACE
load("@rules_ruby//ruby:deps.bzl", "rb_bundle_fetch")
rb_bundle_fetch(
name = "bundle",
gemfile = "//:Gemfile",
gemfile_lock = "//:Gemfile.lock",
)
BUILD files.# MODULE.bazel
ruby = use_extension("@rules_ruby//ruby:extensions.bzl", "ruby")
ruby.toolchain(
name = "ruby",
version = "3.0.6",
# alternatively, load version from .ruby-version file
# version_file = "//:.ruby-version",
)
use_repo(ruby, "ruby")
# MODULE.bazel
ruby.bundle_fetch(
name = "bundle",
gemfile = "//:Gemfile",
gemfile_lock = "//:Gemfile.lock",
)
use_repo(ruby, "bundle", "ruby_toolchains")
# MODULE.bazel
register_toolchains("@ruby_toolchains//:all")
BUILD files.WORKSPACE rules.BUILD rules.See examples directory for a comprehensive set of examples how to use the ruleset.
The following toolchains are known to work and tested on CI.
| Ruby | Linux | macOS | Windows |
|---|---|---|---|
| MRI 4.0 | 🟩 | 🟩 | 🟩 |
| MRI 3.4 | 🟩 | 🟩 | 🟩 |
| MRI 3.3 | 🟩 | 🟩 | 🟩 |
| MRI 3.2 | 🟩 | 🟩 | 🟩 |
| JRuby 10.0 | 🟩 | 🟩 | 🟩 |
| TruffleRuby 33.0 | 🟩 | 🟩 | 🟥 |
The following toolchains were previously known to work but no longer tested on CI.
| Ruby | Linux | macOS | Windows |
|---|---|---|---|
| MRI 3.1 | 🟩 | 🟩 | 🟩 |
| MRI 3.0 | 🟩 | 🟩 | 🟩 |
| MRI 2.7 | 🟩 | 🟩 | 🟩 |
| JRuby 9.4 | 🟩 | 🟩 | 🟩 |
| JRuby 9.3 | 🟩 | 🟩 | 🟩 |
| TruffleRuby 25.0 | 🟩 | 🟩 | 🟥 |
| TruffleRuby 24.0 | 🟩 | 🟩 | 🟥 |
| TruffleRuby 23.0 | 🟩 | 🟩 | 🟥 |
| TruffleRuby 22.0 | 🟩 | 🟩 | 🟥 |
On Linux and macOS, ruby-build is used to install MRI from sources. Keep in mind, that it takes some time for compilation to complete.
On Windows, RubyInstaller is used to install MRI.
For faster MRI installation on Linux and macOS, you can use portable Ruby binaries from bazel-contrib/portable-ruby instead of compiling from source. This significantly reduces installation time and ensures consistent, portable Ruby environments.
To enable portable Ruby, set portable_ruby = True in your toolchain declaration:
ruby = use_extension("@rules_ruby//ruby:extensions.bzl", "ruby")
ruby.toolchain(
name = "ruby",
portable_ruby = True,
version_file = "//:.ruby-version",
)
This ruleset ships with default checksums to securely download and properly cache
the Ruby binaries. If you want to use Ruby version not available with ruleset release,
you should use portable_ruby_release_suffix and portable_ruby_checksums attribute.
We have provided the generate_portable_ruby_checksums utility to add/update these
attributes for you. The utility needs to know the version of Ruby to download.
By default, it will use the Ruby version specified in the .ruby-version file.
bazel run @rules_ruby//tools/generate_portable_ruby_checksums -- 3.4.8
After running the utility, the toolchain declaration in your MODULE.bazel
should look something like the following:
ruby = use_extension("@rules_ruby//ruby:extensions.bzl", "ruby")
ruby.toolchain(
name = "ruby",
version_file = "//:.ruby-version",
portable_ruby = True,
portable_ruby_release_suffix = "2", # default is 1
portable_ruby_checksums = {
"ruby-3.2.8.arm64_darwin.tar.gz": "4b5343a5513523409b4cc1b285ebaeb75356c758080e45d99f506a827492a8fb",
"ruby-3.4.8.arm64_linux.tar.gz": "8348296d8148acbc6e5a170861810b693fb6ea72e1d59cc7b82f0369bffa9870",
"ruby-3.2.8.x86_64_darwin.tar.gz": "75b72e64e42bb36a80e3382751c74bfe379efcf28880ed3c4c86657cac9d8462",
"ruby-3.2.8.x86_64_linux.tar.gz": "2a2f40774634abed8eb32b762b8f440f85c6add74b5c14f28e70b42f49537464",
},
)
Notes:
portable_ruby = True has no effect on JRuby, TruffleRuby, or Windows.On all operating systems, JRuby is downloaded manually. It uses Bazel runtime Java toolchain as JDK. JRuby is currently the only toolchain that supports Remote Build Execution.
On Linux and macOS, ruby-build is used to install TruffleRuby. Windows is not supported.
On Linux and macOS, you can potentially use any Ruby distribution that is supported by ruby-build. However, some are known not to work or work only partially (e.g. mRuby has no bundler support).
HOME variable exposed.
See examples/gem/.bazelrc to learn how to do that.
This is to be fixed in jruby/jruby#5661 and oracle/truffleruby#2784.Errno::EACCES: Permission denied - NUL error on Windows.
You need to configure JDK to allow proper access.
This is described in jruby/jruby#7182.LoadError on Windows.
This is fixed in rubocop/rubocop#12062.bazel test.
To work it around, use a debugger with remote client support such as ruby/debug .
See examples/gem/.bazelrc to learn how to do that.link or target filename contains space.
To work it around, use --experimental_inprocess_symlink_creation Bazel flag.
See bazelbuild/bazel#4327 for more details.Ruby rules support Bazel's native coverage collection using SimpleCov and simplecov-lcov.
[!NOTE] Code coverage is currently not supported on Windows.
To enable coverage:
simplecov and simplecov-lcov gems to your Gemfile.coverage command:bazel coverage //...
The rules automatically configure SimpleCov to use the LCOV formatter and output reports to the location expected by Bazel. Coverage reports will have workspace-relative paths, allowing Bazel to aggregate results from multiple targets.
For JRuby, coverage requires --debug mode, which is automatically enabled by the rules when coverage is requested.
You can add additional coverage filters using coverage_filters attribute in rb_test or rb_binary:
rb_test(
name = "my_test",
...
coverage_filters = ["/vendor/", "/custom/"],
)
0.25.0 +1.0mo2026-04-27 | |
0.24.0 +16d2026-03-28 | |
0.23.1 +7d2026-03-11 | |
0.23.0 +6d2026-03-04 | |
0.22.1 +4.6mo2026-02-25 | |
0.21.1 +3.2mo2025-10-09 | |
0.18.0 +1.0mo2025-03-25 | |
0.17.2 +23d2025-02-18 | |
0.17.0 +1.0mo2025-01-26 | |
0.16.0 +2d2024-12-25 | |
0.15.1 +25d2024-12-23 | |
0.14.1 +1d2024-11-27 | |
0.14.0 +25d2024-11-25 | |
0.13.0 +14d2024-10-31 | |
0.12.2 +2.8mo2024-10-17 | |
0.12.1 +6d2024-07-24 | |
0.12.0 +1.5mo2024-07-18 | |
0.11.0 +27d2024-06-03 | |
0.10.0 +1.5mo2024-05-07 | |
0.9.1 +15d2024-03-22 | |
0.8.1 +22h2024-03-06 | |
0.8.0 +1.2mo2024-03-05 | |
0.6.0 +10d2024-01-29 | |
0.5.0 +1.5mo2024-01-18 | |
0.4.1 +3d2023-12-04 | |
0.3.0 +3d2023-11-30 | |
0.2.02023-11-27 |