autoconf_srcs
Rules
autoconf_srcs
load("@rules_cc_autoconf//autoconf:autoconf_srcs.bzl", "autoconf_srcs")
autoconf_srcs(name, deps, srcs, defaults, defaults_exclude, defaults_include, naming)
Generate wrapper sources that are conditionally enabled by autoconf results.
Typical use case:
load("@rules_cc_autoconf//autoconf:autoconf_srcs.bzl", "autoconf_srcs")
load("@rules_cc_autoconf//autoconf:autoconf.bzl", "autoconf")
load("@rules_cc_autoconf//autoconf:checks.bzl", "checks")
load("@rules_cc//cc:cc_library.bzl", "cc_library")
autoconf(
name = "config",
out = "config.h",
checks = [
# Feature is present on this platform/toolchain.
checks.AC_CHECK_HEADER("foo.h", define = "HAVE_FOO"),
],
)
autoconf_srcs(
name = "foo_srcs",
deps = [":config"],
srcs = {
"uses_foo.c": "HAVE_FOO",
},
)
cc_library(
name = "foo",
srcs = [":foo_srcs"],
hdrs = [":config.h"],
)
In this setup autoconf_srcs reads the results from :config (or multiple targets via deps) and generates a
wrapped copy of uses_foo.c whose contents are effectively:
#define HAVE_FOO 1 // when the check for HAVE_FOO succeeds
/* or: #undef HAVE_FOO // when the check fails */
#ifdef HAVE_FOO
/* original uses_foo.c contents ... */
#endif
This is useful when you have platform-specific or optional sources that should
only be compiled when a particular autoconf check passes, without having to
manually maintain #ifdef guards in every source file.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | List of autoconf targets which provide defines. Results from all deps will be merged together, and duplicate define names will produce an error. | List of labels | required | |
| srcs | A mapping of source file to define required to compile the file. | Dictionary: Label -> String | required | |
| defaults | Whether to include toolchain defaults. When False (the default), no toolchain defaults are included and only the explicit deps provide check results. When True, defaults from the autoconf toolchain are included, subject to filtering by defaults_include or defaults_exclude. | Boolean | optional | False |
| defaults_exclude | Labels to exclude from toolchain defaults. Only effective when defaults=True. If specified, defaults from these labels are excluded. Labels not found in the toolchain are silently ignored. Mutually exclusive with defaults_include. | List of labels | optional | [] |
| defaults_include | Labels to include from toolchain defaults. Only effective when defaults=True. If specified, only defaults from these labels are included. An error is raised if a specified label is not found in the toolchain. Mutually exclusive with defaults_exclude. | List of labels | optional | [] |
| naming | How to name generated sources: package_relative keeps the original package-relative path, ac_suffix inserts .ac. before the final suffix (e.g. foo.cc -> foo.ac.cc), and per_target prefixes outputs with {ctx.label.name} to namespace them per rule. | String | optional | "package_relative" |