Skip to content

envoy/rules_ruby

 
 

Repository files navigation

Ruby Rules for Bazel

Overview

This repository hosts Ruby language ruleset for Bazel.

The ruleset is known to work with:

  • Bazel 7 using WORKSPACE and Bzlmod (tested on CI);
  • Bazel 6 using WORKSPACE and Bzlmod (not tested on CI);
  • Bazel 5 using WORKSPACE (no longer tested on CI).

Getting Started

WORKSPACE

  1. Install the ruleset following WORKSPACE instructions on the latest release.
  2. Download and install Ruby:
# WORKSPACE
load("@rules_ruby//ruby:deps.bzl", "rb_register_toolchains")

rb_register_toolchains(
    version = "3.0.6",
    # alternatively, load version from .ruby-version file
    # version_file = "//:.ruby-version",
)
  1. (Optional) Download and install Bundler dependencies:
# WORKSPACE
load("@rules_ruby//ruby:deps.bzl", "rb_bundle")

rb_bundle(
    name = "bundle",
    srcs = ["//:Gemfile.lock"],
    gemfile = "//:Gemfile",
)
  1. Start defining your library, binary and test targets in BUILD files.

Bzlmod

  1. Install ruleset following Bzlmod instructions on the latest release.
  2. Download and install Ruby:
# 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")
  1. (Optional) Download and install Bundler dependencies:
# MODULE.bazel
ruby.bundle(
    name = "bundle",
    srcs = ["//:Gemfile.lock"],
    gemfile = "//:Gemfile",
    toolchain = "@ruby//:BUILD",
)
use_repo(ruby, "bundle", "ruby_toolchains")
  1. Register Ruby toolchains:
# MODULE.bazel
register_toolchains("@ruby_toolchains//:all")
  1. Start defining your library, binary and test targets in BUILD files.

Documentation

  • See repository rules for the documentation of WORKSPACE rules.
  • See rules for the documentation of BUILD rules.

Examples

See examples directory for a comprehensive set of examples how to use the ruleset.

Toolchains

The following toolchains are known to work and tested on CI.

Ruby Linux macOS Windows
MRI 3.3 🟩 🟩 🟩
MRI 3.2 🟩 🟩 🟩
MRI 3.1 🟩 🟩 🟩
MRI 3.0 🟩 🟩 🟩
JRuby 9.4 🟩 🟩 🟩
TruffleRuby 23.0 🟩 🟩 🟥

The following toolchains were previously known to work but no longer tested on CI.

Ruby Linux macOS Windows
MRI 2.7 🟩 🟩 🟩
JRuby 9.3 🟩 🟩 🟩
TruffleRuby 22.0 🟩 🟩 🟥

MRI

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.

JRuby

On all operating systems, JRuby is downloaded manually. It uses Bazel runtime Java toolchain as JDK.

TruffleRuby

On Linux and macOS, ruby-build is used to install TruffleRuby. Windows is not supported.

Other

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).

Known Issues

Packages

No packages published

Languages

  • Starlark 94.2%
  • Smarty 2.7%
  • Ruby 2.0%
  • Other 1.1%