This repository has been archived by the owner on Oct 27, 2023. It is now read-only.
forked from pubref/rules_protobuf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rules.bzl
104 lines (87 loc) · 2.56 KB
/
rules.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
load("@io_bazel_rules_go//go:def.bzl", "go_library", "new_go_repository")
load("//protobuf:rules.bzl", "proto_compile", "proto_repositories")
load("//go:deps.bzl", "DEPS")
def go_proto_repositories(
lang_deps = DEPS,
lang_requires = [
"com_github_golang_protobuf",
"com_github_golang_glog",
"org_golang_google_grpc",
"org_golang_x_net",
], **kwargs):
rem = proto_repositories(lang_deps = lang_deps,
lang_requires = lang_requires,
**kwargs)
# Load remaining (special) deps
for dep in rem:
rule = dep.pop("rule")
if "new_go_repository" == rule:
new_go_repository(**dep)
else:
fail("Unknown loading rule %s for %s" % (rule, dep))
PB_COMPILE_DEPS = [
"@com_github_golang_protobuf//proto:go_default_library",
]
GRPC_COMPILE_DEPS = PB_COMPILE_DEPS + [
"@com_github_golang_glog//:go_default_library",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_x_net//context:go_default_library",
]
def go_proto_compile(langs = [str(Label("//go"))], **kwargs):
proto_compile(langs = langs, **kwargs)
def go_proto_library(
name,
langs = [str(Label("//go"))],
go_prefix = Label("//:go_prefix", relative_to_caller_repository=True),
go_package = None,
protos = [],
importmap = {},
imports = [],
inputs = [],
proto_deps = [],
output_to_workspace = False,
protoc = None,
pb_plugin = None,
pb_options = [],
grpc_plugin = None,
grpc_options = [],
proto_compile_args = {},
with_grpc = True,
srcs = [],
deps = [],
go_proto_deps = [],
verbose = 0,
**kwargs):
if not go_proto_deps:
if with_grpc:
go_proto_deps += GRPC_COMPILE_DEPS
else:
go_proto_deps += PB_COMPILE_DEPS
proto_compile_args += {
"name": name + ".pb",
"protos": protos,
"go_prefix": go_prefix,
"go_package": go_package,
"deps": [dep + ".pb" for dep in proto_deps],
"langs": langs,
"importmap": importmap,
"imports": imports,
"inputs": inputs,
"pb_options": pb_options,
"grpc_options": grpc_options,
"output_to_workspace": output_to_workspace,
"verbose": verbose,
"with_grpc": with_grpc,
}
if protoc:
proto_compile_args["protoc"] = protoc
if pb_plugin:
proto_compile_args["pb_plugin"] = pb_plugin
if grpc_plugin:
proto_compile_args["grpc_plugin"] = grpc_plugin
proto_compile(**proto_compile_args)
go_library(
name = name,
srcs = srcs + [name + ".pb"],
deps = list(set(deps + proto_deps + go_proto_deps)),
**kwargs)