autoconf_toolchain

Provides default autoconf checks that can be overridden by targets.

Rules

Functions

autoconf_toolchain

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

autoconf_toolchain(name, cache_deps)

Define an autoconf toolchain that shares check results across targets.

The toolchain carries one thing: the content cache of its cache_deps. When an autoconf target lists a check whose implementation already has a result there, the checker action is skipped and the existing result file is reused. Nothing else crosses the toolchain boundary: not the results as defines or substs, and not defaults. Defaults are autoconf_defaults targets that a target reads through its own default_deps (see autoconf_defaults); the toolchain neither carries nor injects any.

Targets listed in cache_deps must use autoconf_cache (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 = "common_checks",
    checks = [
        checks.AC_CHECK_HEADER("stdio.h"),
        checks.AC_CHECK_FUNC("strerror"),
    ],
)

autoconf_toolchain(
    name = "my_toolchain_impl",
    cache_deps = [":common_checks"],
)

toolchain(
    name = "my_toolchain",
    toolchain = ":my_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 content cache (cache_deps)
  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.

cache_deps on the toolchain itself is intentionally exempt from define/subst conflict detection: it contributes only to the content cache and is meant to absorb broad sweeps of cache providers (e.g., every gnulib m4 module) that legitimately publish overlapping symbols from different files. Per-target deps still enforce conflicts.

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. Only the content cache is exposed downstream; define/subst conflicts among these targets are NOT detected, so a broad sweep of cache providers with overlapping symbols (e.g., every gnulib m4 module) can be passed safely.List of labelsoptional[]

autoconf_cache

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

autoconf_cache(*, name, build_settings, checks, deps, **kwargs)

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 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.

PARAMETERS

NameDescriptionDefault Value
nameA unique name for this target.none
build_settingsList of checks.AC_BUILD_SETTING(...) entries associating Bazel build setting targets (any rule providing BuildSettingInfo) with autoconf-style defines and substitutions.None
checksList of JSON-encoded checks from checks (e.g., checks.AC_CHECK_HEADER('stdio.h')).None
depsAdditional autoconf, autoconf_cache, or autoconf_package_info dependencies.None
kwargsStandard Bazel attributes (e.g. visibility, tags).none