Skip to content

Commit 08847a2

Browse files
cfeckardtkigster
authored andcommitted
Merging Coinbase PR: coinbase/rules_ruby#10
Feature: Add rb_gem and rb_gemspec
1 parent 65009d4 commit 08847a2

File tree

16 files changed

+330
-3
lines changed

16 files changed

+330
-3
lines changed

README.md

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* [ruby_binary](#ruby_binary)
99
* [ruby_test](#ruby_test)
1010
* [ruby_bundle](#ruby_bundle)
11+
* [ruby_gem](#rb_gem)
1112
* [What's coming next](#whats-coming-next)
1213
* [Contributing](#contributing)
1314
* [Setup](#setup)
@@ -483,11 +484,88 @@ ruby_bundle(name, gemfile, gemfile_lock, bundler_version = "2.1.2")
483484
</tbody>
484485
</table>
485486

487+
## rb_gem
488+
Used to generate a zipped gem containing its srcs, dependencies and a gemspec.
489+
490+
<pre>
491+
rb_gem(name, gem_name, version, srcs, authors, deps, data, includes)
492+
</pre>
493+
<table class="table table-condensed table-bordered table-params">
494+
<colgroup>
495+
<col class="col-param" />
496+
<col class="param-description" />
497+
</colgroup>
498+
<thead>
499+
<tr>
500+
<th colspan="2">Attributes</th>
501+
</tr>
502+
</thead>
503+
<tbody>
504+
<tr>
505+
<td><code>name</code></td>
506+
<td>
507+
<code>Name, required</code>
508+
<p>A unique name for this rule.</p>
509+
</td>
510+
</tr>
511+
<tr>
512+
<td><code>gem_name</code></td>
513+
<td>
514+
<code>Name of the gem, required</code>
515+
<p>The name of the gem to be generated.</p>
516+
</td>
517+
</tr>
518+
<tr>
519+
<tr>
520+
<td><code>version</code></td>
521+
<td>
522+
<code>Label, required</code>
523+
<p>
524+
The version of the gem. Is used to name the output file,
525+
which becomes <code>name-version.zip</code>, and also
526+
included in the Gemspec.
527+
</p>
528+
</td>
529+
</tr>
530+
<tr>
531+
<td><code>authors</code></td>
532+
<td>
533+
<code>List of Strings, required</code>
534+
<p>
535+
List of human readable names of the gem authors.
536+
Required to generate a valid gemspec.
537+
</p>
538+
</td>
539+
</tr>
540+
<tr>
541+
<td><code>srcs</code></td>
542+
<td>
543+
<code>List of Labels, optional</code>
544+
<p>
545+
List of <code>.rb</code> files.
546+
</p>
547+
<p>At least <code>srcs</code> or <code>deps</code> must be present</p>
548+
</td>
549+
</tr>
550+
<tr>
551+
<td><code>deps</code></td>
552+
<td>
553+
<code>List of labels, optional</code>
554+
<p>
555+
List of targets that are required by the <code>srcs</code> Ruby
556+
files.
557+
</p>
558+
<p>At least <code>srcs</code> or <code>deps</code> must be present</p>
559+
</td>
560+
</tr>
561+
</tbody>
562+
</table>
563+
486564
## What's coming next
487565

488566
1. Building native extensions in gems with Bazel
489567
2. Using a specified version of Ruby.
490-
3. Building and releasing your gems with Bazel
568+
3. Releasing your gems with Bazel
491569

492570
## Contributing
493571

WORKSPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,7 @@ ruby_bundle(
102102
gemfile = "//:Gemfile",
103103
gemfile_lock = "//:Gemfile.lock",
104104
)
105+
106+
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
107+
108+
rules_pkg_dependencies()

bin/test-suite

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,17 @@ test::buildifier() {
147147
test::simple-script() {
148148
__test::exec simple-script "
149149
cd examples/simple_script
150-
${Bazel__BuildSteps}
150+
${Bazel__BuildSteps}
151151
echo run :bin; bazel ${BAZEL_OPTS} run ${BAZEL_BUILD_OPTS} :bin
152152
echo run :rubocop; bazel ${BAZEL_OPTS} run ${BAZEL_BUILD_OPTS} :rubocop
153+
"
154+
}
153155

156+
# Builds and runs workspace inside examples/simple_script
157+
test::example-gem() {
158+
__test::exec example-gem "
159+
cd examples/example_gem
160+
echo bazel ${BAZEL_OPTS} build ...:all; bazel ${BAZEL_OPTS} build ...:all
154161
"
155162
}
156163

examples/example_gem/BUILD

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package(default_visibility = ["//:__subpackages__"])
2+
3+
load(
4+
"@bazelruby_ruby_rules//ruby:defs.bzl",
5+
"rb_gem",
6+
)
7+
8+
rb_gem(
9+
name = "default_gem",
10+
authors = ["Coinbase"],
11+
gem_name = "example_gem",
12+
version = "0.1.0",
13+
deps = [
14+
"//lib:example_gem",
15+
],
16+
)

examples/example_gem/WORKSPACE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
workspace(name = "bazelruby_ruby_rules_example_gem")
2+
3+
# Importing rules_ruby from the parent directory for developing
4+
# rules_ruby itself...
5+
local_repository(
6+
name = "bazelruby_ruby_rules",
7+
path = "../..",
8+
)
9+
10+
load(
11+
"@bazelruby_ruby_rules//ruby:deps.bzl",
12+
"ruby_register_toolchains",
13+
"ruby_rules_dependencies",
14+
)
15+
16+
ruby_rules_dependencies()
17+
18+
ruby_register_toolchains()
19+
20+
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
21+
22+
bazel_skylib_workspace()

examples/example_gem/lib/BUILD

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package(default_visibility = ["//:__subpackages__"])
2+
3+
load(
4+
"@bazelruby_ruby_rules//ruby:defs.bzl",
5+
"rb_library",
6+
)
7+
8+
rb_library(
9+
name = "example_gem",
10+
srcs = ["example_gem.rb"],
11+
deps = ["//lib/foo:default_library"],
12+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
require_relative 'foo/bar'
4+
5+
puts 'Foo'

examples/example_gem/lib/foo/BUILD

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package(default_visibility = ["//:__subpackages__"])
2+
3+
load(
4+
"@bazelruby_ruby_rules//ruby:defs.bzl",
5+
"rb_library",
6+
)
7+
8+
rb_library(
9+
name = "default_library",
10+
srcs = ["bar.rb"],
11+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# frozen_string_literal: true
2+
3+
module Foo
4+
class Bar
5+
def call
6+
puts 'Hello World'
7+
end
8+
end
9+
end

ruby/defs.bzl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,26 @@ load(
2424
"@bazelruby_ruby_rules//ruby/private/rubocop:def.bzl",
2525
_rubocop = "rubocop",
2626
)
27+
load(
28+
"@bazelruby_ruby_rules//ruby/private:gemspec.bzl",
29+
_gemspec = "rb_gemspec",
30+
)
31+
load(
32+
"@bazelruby_ruby_rules//ruby/private:gem.bzl",
33+
_gem = "rb_gem",
34+
)
2735

2836
ruby_toolchain = _toolchain
37+
2938
ruby_library = _library
3039
ruby_binary = _binary
3140
ruby_test = _test
3241
ruby_rspec_test = _ruby_rspec_test
3342
ruby_rspec = _ruby_rspec
3443
ruby_bundle = _ruby_bundle
3544
ruby_rubocop = _rubocop
45+
ruby_gemspec = _gemspec
46+
ruby_gem = _gem
3647

3748
rb_toolchain = _toolchain
3849
rb_library = _library
@@ -41,3 +52,5 @@ rb_test = _test
4152
rb_rspec = _ruby_rspec
4253
rb_bundle = _ruby_bundle
4354
rb_rubocop = _rubocop
55+
rb_gemspec = _gemspec
56+
rb_gem = _gem

0 commit comments

Comments
 (0)