autoconf_hdr

Rules

autoconf_hdr

load("@rules_cc_autoconf//autoconf:autoconf_hdr.bzl", "autoconf_hdr")

autoconf_hdr(name, deps, out, default_deps, defaults, inlines, mode, substitutions, template)

Generate configuration headers from results provided by autoconf targets.

This rule takes check results from autoconf targets (via deps) and generates a header file. The template file (if provided) is used to format the output header.

Example:

load("@rules_cc_autoconf//autoconf:autoconf.bzl", "autoconf")
load("@rules_cc_autoconf//autoconf:autoconf_hdr.bzl", "autoconf_hdr")
load("@rules_cc_autoconf//autoconf:checks.bzl", "checks")

autoconf(
    name = "config_checks",
    checks = [
        checks.AC_CHECK_HEADER("stdio.h"),
        checks.AC_CHECK_HEADER("stdlib.h"),
        checks.AC_CHECK_FUNC("printf"),
    ],
)

autoconf_hdr(
    name = "config",
    out = "config.h",
    deps = [":config_checks"],
    template = "config.h.in",
)

Valid mode values:

  • "defines" (default): Only process defines (AC_DEFINE, AC_CHECK_*, etc.), not substitution variables (AC_SUBST). This is for config.h files.
  • "subst": Only process substitution variables (AC_SUBST), not defines. This is for subst.h files.
  • "all": Process both defines and substitution variables.

This allows you to run checks once and generate multiple header files from the same results.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsList of autoconf targets which provide check results. Results from all deps will be merged together, and duplicate define names will produce an error. If not provided, an empty results file will be created.List of labelsoptional[]
outThe output config file (typically config.h).Label; nonconfigurablerequired
default_depsautoconf_defaults targets whose values stand where no result of the name comes through deps (a result overrides a default silently; two defaults of one name must agree). The defaults the deps carry are read as well.List of labelsoptional[]
defaultsDeprecated and ignored: defaults come through deps and default_deps; the autoconf toolchain no longer carries any. Accepted so existing BUILD files keep loading.BooleanoptionalFalse
inlinesA mapping of strings to files for replace within the content of the given template attribute.

The exact string in the template is replaced with the content of the associated file. Any @VAR@ style placeholders in the inline file content will be replaced with their corresponding define values (package info, check results, etc.) after insertion.
Dictionary: String -> Labeloptional{}
modeProcessing mode that determines what should be replaced within the file.Stringoptional"defines"
substitutionsA mapping of exact strings to replacement values.

Each entry performs an exact text replacement in the template - the key string is replaced with the value string. No special patterns or wrappers are added.

Example:
autoconf_hdr(
    name = "config",
    out = "config.h",
    template = "config.h.in",
    substitutions = {
        "@MY_VERSION@": "1.2.3",
        "@BUILD_TYPE@": "release",
        "PLACEHOLDER_TEXT": "actual_value",
    },
    deps = [":checks"],
)


This would replace the exact string @MY_VERSION@ with 1.2.3, @BUILD_TYPE@ with release, and PLACEHOLDER_TEXT with actual_value.
Dictionary: String -> Stringoptional{}
templateTemplate file (config.h.in) to use as base for generating the header file. The template is used to format the output header, but does not generate any checks.Labelrequired