-
Notifications
You must be signed in to change notification settings - Fork 157
/
rules.bzl
103 lines (86 loc) · 2.35 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
load("//protobuf:rules.bzl", "proto_compile", "proto_repositories")
load("//cpp:deps.bzl", "DEPS")
load("//cpp:grpc_archive.bzl", "grpc_archive")
def cpp_proto_repositories(
lang_deps = DEPS,
lang_requires = [
"com_google_grpc",
"com_github_cares_cares",
"com_google_googletest",
"com_github_madler_zlib",
"cares",
"zlib",
"nanopb",
"boringssl",
"libssl",
"protoc_gen_grpc_cpp",
], **kwargs):
rem = proto_repositories(lang_deps = lang_deps,
lang_requires = lang_requires,
**kwargs)
for dep in rem:
rule = dep.pop("rule")
if "grpc_archive" == rule:
grpc_archive(**dep)
else:
fail("Unknown loading rule %s for %s" % (rule, dep))
PB_COMPILE_DEPS = [
"//external:protobuf_clib",
]
GRPC_COMPILE_DEPS = PB_COMPILE_DEPS + [
"@com_google_grpc//:grpc++",
"@com_google_grpc//:grpc++_reflection",
]
def cpp_proto_compile(langs = [str(Label("//cpp"))], **kwargs):
proto_compile(langs = langs, **kwargs)
cc_proto_compile = cpp_proto_compile
def cpp_proto_library(
name,
langs = [str(Label("//cpp"))],
protos = [],
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 = [],
verbose = 0,
**kwargs):
if with_grpc:
compile_deps = GRPC_COMPILE_DEPS
else:
compile_deps = PB_COMPILE_DEPS
proto_compile_args += {
"name": name + ".pb",
"protos": protos,
"deps": [dep + ".pb" for dep in proto_deps],
"langs": langs,
"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)
native.cc_library(
name = name,
srcs = srcs + [name + ".pb"],
deps = depset(deps + proto_deps + compile_deps).to_list(),
**kwargs)
# Alias for cpp_proto_library
cc_proto_library = cpp_proto_library