Skip to content

Latest commit

 

History

History
117 lines (79 loc) · 5.13 KB

repository_rules.md

File metadata and controls

117 lines (79 loc) · 5.13 KB

Public API for repository rules

rb_bundle_rule

rb_bundle_rule(name, env, gemfile, repo_mapping, srcs, toolchain)

Installs Bundler dependencies and registers an external repository that can be used by other targets.

WORKSPACE:

load("@rules_ruby//ruby:deps.bzl", "rb_bundle")

rb_bundle(
    name = "bundle",
    gemfile = "//:Gemfile",
    srcs = [
        "//:gem.gemspec",
        "//:lib/gem/version.rb",
    ]
)

All the installed gems can be accessed using @bundle target and additionally gems binary files can also be used:

BUILD:

load("@rules_ruby//ruby:defs.bzl", "rb_binary")

package(default_visibility = ["//:__subpackages__"])

rb_binary(
    name = "rubocop",
    main = "@bundle//:bin/rubocop",
    deps = ["@bundle"],
)

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this repository. Name required
env Environment variables to use during installation. Dictionary: String -> String optional {}
gemfile Gemfile to install dependencies from. Label optional None
repo_mapping A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<p>For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target). Dictionary: String -> String required
srcs List of Ruby source files used to build the library. List of labels optional []
toolchain - Label required

rb_bundle

rb_bundle(toolchain, kwargs)
Wraps `rb_bundle_rule()` providing default toolchain name.

PARAMETERS

Name Description Default Value
toolchain default Ruby toolchain BUILD "@ruby//:BUILD"
kwargs underlying attrs passed to rb_bundle_rule() none

rb_register_toolchains

rb_register_toolchains(name, version, version_file, register, kwargs)
Register a Ruby toolchain and lazily download the Ruby Interpreter.
  • (For MRI on Linux and macOS) Installed using ruby-build.
  • (For MRI on Windows) Installed using RubyInstaller.
  • (For JRuby on any OS) Downloaded and installed directly from official website.
  • (For TruffleRuby on Linux and macOS) Installed using ruby-build.
  • _(For "system") Ruby found on the PATH is used. Please note that builds are not hermetic in this case.

WORKSPACE:

load("@rules_ruby//ruby:deps.bzl", "rb_register_toolchains")

rb_register_toolchains(
    version = "3.0.6"
)

PARAMETERS

Name Description Default Value
name base name of resulting repositories, by default "rules_ruby" "ruby"
version a semver version of MRI, or a string like [interpreter type]-[version], or "system" None
version_file .ruby-version or .tool-versions file to read version from None
register whether to register the resulting toolchains, should be False under bzlmod True
kwargs additional parameters to the downloader for this interpreter type none