autoconf_srcs
Rules
autoconf_srcs
load("@rules_cc_autoconf//autoconf:autoconf_srcs.bzl", "autoconf_srcs")
autoconf_srcs(name, deps, srcs, default_deps, defaults, naming, wrap)
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 | |
| default_deps | autoconf_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 labels | optional | [] |
| defaults | Deprecated and ignored: defaults come through deps and default_deps; the autoconf toolchain no longer carries any. Accepted so existing BUILD files keep loading. | Boolean | optional | False |
| 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. Under wrap = "include" the output always carries the .ac infix as well (foo.c -> foo.ac.c, per_target: {ctx.label.name}/foo.ac.c): a wrapper named like a root-level source would resolve its own #include "foo.c" to itself. | String | optional | "package_relative" |
| wrap | How a generated file stands for its source. copy (the default) carries a copy of the source's contents. include carries only #include "<path of the source>", so the source's own quoted includes (#include "sibling.h") still resolve in its directory and __FILE__ and diagnostics name the source; the sources must then reach the compiler, which they do when the consumer lists this target in deps as well as srcs (the target provides them as headers of a CcInfo). | String | optional | "copy" |