aboutsummaryrefslogtreecommitdiff
path: root/tools/configure_file.bzl
diff options
context:
space:
mode:
Diffstat (limited to 'tools/configure_file.bzl')
-rw-r--r--tools/configure_file.bzl29
1 files changed, 29 insertions, 0 deletions
diff --git a/tools/configure_file.bzl b/tools/configure_file.bzl
new file mode 100644
index 0000000..8fdd75c
--- /dev/null
+++ b/tools/configure_file.bzl
@@ -0,0 +1,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,
+)