Skip to content

Commit ed02dca

Browse files
committed
Basic ruby support.
1 parent d1d7566 commit ed02dca

File tree

8 files changed

+66
-74
lines changed

8 files changed

+66
-74
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ Bazel | rules_protobuf | gRPC |
1212

1313
| Language | Compile (1) | Build (2) | gRPC (3) |
1414
| ------------------------ | ------------ | ----------- | -------- |
15-
| [C++][cpp] | [cc_proto_compile][cpp] | [cc_proto_library][cpp] | yes |
15+
| [C++][cpp] | [cc_proto_compile][cpp] | [cc_proto_library][cpp] | yes |
1616
| [C#](bzl/csharp) | | | |
17-
| [Go][go] | [go_proto_compile][go] | [go_proto_library][go] | yes |
18-
| [Java][java] | [java_proto_compile][java] | [java_proto_library][java] | yes |
19-
| [JavaNano][javanano] | [android_proto_compile][javanano] | [android_proto_library][javanano] | yes |
17+
| [Go][go] | [go_proto_compile][go] | [go_proto_library][go] | yes |
18+
| [Java][java] | [java_proto_compile][java] | [java_proto_library][java] | yes |
19+
| [JavaNano][javanano] | [android_proto_compile][javanano] | [android_proto_library][javanano] | yes |
2020
| [Javascript](bzl/js) | | | |
2121
| [Objective-C](bzl/objc) | | | |
22-
| [Python](bzl/python) | | | |
23-
| [Ruby](bzl/ruby) | | | |
24-
| [gRPC gateway][grpc-gateway-home] | [grpc_gateway_proto_compile][grpc_gateway] | [grpc_gateway_proto_library][grpc_gateway] | yes |
22+
| [Python](bzl/python) | [py_proto_compile][python] | | |
23+
| [Ruby](bzl/ruby) | [py_proto_compile][ruby] | | |
24+
| [gRPC gateway][grpc-gateway-home] | [grpc_gateway_proto_compile][grpc_gateway] | [grpc_gateway_proto_library][grpc_gateway] | yes |
2525

2626
1. Support for generation of protobuf classes via the `protoc` tool.
2727
2. Support for generation + compilation of outputs with protobuf dependencies.
@@ -268,5 +268,7 @@ Contributions welcome; please create Issues or GitHub pull requests.
268268
[go]: bzl/go
269269
[java]: bzl/java
270270
[javanano]: bzl/javanano
271+
[python]: bzl/python
272+
[ruby]: bzl/ruby
271273
[grpc_gateway]: bzl/grpc_gateway
272274
[repositories.bzl]: bzl/repositories.bzl

bzl/csharp/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
# `rules_protobuf` C# Support
22

3-
Not currently supported; contributions welcome.
3+
4+
| Rule | Description |
5+
| --- | --- |
6+
| `csharp_proto_library` | Generates and compiles protobuf source files. |
7+
8+
Support for C# is limited to the proto_compile rule. Semantics are
9+
identical to `cc_proto_compile`.

bzl/python/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# `rules_protobuf` Python Support
2+
3+
4+
| Rule | Description |
5+
| --- | --- |
6+
| `python_proto_library` | Generates and compiles protobuf source files. |
7+
8+
Support for python is limited to the proto_compile rule. Semantics are
9+
identical to `cc_proto_compile`.

bzl/ruby/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
# `rules_protobuf` Ruby Support
22

3-
Not currently supported; contributions welcome.
3+
4+
| Rule | Description |
5+
| --- | --- |
6+
| `ruby_proto_library` | Generates and compiles protobuf source files. |
7+
8+
Support for ruby is limited to the proto_compile rule. Semantics are
9+
identical to `cc_proto_compile`.

bzl/ruby/class.bzl

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
11
load("//bzl:base/class.bzl", BASE = "CLASS")
22

3-
CLASS = struct(
4-
name = "ruby",
5-
short_name = "ruby",
3+
def ruby_library(**kwargs):
4+
"""Dummy implementation."""
5+
pass
6+
67

7-
protobuf = struct(
8-
file_extensions = [".pb.rb"],
9-
compile_deps = [
10-
],
11-
requires = [
12-
"protobuf",
13-
"external_protobuf_clib",
14-
],
15-
),
8+
CLASS = struct(
9+
parent = BASE,
10+
name = "ruby",
1611

17-
grpc = struct(
18-
executable = "//external:protoc_gen_grpc",
19-
name = "protoc-gen-grpc",
20-
file_extensions = [".grpc.pb.rb"],
21-
requires = [
22-
],
23-
compile_deps = [
24-
],
25-
),
12+
protobuf = struct(
13+
file_extensions = ["_pb.rb"],
14+
compile_deps = [],
15+
),
2616

17+
library = ruby_library,
2718
)

bzl/ruby/rules.bzl

Lines changed: 10 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,13 @@
1-
def pre(lang, ctx, gendir, args, srcs, requires, provides):
1+
load("//bzl:base/rules.bzl", "proto_library")
2+
load("//bzl:protoc.bzl", "implement")
3+
load("//bzl:ruby/class.bzl", RUBY = "CLASS")
24

3-
if (lang.plugin_outdir_hook):
4-
outdir = lang.plugin_out_hook(lang, ctx, gendir)
5-
else:
6-
outdir = gendir
5+
SPEC = [RUBY]
76

8-
# Default language options
9-
plugin_args = lang.plugin_args
7+
ruby_proto_compile = implement(SPEC)
108

11-
# Options specified in context
12-
plugin_args += getattr(ctx.attr, "gen_" + lang + "_args")
13-
14-
# if opts:
15-
# plugin_args = ",".join(opts) + ":" + plugin_args
16-
17-
# Configure plugin definition if defined
18-
if lang.plugin_binary:
19-
plugin_exe_name = "gen_" + lang.name + "_plugin"
20-
plugin_exe = getattr(ctx.attr, plugin_exe_name)
21-
if not plugin_exe:
22-
fail("Undefined plugin executable", plugin_exe_name)
23-
args += ["--plugin=%s=%s" % (lang.plugin_name, lang.plugin_exe.path)]
24-
25-
# Configure plugin for this language
26-
args += ["--%s_out=%s:%s" % (lang.name, lang.plugin_name, plugin_args, outdir.path)]
27-
28-
for srcfile in ctx.files.srcs:
29-
basename = srcfile.basename
30-
filename = basename[:-len('.proto')] + lang.file_extension
31-
pbfile = ctx.new_file(filename)
32-
srcs += [srcfile.path]
33-
requires += [srcfile]
34-
provides += [pbfile]
35-
36-
return (args, srcs, requires, provides)
37-
38-
39-
def post(ctx, requires, provides):
40-
return (requires, provides)
41-
42-
py_proto_compile = _compile([ LANGUAGE.get("python") ])
43-
44-
#def py_proto_compile(**kwargs):
45-
# pass
46-
#rule = _compile([ LANGUAGE.get("python") ])
47-
#_rule(gen_py = True)
9+
def ruby_proto_library(name, **kwargs):
10+
proto_library(name,
11+
proto_compile = ruby_proto_compile,
12+
spec = SPEC,
13+
**kwargs)

bzl/rules.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def protobuf_repositories(
1212
with_java=False,
1313
with_javanano=False,
1414
with_python=False,
15+
with_ruby=False,
1516
with_grpc_gateway=False,
1617
):
1718

@@ -57,6 +58,8 @@ def protobuf_repositories(
5758
classes += ["javanano"]
5859
if with_grpc_gateway:
5960
classes += ["gateway"]
61+
if with_ruby:
62+
classes += ["ruby"]
6063

6164
requires = [
6265
"protobuf",

examples/proto/BUILD

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package(default_visibility = ["//visibility:public"])
22

33
load("//bzl:cpp/rules.bzl", "cc_proto_library")
44
load("//bzl:go/rules.bzl", "go_proto_library")
5+
load("//bzl:ruby/rules.bzl", "ruby_proto_library")
56

67
filegroup(
78
name = "protos",
@@ -21,3 +22,11 @@ cc_proto_library(
2122
protos = [":protos"],
2223
verbose = 1,
2324
)
25+
26+
# This must be called with ':rb.pb' due to lack of implementing library rule for the moment.
27+
#
28+
ruby_proto_library(
29+
name = "rb",
30+
protos = [":protos"],
31+
verbose = 1,
32+
)

0 commit comments

Comments
 (0)