autoconf_toolchain

Provides default autoconf checks that can be overridden by targets.

Rules

autoconf_cache

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

autoconf_cache(name, deps, checks)

Run autoconf-like checks without resolving the autoconf toolchain.

Identical to autoconf except that it does not resolve the autoconf_toolchain. Use this rule for targets that are listed as cache_deps or defaults of an autoconf_toolchain -- using the regular autoconf rule in that position would create a dependency cycle.

Dep-level caching still applies: if a check's cache variable name already has a result in transitive deps, the action is skipped.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsAdditional autoconf, autoconf_library, or package_info dependencies.List of labelsoptional[]
checksList of JSON-encoded checks from checks (e.g., checks.AC_CHECK_HEADER('stdio.h')).List of stringsoptional[]

autoconf_toolchain

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

autoconf_toolchain(name, cache_deps, defaults)

Define an autoconf toolchain providing cached check results and rendering defaults.

The toolchain has two separate concepts:

  • cache_deps: Check results available for action deduplication. When an autoconf target lists a check whose cache variable name already has a result in cache_deps, the checker action is skipped and the existing result file is reused.
  • defaults: Baseline values for autoconf_hdr rendering. When autoconf_hdr has defaults = True, these values are merged into the generated header.

Both cache_deps and defaults contribute to the unified cache used by the autoconf rule for action deduplication. Only defaults contributes to the defaults_by_label map used by autoconf_hdr for include/exclude filtering.

Targets listed in cache_deps and defaults must use autoconf_library (not autoconf) to avoid a dependency cycle.

Example:

load("@rules_cc_autoconf//autoconf:defs.bzl", "autoconf_cache", "autoconf_toolchain")
load("@rules_cc_autoconf//autoconf:checks.bzl", "checks")

autoconf_cache(
    name = "gnulib_defaults",
    checks = [
        checks.AC_SUBST("GNULIB_VFPRINTF_POSIX", "0"),
        checks.AC_SUBST("REPLACE_POSIX_SPAWN", "0"),
    ],
)

autoconf_toolchain(
    name = "gnulib_toolchain_impl",
    defaults = [":gnulib_defaults"],
)

toolchain(
    name = "gnulib_toolchain",
    toolchain = ":gnulib_toolchain_impl",
    toolchain_type = "@rules_cc_autoconf//autoconf:toolchain_type",
)

Caching behavior

Content-key deduplication

Every check is fingerprinted by a content key derived from its implementation fields: type, code, language, define_value, includes, libraries, requires, condition, compile_defines, and similar. Consumer metadata (name, define, subst, unquote) is excluded, so two checks with different consumer names but identical implementations share one content key and produce a single checker action and result file.

When a new check is processed, its content key is looked up in order:

  1. Transitive deps' content_cache
  2. Toolchain unified cache (cache_deps + defaults)
  3. Current target's local content_cache

If a hit is found at any level the existing result file is reused and no new checker action is declared. Identical checks within the same target are idempotent (silently skipped on second occurrence).

Conflict detection

Three layers, from strictest to most relaxed:

  • Within one target -- duplicate define or subst symbol names in the same checks list always fail, even if the content keys match. This prevents accidental duplication in a single target.
  • Local vs dependencies / deps vs deps -- the same symbol appearing with a different result file is an error, unless both files share the same content key (a benign duplicate from identical implementations).
  • Cache variable names (cache_results) have no cross-dep conflict detection; content-based dedup is the identity signal.

Resolving conflicts

The typical fix for "Define 'X' is defined both locally and in dependencies with different result files":

  • Remove the local check and depend on the target that already provides it.
  • Or factor the shared check into its own autoconf / autoconf_cache target and depend on it from both consumers.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
cache_depsTargets whose check results are available for action deduplication in autoconf targets.List of labelsoptional[]
defaultsTargets whose results provide baseline values for autoconf_hdr rendering.List of labelsoptional[]