-
Notifications
You must be signed in to change notification settings - Fork 388
/
srpc.bzl
76 lines (66 loc) · 1.76 KB
/
srpc.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
"""
Rules for building C++ srpc with Bazel.
"""
load("@rules_cc//cc:defs.bzl", "cc_library")
tool_path = ":srpc_generator"
def srpc_cc_library(
name,
srcs,
deps = [],
type = "proto",
out_prefix = "",
visibility = None):
output_directory = (
("$(@D)/%s" % (out_prefix)) if len(srcs) > 1 else ("$(@D)")
)
proto_output_headers = [
(out_prefix + "%s.srpc.h") % (s.replace(".%s" % type, "").split("/")[-1])
for s in srcs
]
thrift_output_headers = [
(out_prefix + "%s.thrift.h") % (s.replace(".%s" % type, "").split("/")[-1])
for s in srcs
]
if type == "thrift":
output_headers = proto_output_headers + thrift_output_headers
gen_proto = "thrift"
if type == "proto":
output_headers = proto_output_headers
gen_proto = "protobuf"
genrule_cmd = " ".join([
"SRCS=($(SRCS));",
"for f in $${SRCS[@]:0:%s}; do" % len(srcs),
"$(location %s)" % (tool_path),
" %s " % gen_proto,
"$$f",
output_directory + ";",
"done",
])
srcs_lib = "%s_srcs" % (name)
native.genrule(
name = srcs_lib,
srcs = srcs,
outs = output_headers,
tools = [tool_path],
cmd = genrule_cmd,
output_to_bindir = True,
message = "Generating srpc files for %s:" % (name),
)
runtime_deps = deps + [":srpc"]
print(runtime_deps)
cc_library(
name = name,
hdrs = [
":" + srcs_lib,
],
srcs = [
":" + srcs_lib,
],
features = [
"-parse_headers",
],
deps = runtime_deps,
includes = [],
linkstatic = 1,
visibility = visibility,
)