| Build | Status |
|---|---|
| CircleCI Develop: | |
| CircleCI Default: | |
| Develop: | |
| Master: |
Ruby rules for Bazel.
Work in progress.
We have a guide on Building your first Ruby Project on the Wiki. We encourage you to check it out.
Add ruby_rules_dependencies and ruby_register_toolchains into your WORKSPACE file.
# To get the latest, grab the 'develop' branch.
git_repository(
name = "bazelruby_ruby_rules",
remote = "https://github.com/bazelruby/rules_ruby.git",
branch = "develop",
)
load(
"@bazelruby_ruby_rules//ruby:deps.bzl",
"ruby_register_toolchains",
"ruby_rules_dependencies",
)
ruby_rules_dependencies()
ruby_register_toolchains()Add ruby_library, ruby_binary or ruby_test into your BUILD.bazel files.
load(
"@bazelruby_ruby_rules//ruby:defs.bzl",
"ruby_binary",
"ruby_library",
"ruby_test",
)
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"],
)The following diagram attempts to capture the implementation behind ruby_library that depends on the result of bundle install, and a ruby_binary that depends on both:
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 At least |
deps |
List of labels, optional
List of targets that are required by the At least |
includes |
List of strings, optional
List of paths to be added to |
rubyopt |
List of strings, optional
List of options to be passed to the Ruby interpreter at runtime.
NOTE: |
| And other common attributes | |
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 |
deps |
List of labels, optional
List of targets that are required by the |
main |
Label, optional
The entrypoint file. It must be also in If not specified, |
includes |
List of strings, optional
List of paths to be added to |
rubyopt |
List of strings, optional
List of options to be passed to the Ruby interpreter at runtime.
NOTE: |
| And other common attributes | |
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 |
deps |
List of labels, optional
List of targets that are required by the |
main |
Label, optional
The entrypoint file. It must be also in If not specified, |
includes |
List of strings, optional
List of paths to be added to |
rubyopt |
List of strings, optional
List of options to be passed to the Ruby interpreter at runtime.
NOTE: |
| And other common attributes | |
Installs gems with Bundler, and make them available as a ruby_library.
Example: WORKSPACE:
git_repository(
name = "bazelruby_ruby_rules",
remote = "https://github.com/bazelruby/rules_ruby.git",
tag = "v0.1.0",
)
load(
"@bazelruby_ruby_rules//ruby:deps.bzl",
"ruby_register_toolchains",
"ruby_rules_dependencies",
)
ruby_rules_dependencies()
ruby_register_toolchains()
load("@bazelruby_ruby_rules//ruby:defs.bzl", "bundle_install")
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_lock |
Label, required
The NOTE: This rule never updates the |
- Building native extensions in gems with Bazel
- Using a specified version of Ruby.
- Building and releasing your gems with Bazel
We welcome contributions to RulesRuby. Please make yourself familiar with the CODE_OF_CONDUCT document.
You may notice that there is more than one Bazel WORKSPACE inside this repo. There is one in examples/simple_script for instance, because
we use this example to validate and test the rules. So be mindful whether your current directory contains WORKSPACE file or not.
You will need Homebrew installed prior to running the script.
After that, cd into the top level folder and run the setup script in your Terminal:
❯ bin/setupThis runs a complete setup, shouldn't take too long. You can explore various script options with the help command:
❯ bin/setup help
USAGE
# without any arguments runs a complete setup.
bin/setup
# alternatively, a sub-setup function name can be passed:
bin/setup [ gems | git-hook | help | os-specific | main | remove-git-hook ]
DESCRIPTION:
Runs full setup without any arguments.
Accepts one optional argument — one of the actions that typically run
as part of setup, with one exception — remove-git-hook.
This action removes the git commit hook installed by the setup.
EXAMPLES:
bin/setup — runs the entire setup.Note that the setup contains os-specific section. This is because there are two extension scripts:
bin/setup-linuxbin/setup-darwin
Those will install Bazel and everything else you need on either platform. In fact, we use the linux version on CI.
Please report any errors to bin/setup as Issues on Github. You can assign them to @kigster.
Besides making yourself familiar with the existing code, and Bazel documentation on writing rules, you might want to follow this order:
- Setup dev tools as described in the setup section.
- hack, hack, hack...
- Make sure all tests pass — you can run a single command for that (but see more on it below.
```bash
bin/test-suite
```
OR you can run individual Bazel test commands from the inside.
bazel test //...cd examples/simple_script && bazel test //...
- Open a pull request in Github, and please be as verbose as possible in your description.
In general, it's always a good idea to ask questions first — you can do so by creating an issue.
After running setup, and since this is a bazel repo you can use Bazel commands:
bazel build //...:all
bazel query //...:all
bazel test //...:allBut to run tests inside each sub-WORKSPACE, you will need to repeat that in each sub-folder. Luckily, there is a better way.
This script runs all tests (including sub-workspaces) when ran without arguments:
bin/test-suiteRun it with help command to see other options, and to see what parts you can run individually. At the moment they are:
# alternatively, a partial test name can be passed:
bin/test-suite [ all | bazel-info | buildifier | help | rspec | rubocop | simple-script | workspace ]On a MacBook Pro it takes about 3 minutes to run.
We are using RuboCop for ruby and Buildifier for Bazel. Both are represented by a single script bin/linter, which just like the scripts above runs ALL linters when ran without arguments, accepts help commnd, and can be run on a subset of linting strategies:
bin/linterThe following are the partial linting functions you can run:
# alternatively, a partial linter name can be passed:
bin/linter [ all | buildifier | help | rubocop ]© 2018-2019 Yuki Yugui Sonoda & BazelRuby Authors
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.
