forked from capnproto/capnproto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
capnproto.bzl
83 lines (75 loc) · 2.6 KB
/
capnproto.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
def _impl(ctx):
includes = depset(ctx.attr.includes + [ctx.attr.capnp_system_include])
inputs = depset(ctx.files.srcs + ctx.files.data)
for dep_target in ctx.attr.deps:
includes += dep_target.capnp.includes
inputs += dep_target.capnp.inputs
cc_out = "-o%s:%s" % (ctx.executable.capnpc_cxx.path, ctx.var["GENDIR"])
args = ["compile", "--verbose", "--no-standard-import", cc_out]
include_flags = ["-I" + inc for inc in includes]
ctx.action(
inputs=list(inputs) + ctx.files.capnpc_cxx + ctx.files.capnp_capnp,
outputs=ctx.outputs.outs,
executable=ctx.executable.capnp,
arguments = args + include_flags + [s.path for s in ctx.files.srcs],
mnemonic="GenCapnp",
)
return struct(
capnp=struct(
includes = includes,
inputs = inputs,
)
)
_capnp_gen = rule(
attrs={
"srcs": attr.label_list(allow_files=True),
"deps": attr.label_list(providers = ["capnp"]),
"data": attr.label_list(allow_files=True),
"includes": attr.string_list(),
"capnp": attr.label(executable=True, cfg="host", allow_single_file=True, mandatory=True,
default=Label("@capnproto//:capnp")),
"capnpc_cxx": attr.label(executable=True, cfg="host", allow_single_file=True,
mandatory=True,
default=Label("@capnproto//:capnpc-c++")),
"capnp_capnp": attr.label(default=Label("@capnproto//:capnp-capnp")),
"capnp_system_include": attr.string(default=Label("@capnproto//:capnp").workspace_root + "/c++/src"),
"outs": attr.output_list(),
},
output_to_genfiles=True,
implementation=_impl,
)
def cc_capnp_library(
name,
srcs=[],
deps=[],
data=[],
include=None,
capnp="@capnproto//:capnp",
capnpc_cxx="@capnproto//:capnpc-c++",
capnp_capnp="@capnproto//:capnp-capnp",
**kargs):
"""Bazel rule to create a C++ capnproto library from capnp source files
"""
includes = []
if include != None:
includes = [include]
outs = ([s + ".h" for s in srcs] +
[s + ".c++" for s in srcs])
_capnp_gen(
name=name + "_gencapnp",
srcs=srcs,
deps=[s + "_gencapnp" for s in deps],
data=data,
includes=includes,
capnp=capnp,
capnpc_cxx=capnpc_cxx,
outs=outs,
visibility=["//visibility:public"],
)
cc_libs = ["@capnproto//:capnp-lib"]
native.cc_library(
name=name,
srcs=outs,
deps=cc_libs + deps,
includes=includes,
**kargs)