Skip to content

framegrace/rules_ruby

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rules ruby

Build Status

Ruby rules for Bazel.

Status

Proof of Concept

How to use

Add ruby_register_toolchains into your WORKSPACE file

git_repository(
    name = "com_github_yugui_rules_ruby",
    remote = "https://github.com/yugui/rules_ruby.git",
    commit = "8378a0ba19ab7c6d751c440bc016d9af76da656c",
)

load("@com_github_yugui_rules_ruby//ruby:def.bzl", "ruby_register_toolchains")

ruby_register_toolchains()

Add ruby_library, ruby_binary or ruby_test into your BUILD.bazel files.

ruby_library(
  name = "foo",
  srcs = ["lib/foo.rb"],
  includes = ["lib"],
)

ruby_binary(
  name = "bar",
  srcs = ["bin/bar"],
  deps = [":foo"],
)

ruby_test(
  name = "foo_test",
  srcs = ["test/foo_test.rb"],
  deps = [":foo"],
)

Rules

ruby_library

ruby_library(name, deps, srcs, data, compatible_with, deprecation, distribs, features, licenses, restricted_to, tags, testonly, toolchains, visibility)
Attributes
name Name, required

A unique name for this rule.

srcs List of Labels, optional

List of .rb files.

At least srcs or deps must be present

deps List of labels, optional

List of targets that are required by the srcs Ruby files.

At least srcs or deps must be present

includes List of strings, optional

List of paths to be added to $LOAD_PATH at runtime. The paths must be relative to the the workspace which this rule belongs to.

rubyopt List of strings, optional

List of options to be passed to the Ruby interpreter at runtime.

NOTE: -I option should usually go to includes attribute.

And other common attributes

ruby_binary

ruby_binary(name, deps, srcs, data, main, compatible_with, deprecation, distribs, features, licenses, restricted_to, tags, testonly, toolchains, visibility, args, output_licenses)
Attributes
name Name, required

A unique name for this rule.

srcs List of Labels, required

List of .rb files.

deps List of labels, optional

List of targets that are required by the srcs Ruby files.

main Label, optional

The entrypoint file. It must be also in srcs.

If not specified, $(NAME).rb where $(NAME) is the name of this rule.

includes List of strings, optional

List of paths to be added to $LOAD_PATH at runtime. The paths must be relative to the the workspace which this rule belongs to.

rubyopt List of strings, optional

List of options to be passed to the Ruby interpreter at runtime.

NOTE: -I option should usually go to includes attribute.

And other common attributes

ruby_test

ruby_test(name, deps, srcs, data, main, compatible_with, deprecation, distribs, features, licenses, restricted_to, tags, testonly, toolchains, visibility, args, size, timeout, flaky, local, shard_count)
Attributes
name Name, required

A unique name for this rule.

srcs List of Labels, required

List of .rb files.

deps List of labels, optional

List of targets that are required by the srcs Ruby files.

main Label, optional

The entrypoint file. It must be also in srcs.

If not specified, $(NAME).rb where $(NAME) is the name of this rule.

includes List of strings, optional

List of paths to be added to $LOAD_PATH at runtime. The paths must be relative to the the workspace which this rule belongs to.

rubyopt List of strings, optional

List of options to be passed to the Ruby interpreter at runtime.

NOTE: -I option should usually go to includes attribute.

And other common attributes

bundle_install

Installs gems with Bundler, and make them available as a ruby_library.

Example: WORKSPACE:

git_repository(
    name = "com_github_yugui_rules_ruby",
    remote = "https://github.com/yugui/rules_ruby.git",
    commit = "8378a0ba19ab7c6d751c440bc016d9af76da656c",
)

load(
  "@com_github_yugui_rules_ruby//ruby:def.bzl",
  "ruby_register_toolchains",
  "bundle_install"
)

ruby_register_toolchains()

bundle_install(
  name = "gems",
  gemfile = "Gemfile",
  gemfile_lock = "Gemfile.lock",
)

Example: lib/BUILD.bazel:

ruby_library(
  name = "foo",
  srcs = ["foo.rb"],
  deps = ["@gems//:libs"],
)
bundle_install(name, gemfile, gemfile_lock)
Attributes
name Name, required

A unique name for this rule.

gemfile Label, required

The Gemfile which Bundler runs with.

gemfile_lock Label, required

The Gemfile.lock which Bundler runs with.

NOTE: This rule never updates the Gemfile.lock. It is your responsibility to generate/update Gemfile.lock

What's coming next

  1. Building native extensions in gems with Bazel
  2. Using a specified version of Ruby.
  3. Building and releasing your gems with Bazel

Copyright

Copyright 2018 Yuki Yugui Sonoda

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

Ruby rules for Bazel

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 82.3%
  • Ruby 9.9%
  • Shell 4.1%
  • Smarty 3.7%