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
|
load("//:project_config.bzl", "version")
load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain", "use_cc_toolchain")
def configure_file(**kwargs):
_configure_file(
source_file = "{name}.h".format(**kwargs),
**kwargs
)
def _configure_file_impl(ctx):
cc_toolchain = find_cc_toolchain(ctx)
ctx.actions.expand_template(
template = ctx.file.template,
output = ctx.outputs.source_file,
substitutions = {
"{VERSION}": '"{}"'.format(version()),
"{CC}": '"{} " __VERSION__'.format(cc_toolchain.compiler),
},
)
_configure_file = rule(
attrs = {
"template": attr.label(allow_single_file = True),
"source_file": attr.output(mandatory = True),
},
toolchains = use_cc_toolchain(),
implementation = _configure_file_impl,
)
|