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, )