checks

This module provides Bazel macros that mirror GNU Autoconf's behavior.

Cache Variables, Defines, and Subst Values

Checks (AC_CHECK_FUNC, AC_CHECK_HEADER, etc.) create cache variables by default, following autoconf's naming convention:

  • AC_CHECK_HEADER("foo.h") -> cache variable "ac_cv_header_foo_h"
  • AC_CHECK_FUNC("foo") -> cache variable "ac_cv_func_foo"
  • AC_CHECK_DECL("foo") -> cache variable "ac_cv_have_decl_foo"

Defines and subst values are created explicitly using AC_DEFINE and AC_SUBST.

Condition Resolution

When AC_DEFINE or AC_SUBST use a condition parameter that references a cache variable (e.g., condition="ac_cv_header_foo_h"), the condition is evaluated as a truthy check:

  • Condition is true if:

    • The cache variable exists (check was run)
    • The check succeeded (success = true)
    • The value is truthy (non-empty string, not "0")
  • Condition is false if:

    • The cache variable doesn't exist (check wasn't run)
    • The check failed (success = false)
    • The value is falsy (empty string or "0")

If the condition includes a comparison operator (e.g., condition="ac_cv_header_foo_h==1"), it performs value comparison instead of truthy check.

Example:

# Check creates cache variable
macros.AC_CHECK_HEADER("alloca.h")
# -> Creates cache variable: "ac_cv_header_alloca_h" with value "1" (if header exists)

# Define with truthy condition
macros.AC_DEFINE(
    "HAVE_ALLOCA_H",
    condition="ac_cv_header_alloca_h",  # Truthy: true if check succeeded and value is truthy
    if_true="1",
    if_false=None,  # Don't define if condition is false
)

# Subst with truthy condition
macros.AC_SUBST(
    "HAVE_ALLOCA_H",
    condition="ac_cv_header_alloca_h",  # Truthy check
    if_true="1",
    if_false="0",  # Always set subst value
)

Default Includes

Default includes used by AC_CHECK_DECL, AC_CHECK_TYPE, etc. when no includes are specified.

GNU Autoconf's AC_INCLUDES_DEFAULT uses #ifdef HAVE_* guards, but that relies on AC_CHECK_HEADERS_ONCE being called earlier to define those macros. In Bazel, each compile test runs independently without access to results from other checks, so we use unconditional includes instead. This matches what would happen on a modern POSIX system where all the standard headers exist.

See: https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.72/autoconf.html#Default-Includes

Header / includes parameter

Checks that need to include headers (AC_CHECK_DECL, AC_CHECK_TYPE, AC_CHECK_SIZEOF, AC_CHECK_MEMBER, etc.) take an includes parameter. AC_CHECK_FUNC does not take includes (standard Autoconf link test only); use GL_CHECK_FUNCS_ANDROID (or other GL_CHECK_FUNCS* in gnulib/macros.bzl) when includes are needed. Both of these forms are supported:

Use include directives as strings, e.g. "#include <stdlib.h>" or "#include <sys/stat.h>", matching Autoconf/gnulib (e.g. gl_CHECK_FUNCS_ANDROID([faccessat], [[#include <unistd.h>]])). The list is joined with newlines to form the prologue of the test program.

The parameter headers is a deprecated alias for includes; prefer includes.

Functions

checks.AC_CHECK_ALIGNOF

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

checks.AC_CHECK_ALIGNOF(type_name, *, define, includes, language, requires, subst)

Check the alignment of a type.

Original m4 example:

AC_CHECK_ALIGNOF([int])
AC_CHECK_ALIGNOF([double], [[#include <stddef.h>]])

Example:

macros.AC_CHECK_ALIGNOF("int")
macros.AC_CHECK_ALIGNOF("double", includes = ["stddef.h"])

Cross-Compile Warning: This macro is NOT cross-compile friendly. It requires compiling and running code to determine the alignment, which doesn't work when cross-compiling.

PARAMETERS

NameDescriptionDefault Value
type_nameName of the typenone
defineCustom define name (defaults to ALIGNOF_<TYPE>)None
includesOptional list of header names to include (e.g. ["stddef.h"])None
languageLanguage to use for check ("c" or "cpp")"c"
requiresList of requirements that must be met before this check runs. Can be simple define names (e.g., "HAVE_FOO") or value-based requirements (e.g., "REPLACE_FSTAT=1" to require specific value)None
substIf True, mark as a substitution variable (for @VAR@ replacement in subst.h).None

RETURNS

A JSON-encoded check string for use with the autoconf rule.

checks.AC_CHECK_CXX_COMPILER_FLAG

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

checks.AC_CHECK_CXX_COMPILER_FLAG(flag, define, language, requires, subst)

Check if the C++ compiler supports a specific flag.

Original m4 example:

AC_CHECK_CXX_COMPILER_FLAG([-std=c++17], [CXXFLAGS="$CXXFLAGS -std=c++17"])

Example:

macros.AC_CHECK_CXX_COMPILER_FLAG("-std=c++17")
macros.AC_CHECK_CXX_COMPILER_FLAG("-Wall")

PARAMETERS

NameDescriptionDefault Value
flagCompiler flag to test (e.g., "-Wall", "-std=c++17")none
defineCustom define name (defaults to HAVE_FLAG_<FLAG>)None
languageLanguage to use for check ("c" or "cpp")"cpp"
requiresList of requirements that must be met before this check runs. Can be simple define names (e.g., "HAVE_FOO") or value-based requirements (e.g., "REPLACE_FSTAT=1" to require specific value)None
substIf True, mark as a substitution variable (for @VAR@ replacement in subst.h).None

RETURNS

A JSON-encoded check string for use with the autoconf rule.

checks.AC_CHECK_C_COMPILER_FLAG

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

checks.AC_CHECK_C_COMPILER_FLAG(flag, define, language, requires, subst)

Check if the C compiler supports a specific flag.

Original m4 example:

AC_CHECK_C_COMPILER_FLAG([-Wall], [CFLAGS="$CFLAGS -Wall"])

Example:

macros.AC_CHECK_C_COMPILER_FLAG("-Wall")
macros.AC_CHECK_C_COMPILER_FLAG("-std=c99")

PARAMETERS

NameDescriptionDefault Value
flagCompiler flag to test (e.g., "-Wall", "-std=c99")none
defineCustom define name (defaults to HAVE_FLAG_<FLAG>)None
languageLanguage to use for check ("c" or "cpp")"c"
requiresList of requirements that must be met before this check runs. Can be simple define names (e.g., "HAVE_FOO") or value-based requirements (e.g., "REPLACE_FSTAT=1" to require specific value)None
substIf True, mark as a substitution variable (for @VAR@ replacement in subst.h).None

RETURNS

A JSON-encoded check string for use with the autoconf rule.

checks.AC_CHECK_DECL

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

checks.AC_CHECK_DECL(symbol, *, name, define, includes, compile_defines, language, requires,
                     if_true, if_false, subst)

Check if a symbol is declared.

Original m4 example:

AC_CHECK_DECL([NULL], [AC_DEFINE([HAVE_DECL_NULL], [1])], [], [[#include <stddef.h>]])
AC_CHECK_DECL([stdout], [AC_DEFINE([HAVE_DECL_STDOUT], [1])], [], [[#include <stdio.h>]])

Example:

# Cache variable only (no define, no subst)
macros.AC_CHECK_DECL("NULL", includes = ["stddef.h"])
# -> Creates cache variable: "ac_cv_have_decl_NULL"

# Cache variable + define (explicit name)
macros.AC_CHECK_DECL("stdout", includes = ["stdio.h"], define = "HAVE_DECL_STDOUT")
# -> Creates cache variable: "ac_cv_have_decl_stdout"
# -> Creates define: "HAVE_DECL_STDOUT" in config.h

Note: This is different from AC_CHECK_SYMBOL - it checks if something is declared (not just #defined).

When no includes are specified, the standard default includes
are used (AC_INCLUDES_DEFAULT from GNU Autoconf).

Use header names like `"stdlib.h"` (not `"#include <stdlib.h>"`).

PARAMETERS

NameDescriptionDefault Value
symbolName of the symbol to checknone
nameCache variable name (defaults to ac_cv_have_decl_<SYMBOL> following autoconf convention)None
defineDefine behavior: - None (default): No define is created, only cache variable - True: Create define using the cache variable name (name) - "HAVE_FOO": Create define with explicit name HAVE_FOO (implies define=True)None
includesOptional list of header names to include (e.g. ["stdlib.h"]). If not specified and headers is not specified, uses AC_INCLUDES_DEFAULT.None
compile_definesOptional list of preprocessor define names from previous checks to add before includes (e.g., ["_GNU_SOURCE", "_DARWIN_C_SOURCE"]). Each string must match the define name of a previous check. The values from those checks will be used automatically.None
languageLanguage to use for check ("c" or "cpp")"c"
requiresRequirements that must be met for this check to run. Can be define names (e.g., "HAVE_FOO"), negated (e.g., "!HAVE_FOO"), or value-based (e.g., "REPLACE_FSTAT==1", "REPLACE_FSTAT!=0").None
if_trueValue to use when check succeeds (currently not used for this check type).None
if_falseValue to use when check fails (currently not used for this check type).None
substSubst behavior: - None (default): No subst is created, only cache variable - True: Create subst using the cache variable name (name) - "HAVE_FOO": Create subst with explicit name HAVE_FOO (implies subst=True)None

RETURNS

A JSON-encoded check string for use with the autoconf rule.

checks.AC_CHECK_FUNC

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

checks.AC_CHECK_FUNC(function, name, *, define, code, language, compile_defines, requires, subst)

Check for a function.

Original m4 example:

AC_CHECK_FUNC([malloc])
AC_CHECK_FUNC([mmap], [AC_DEFINE([HAVE_MMAP_FEATURE], [1])])

Example:

# Cache variable only (no define, no subst)
macros.AC_CHECK_FUNC("malloc")
# -> Creates cache variable: "ac_cv_func_malloc"

# Cache variable + define (explicit name)
macros.AC_CHECK_FUNC("mmap", define = "HAVE_MMAP")
# -> Creates cache variable: "ac_cv_func_mmap"
# -> Creates define: "HAVE_MMAP" in config.h

# Cache variable + define (using cache var name)
macros.AC_CHECK_FUNC("mmap", define = True)
# -> Creates cache variable: "ac_cv_func_mmap"
# -> Creates define: "ac_cv_func_mmap" in config.h

# Cache variable + subst
macros.AC_CHECK_FUNC("_Exit", subst = True)
# -> Creates cache variable: "ac_cv_func__Exit"
# -> Creates subst: "ac_cv_func__Exit" in subst.h

PARAMETERS

NameDescriptionDefault Value
functionName of the function (e.g., "printf")none
nameCache variable name (defaults to ac_cv_func_<FUNCTION> following autoconf convention)None
defineDefine behavior: - None (default): No define is created, only cache variable - True: Create define using the cache variable name (name) - "HAVE_FOO": Create define with explicit name HAVE_FOO (implies define=True)None
codeCustom code to compile (optional).None
languageLanguage to use for check ("c" or "cpp")"c"
compile_definesOptional list of preprocessor define names from previous checks to add before includes (e.g., ["_GNU_SOURCE", "_DARWIN_C_SOURCE"]). Each string must match the define name of a previous check. The values from those checks will be used automatically.None
requiresRequirements that must be met for this check to run. Can be define names (e.g., "HAVE_FOO"), negated (e.g., "!HAVE_FOO"), or value-based (e.g., "REPLACE_FSTAT==1", "REPLACE_FSTAT!=0").None
substSubst behavior: - None (default): No subst is created, only cache variable - True: Create subst using the cache variable name (name) - "HAVE_FOO": Create subst with explicit name HAVE_FOO (implies subst=True)None

RETURNS

A JSON-encoded check string for use with the autoconf rule.

checks.AC_CHECK_HEADER

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

checks.AC_CHECK_HEADER(header, name, define, includes, language, compile_defines, requires, subst)

Check for a header file.

Original m4 example:

AC_CHECK_HEADER([stdio.h])
AC_CHECK_HEADER([pthread.h], [AC_CHECK_FUNC([pthread_create])])

Example:

# Cache variable only (no define, no subst)
macros.AC_CHECK_HEADER("stdio.h")
# -> Creates cache variable: "ac_cv_header_stdio_h"

# Cache variable + define (explicit name)
macros.AC_CHECK_HEADER("pthread.h", define = "HAVE_PTHREAD_H")
# -> Creates cache variable: "ac_cv_header_pthread_h"
# -> Creates define: "HAVE_PTHREAD_H" in config.h

# Cache variable + define (using cache var name)
macros.AC_CHECK_HEADER("pthread.h", define = True)
# -> Creates cache variable: "ac_cv_header_pthread_h"
# -> Creates define: "ac_cv_header_pthread_h" in config.h

PARAMETERS

NameDescriptionDefault Value
headerName of the header file (e.g., "stdio.h")none
nameCache variable name (defaults to ac_cv_header_<HEADER> following autoconf convention)None
defineDefine behavior: - None (default): No define is created, only cache variable - True: Create define using the cache variable name (name) - "HAVE_FOO": Create define with explicit name HAVE_FOO (implies define=True)None
includesOptional list of headers to include.None
languageLanguage to use for check ("c" or "cpp")"c"
compile_definesOptional list of preprocessor define names from previous checks to add before includes (e.g., ["_GNU_SOURCE", "_DARWIN_C_SOURCE"]). Each string must match the define name of a previous check. The values from those checks will be used automatically.None
requiresRequirements that must be met for this check to run. Can be define names (e.g., "HAVE_FOO"), negated (e.g., "!HAVE_FOO"), or value-based (e.g., "REPLACE_FSTAT==1", "REPLACE_FSTAT!=0").None
substSubst behavior: - None (default): No subst is created, only cache variable - True: Create subst using the cache variable name (name) - "HAVE_FOO": Create subst with explicit name HAVE_FOO (implies subst=True)None

RETURNS

A JSON-encoded check string for use with the autoconf rule.

checks.AC_CHECK_LIB

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

checks.AC_CHECK_LIB(library, function, *, name, define, code, language, requires, if_true, if_false,
                    subst)

Check for a function in a library.

Original m4 example:

AC_CHECK_LIB([m], [cos])
AC_CHECK_LIB([pthread], [pthread_create])

Example:

macros.AC_CHECK_LIB("m", "cos")
macros.AC_CHECK_LIB("pthread", "pthread_create")

Note: This checks if the specified function is available in the given library. It attempts to link against -l<library> to verify the library provides the function.

PARAMETERS

NameDescriptionDefault Value
libraryLibrary name without the -l prefix (e.g., "m", "pthread")none
functionFunction name to check for in the library (e.g., "cos", "pthread_create")none
nameThe name of the cache variable. Defaults to ac_cv_lib_library_functionNone
defineCustom define name (defaults to HAVE_LIB<LIBRARY>)None
codeCustom code to compile and link (optional)None
languageLanguage to use for check ("c" or "cpp")"c"
requiresRequirements that must be met for this check to run. Can be define names (e.g., "HAVE_FOO"), negated (e.g., "!HAVE_FOO"), or value-based (e.g., "REPLACE_FSTAT==1", "REPLACE_FSTAT!=0").None
if_trueValue to use when check succeeds (currently not used for this check type).None
if_falseValue to use when check fails (currently not used for this check type).None
substIf True, mark as a substitution variable (for @VAR@ replacement in subst.h).None

RETURNS

A JSON-encoded check string for use with the autoconf rule.

checks.AC_CHECK_MEMBER

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

checks.AC_CHECK_MEMBER(aggregate_member, *, name, define, includes, language, compile_defines,
                       requires, if_true, if_false, subst)

Check if a struct or union has a member.

Original m4 example:

AC_CHECK_MEMBER([struct stat.st_rdev], [AC_DEFINE([HAVE_STRUCT_STAT_ST_RDEV], [1])], [], [[#include <sys/stat.h>]])
AC_CHECK_MEMBER([struct tm.tm_zone], [AC_DEFINE([HAVE_STRUCT_TM_TM_ZONE], [1])], [], [[#include <time.h>]])

Example:

macros.AC_CHECK_MEMBER("struct stat.st_rdev", includes = ["sys/stat.h"])
macros.AC_CHECK_MEMBER("struct tm.tm_zone", includes = ["time.h"])

PARAMETERS

NameDescriptionDefault Value
aggregate_memberStruct or union name with (e.g., struct stat.st_rdev)none
nameCache variable name (defaults to ac_cv_member_aggregate_member following autoconf convention)None
defineCustom define name (defaults to HAVE_<AGGREGATE>_<MEMBER>)None
includesOptional list of header names to include (e.g. ["sys/stat.h"])None
languageLanguage to use for check ("c" or "cpp")"c"
compile_definesOptional list of preprocessor define names from previous checks to add before includes (e.g., ["_GNU_SOURCE", "_DARWIN_C_SOURCE"]). Each string must match the define name of a previous check. The values from those checks will be used automatically.None
requiresRequirements that must be met for this check to run. Can be define names (e.g., "HAVE_FOO"), negated (e.g., "!HAVE_FOO"), or value-based (e.g., "REPLACE_FSTAT==1", "REPLACE_FSTAT!=0").None
if_trueValue to use when check succeeds (currently not used for this check type).None
if_falseValue to use when check fails (currently not used for this check type).None
substIf True, automatically create a substitution variable with the same name that will be set to "1" if the check succeeds, "0" if it fails.None

RETURNS

A JSON-encoded check string for use with the autoconf rule.

checks.AC_CHECK_SIZEOF

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

checks.AC_CHECK_SIZEOF(type_name, *, name, define, includes, language, requires, if_true, if_false,
                       subst)

Check the size of a type.

Original m4 example:

AC_CHECK_SIZEOF([int])
AC_CHECK_SIZEOF([size_t], [], [[#include <stddef.h>]])

Example:

# Cache variable only (no define, no subst)
macros.AC_CHECK_SIZEOF("int")
# -> Creates cache variable: "ac_cv_sizeof_int"

# Cache variable + define (explicit name)
macros.AC_CHECK_SIZEOF("size_t", includes = ["#include <stddef.h>"], define = "SIZEOF_SIZE_T")
# -> Creates cache variable: "ac_cv_sizeof_size_t"
# -> Creates define: "SIZEOF_SIZE_T" in config.h

Cross-Compile Warning: This macro is NOT cross-compile friendly. It requires compiling and running code to determine the size, which doesn't work when cross-compiling.

PARAMETERS

NameDescriptionDefault Value
type_nameName of the type (e.g., int, size_t, void*)none
nameCache variable name (defaults to ac_cv_sizeof_<TYPE> following autoconf convention)None
defineDefine behavior: - None (default): No define is created, only cache variable - True: Create define using the cache variable name (name) - "SIZEOF_FOO": Create define with explicit name SIZEOF_FOO (implies define=True)None
includesOptional list of header names to include (e.g. ["stddef.h"])None
languageLanguage to use for check ("c" or "cpp")"c"
requiresRequirements that must be met for this check to run. Can be define names (e.g., "HAVE_FOO"), negated (e.g., "!HAVE_FOO"), or value-based (e.g., "REPLACE_FSTAT==1", "REPLACE_FSTAT!=0").None
if_trueValue to use when check succeeds (currently not used for this check type).None
if_falseValue to use when check fails (currently not used for this check type).None
substSubst behavior: - None (default): No subst is created, only cache variable - True: Create subst using the cache variable name (name) - "SIZEOF_FOO": Create subst with explicit name SIZEOF_FOO (implies subst=True)None

RETURNS

A JSON-encoded check string for use with the autoconf rule.

checks.AC_CHECK_TYPE

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

checks.AC_CHECK_TYPE(type_name, *, name, define, includes, language, compile_defines, requires,
                     if_true, if_false, subst)

Check for a type.

Original m4 example:

AC_CHECK_TYPE([size_t])
AC_CHECK_TYPE([pthread_t], [], [], [[#include <pthread.h>]])

Example:

# Cache variable only (no define, no subst)
macros.AC_CHECK_TYPE("size_t")
# -> Creates cache variable: "ac_cv_type_size_t"

# Cache variable + define (explicit name)
macros.AC_CHECK_TYPE("pthread_t", includes = ["#include <pthread.h>"], define = "HAVE_PTHREAD_T")
# -> Creates cache variable: "ac_cv_type_pthread_t"
# -> Creates define: "HAVE_PTHREAD_T" in config.h

PARAMETERS

NameDescriptionDefault Value
type_nameName of the type (e.g., size_t)none
nameCache variable name (defaults to ac_cv_type_<TYPE> following autoconf convention)None
defineDefine behavior: - None (default): No define is created, only cache variable - True: Create define using the cache variable name (name) - "HAVE_FOO": Create define with explicit name HAVE_FOO (implies define=True)None
includesOptional list of headers to include (e.g. ["#include <pthread.h>"]). If not specified, uses AC_INCLUDES_DEFAULT.None
languageLanguage to use for check ("c" or "cpp")"c"
compile_definesOptional list of preprocessor define names from previous checks to add before includes (e.g., ["_GNU_SOURCE", "_DARWIN_C_SOURCE"]). Each string must match the define name of a previous check. The values from those checks will be used automatically.None
requiresRequirements that must be met for this check to run. Can be define names (e.g., "HAVE_FOO"), negated (e.g., "!HAVE_FOO"), or value-based (e.g., "REPLACE_FSTAT==1", "REPLACE_FSTAT!=0").None
if_trueValue to use when check succeeds (currently not used for this check type).None
if_falseValue to use when check fails (currently not used for this check type).None
substSubst behavior: - None (default): No subst is created, only cache variable - True: Create subst using the cache variable name (name) - "HAVE_FOO": Create subst with explicit name HAVE_FOO (implies subst=True)None

RETURNS

A JSON-encoded check string for use with the autoconf rule.

checks.AC_COMPUTE_INT

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

checks.AC_COMPUTE_INT(define, expression, *, includes, language, requires, subst)

Compute an integer value at compile time.

Original m4 example:

AC_COMPUTE_INT([SIZEOF_INT], [sizeof(int)])
AC_COMPUTE_INT([MAX_VALUE], [1 << 16])

Example:

macros.AC_COMPUTE_INT("SIZEOF_INT", "sizeof(int)")
macros.AC_COMPUTE_INT("MAX_VALUE", "1 << 16")

Cross-Compile Warning: This macro is NOT cross-compile friendly. It requires compiling and running code to compute the value, which doesn't work when cross-compiling.

PARAMETERS

NameDescriptionDefault Value
defineDefine name for the result (first arg to match autoconf)none
expressionC expression that evaluates to an integer (second arg)none
includesOptional list of header names to include (e.g. ["stdlib.h"])None
languageLanguage to use for check ("c" or "cpp")"c"
requiresList of requirements that must be met before this check runs. Can be simple define names (e.g., "HAVE_FOO") or value-based requirements (e.g., "REPLACE_FSTAT=1" to require specific value)None
substIf True, mark as a substitution variable (for @VAR@ replacement in subst.h).None

RETURNS

A JSON-encoded check string for use with the autoconf rule.

checks.AC_C_INLINE

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

checks.AC_C_INLINE(define, language, requires, subst)

Check what inline keyword the compiler supports.

Original m4 example:

AC_C_INLINE

Example:

macros.AC_C_INLINE()

Tests inline keyword and defines it to the appropriate value.

PARAMETERS

NameDescriptionDefault Value
defineDefine name (defaults to inline)"inline"
languageLanguage to use for check ("c" or "cpp")"c"
requiresList of requirements that must be met before this check runs. Can be simple define names (e.g., "HAVE_FOO") or value-based requirements (e.g., "REPLACE_FSTAT=1" to require specific value)None
substIf True, mark as a substitution variable (for @VAR@ replacement in subst.h).None

RETURNS

A JSON-encoded check string for use with the autoconf rule.

checks.AC_C_RESTRICT

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

checks.AC_C_RESTRICT(define, language, requires, subst)

Check if the compiler supports restrict keyword.

Original m4 example:

AC_C_RESTRICT

Example:

checks.AC_C_RESTRICT()

Note: If restrict is not supported, the define is set to empty string.

PARAMETERS

NameDescriptionDefault Value
defineDefine name (defaults to restrict)"restrict"
languageLanguage to use for check ("c" or "cpp")"c"
requiresList of requirements that must be met before this check runs. Can be simple define names (e.g., "HAVE_FOO") or value-based requirements (e.g., "REPLACE_FSTAT=1" to require specific value)None
substIf True, mark as a substitution variable (for @VAR@ replacement in subst.h).None

RETURNS

A JSON-encoded check string for use with the autoconf rule.

checks.AC_DEFINE

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

checks.AC_DEFINE(define, value, requires, condition, if_true, if_false, subst)

Define a configuration macro.

Original m4 example:

AC_DEFINE([CUSTOM_VALUE], [42])
AC_DEFINE([ENABLE_FEATURE], [1])
AC_DEFINE([PROJECT_NAME], ["MyProject"])
AC_DEFINE([EMPTY_VALUE], [])

Conditional example (m4):

if test $gl_cv_foo = yes; then
  AC_DEFINE([FOO_WORKS], [1])
fi

Example:

# Simple (always define)
macros.AC_DEFINE("CUSTOM_VALUE", "42")

# Conditional (define based on another check's result)
macros.AC_DEFINE(
    "FOO_WORKS",
    condition = "HAVE_FOO",
    if_true = "1",      # Value when HAVE_FOO is true
    if_false = None,    # Don't define when HAVE_FOO is false
)

Note: This is equivalent to GNU Autoconf's AC_DEFINE macro. When used without condition, it creates a define that will always be set. When used with condition, the define is set based on the condition's result.

**Condition Resolution**: If `condition` references a cache variable (e.g.,
`condition="ac_cv_header_foo_h"`), it's evaluated as a truthy check:
- Condition is `true` if the check succeeded AND the value is truthy (non-empty, non-zero)
- Condition is `false` if the check failed OR the value is falsy (empty, "0")
- If condition includes a comparison (e.g., `condition="ac_cv_header_foo_h==1"`),
  it performs value comparison instead.

PARAMETERS

NameDescriptionDefault Value
defineDefine name (e.g., "CUSTOM_VALUE")none
valueValue to assign when no condition is specified (defaults to "1")1
requiresRequirements that must be met for this check to run. Can be define names (e.g., "HAVE_FOO"), negated (e.g., "!HAVE_FOO"), or value-based (e.g., "REPLACE_FSTAT==1", "REPLACE_FSTAT!=0").None
conditionSelects which value to use: if_true when condition is true, if_false when false. Does not affect whether the check runs.None
if_trueValue when condition is true (requires condition).1
if_falseValue when condition is false (requires condition). Use None to not define the macro when condition is false.0
substIf True, mark as a substitution variable (for @VAR@ replacement in subst.h).None

RETURNS

A JSON-encoded check string for use with the autoconf rule.

checks.AC_DEFINE_UNQUOTED

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

checks.AC_DEFINE_UNQUOTED(define, value, requires, condition, if_true, if_false, subst)

Define a configuration macro without quoting (AC_DEFINE_UNQUOTED).

Original m4 example:

AC_DEFINE_UNQUOTED([ICONV_CONST], [$iconv_arg1])
AC_DEFINE_UNQUOTED([VERSION], ["$PACKAGE_VERSION"])

This is similar to AC_DEFINE, but with one key difference:

  • AC_DEFINE with empty value generates: #define NAME /**/
  • AC_DEFINE_UNQUOTED with empty value generates: #define NAME (trailing space)

Example:

# Simple (always define)
macros.AC_DEFINE_UNQUOTED("ICONV_CONST", "")

# Conditional (define based on another check's result)
macros.AC_DEFINE_UNQUOTED(
    "ICONV_CONST",
    condition = "_gl_cv_iconv_nonconst",
    if_true = "",      # Empty value - will generate "#define ICONV_CONST " (trailing space)
    if_false = "const",  # Non-empty value
)

Note: This is equivalent to GNU Autoconf's AC_DEFINE_UNQUOTED macro. The main difference from AC_DEFINE is how empty values are rendered in config.h: AC_DEFINE uses /**/ while AC_DEFINE_UNQUOTED uses a trailing space.

PARAMETERS

NameDescriptionDefault Value
defineDefine name (e.g., "ICONV_CONST")none
valueValue to assign when no condition is specified (defaults to "1")1
requiresRequirements that must be met for this check to run. Can be define names (e.g., "HAVE_FOO"), negated (e.g., "!HAVE_FOO"), or value-based (e.g., "REPLACE_FSTAT==1", "REPLACE_FSTAT!=0").None
conditionSelects which value to use: if_true when condition is true, if_false when false. Does not affect whether the check runs.None
if_trueValue when condition is true (requires condition).None
if_falseValue when condition is false (requires condition). Use None to not define the macro when condition is false.None
substIf True, mark as a substitution variable (for @VAR@ replacement in subst.h).None

RETURNS

A JSON-encoded check string for use with the autoconf rule.

checks.AC_PROG_CC

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

checks.AC_PROG_CC(requires)

Check that a C compiler is available.

Original m4 example:

AC_PROG_CC
AC_PROG_CC([gcc clang])

Example:

macros.AC_PROG_CC()

Note: This is mostly a no-op in Bazel since the toolchain must be configured, but returns a check that will verify the compiler works.

PARAMETERS

NameDescriptionDefault Value
requiresList of requirements that must be met before this check runs. Can be simple define names (e.g., "HAVE_FOO") or value-based requirements (e.g., "REPLACE_FSTAT=1" to require specific value)None

RETURNS

A JSON-encoded check string for use with the autoconf rule.

checks.AC_PROG_CC_C_O

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

checks.AC_PROG_CC_C_O(define, language, requires, subst)

Check if the compiler supports -c and -o flags simultaneously.

Original m4 example:

AC_PROG_CC_C_O

Example:

macros.AC_PROG_CC_C_O()

Note: If the compiler does NOT support both flags together, the define is set.

PARAMETERS

NameDescriptionDefault Value
defineDefine name (defaults to "NO_MINUS_C_MINUS_O")"NO_MINUS_C_MINUS_O"
languageLanguage to use for check ("c" or "cpp")"c"
requiresList of requirements that must be met before this check runs. Can be simple define names (e.g., "HAVE_FOO") or value-based requirements (e.g., "REPLACE_FSTAT=1" to require specific value)None
substIf True, mark as a substitution variable (for @VAR@ replacement in subst.h).None

RETURNS

A JSON-encoded check string for use with the autoconf rule.

checks.AC_PROG_CXX

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

checks.AC_PROG_CXX(requires)

Check that a C++ compiler is available.

Original m4 example:

AC_PROG_CXX
AC_PROG_CXX([g++ clang++])

Example:

macros.AC_PROG_CXX()

Note: This is mostly a no-op in Bazel since the toolchain must be configured, but returns a check that will verify the compiler works.

PARAMETERS

NameDescriptionDefault Value
requiresList of requirements that must be met before this check runs. Can be simple define names (e.g., "HAVE_FOO") or value-based requirements (e.g., "REPLACE_FSTAT=1" to require specific value)None

RETURNS

A JSON-encoded check string for use with the autoconf rule.

checks.AC_SUBST

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

checks.AC_SUBST(variable, value, requires, condition, if_true, if_false)

Substitute a variable value (equivalent to AC_SUBST in GNU Autoconf).

Original m4 example:

HAVE_DECL_WCSDUP=1;   AC_SUBST([HAVE_DECL_WCSDUP])
HAVE_DECL_WCWIDTH=1;  AC_SUBST([HAVE_DECL_WCWIDTH])

Conditional example (m4):

if test $gl_cv_sys_struct_lconv_ok = no; then
  REPLACE_STRUCT_LCONV=1
else
  REPLACE_STRUCT_LCONV=0
fi
AC_SUBST([REPLACE_STRUCT_LCONV])

Example:

# Simple (always set)
macros.AC_SUBST("HAVE_DECL_WCSDUP", "1")

# Conditional (set based on another check's result)
macros.AC_SUBST(
    "REPLACE_STRUCT_LCONV",
    condition = "HAVE_STRUCT_LCONV_OK",
    if_true = "0",    # Value when condition is true
    if_false = "1",   # Value when condition is false
)

Note: Condition Resolution: If condition references a cache variable (e.g., condition="ac_cv_header_foo_h"), it's evaluated as a truthy check: - Condition is true if the check succeeded AND the value is truthy (non-empty, non-zero) - Condition is false if the check failed OR the value is falsy (empty, "0") - If condition includes a comparison (e.g., condition="ac_cv_header_foo_h==1"), it performs value comparison instead.

In GNU Autoconf, `AC_SUBST` is used to substitute shell variables into
Makefiles and template files (replacing `@VAR@` patterns). When used
without `condition`, it always sets the variable. When used with
`condition`, the value depends on the condition's result.

PARAMETERS

NameDescriptionDefault Value
variableVariable name (e.g., "LIBRARY_PATH")none
valueValue to assign when no condition is specified (defaults to "1")1
requiresRequirements that must be met for this check to run. Can be define names (e.g., "HAVE_FOO"), negated (e.g., "!HAVE_FOO"), or value-based (e.g., "REPLACE_FSTAT==1", "REPLACE_FSTAT!=0").None
conditionSelects which value to use: if_true when condition is true, if_false when false. Does not affect whether the check runs.None
if_trueValue when condition is true (requires condition).1
if_falseValue when condition is false (requires condition).0

RETURNS

A JSON-encoded check string for use with the autoconf rule.

checks.AC_TRY_COMPILE

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

checks.AC_TRY_COMPILE(*, code, name, define, includes, language, compile_defines, requires, if_true,
                      if_false, subst)

Try to compile custom code.

Original m4 example:

AC_TRY_COMPILE([#include <stdio.h>], [printf("test");], [AC_DEFINE([HAVE_PRINTF], [1])])

Example:

load("//autoconf:checks.bzl", "utils")
macros.AC_TRY_COMPILE(
    code = "#include <stdio.h>\nint main() { printf(\"test\"); return 0; }",
    define = "HAVE_PRINTF",
)
macros.AC_TRY_COMPILE(file = ":test.c", define = "CUSTOM_CHECK")
macros.AC_TRY_COMPILE(
    includes = ["pthread.h"],
    code = "int x = PTHREAD_CREATE_DETACHED; (void)x;",
    define = "HAVE_PTHREAD_CREATE_DETACHED",
)
macros.AC_TRY_COMPILE(
    code = utils.AC_LANG_PROGRAM(["#include <stdio.h>"], "printf("test");"),
    define = "HAVE_PRINTF",
)

Note: This is a rules_cc_autoconf extension. While GNU Autoconf has an obsolete AC_TRY_COMPILE macro (replaced by AC_COMPILE_IFELSE), this version adds support for file-based checks which is useful in Bazel.

When `includes` is provided along with `code`, the code is treated as
the body of main() and the includes are prepended. For the AC_LANG_PROGRAM
pattern (prologue + body), use `utils.AC_LANG_PROGRAM(prologue, body)` and
pass the result as `code`.

PARAMETERS

NameDescriptionDefault Value
codeCode to compile. If includes is also provided, this is treated as the body of main(). Otherwise, it should be complete C code. For AC_LANG_PROGRAM-style tests, use code = utils.AC_LANG_PROGRAM(prologue, body).None
nameCache variable name.None
defineDefine name to set if compilation succeedsNone
includesOptional list of headers to include. When provided, code is treated as the body of main() function.None
languageLanguage to use for check ("c" or "cpp")"c"
compile_definesOptional list of preprocessor define names from previous checks to add before includes (e.g., ["_GNU_SOURCE", "_DARWIN_C_SOURCE"]). Each string must match the define name of a previous check. The values from those checks will be used automatically.None
requiresRequirements that must be met for this check to run. Can be define names (e.g., "HAVE_FOO"), negated (e.g., "!HAVE_FOO"), or value-based (e.g., "REPLACE_FSTAT==1", "REPLACE_FSTAT!=0").None
if_trueValue to use when check succeeds (currently not used for this check type).None
if_falseValue to use when check fails (currently not used for this check type).None
substIf True, automatically create a substitution variable with the same name that will be set to "1" if the check succeeds, "0" if it fails.None

RETURNS

A JSON-encoded check string for use with the autoconf rule.

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

checks.AC_TRY_LINK(*, code, name, define, includes, language, compile_defines, requires, if_true,
                   if_false, subst)

Try to compile and link custom code.

This function mirrors GNU Autoconf's AC_LINK_IFELSE macro, which uses AC_LANG_PROGRAM to construct test programs. In Bazel, use code (optionally with includes). For the AC_LANG_PROGRAM pattern, pass code = utils.AC_LANG_PROGRAM(prologue, body).

Comparison with GNU Autoconf:

GNU Autoconf:

AC_LINK_IFELSE(
    [AC_LANG_PROGRAM(
        [[#include <stdio.h>]],     # Prologue (includes/declarations)
        [[printf("test");]]         # Body (code inside main())
    )],
    [AC_DEFINE([HAVE_PRINTF], [1])],
    []
)

Bazel (AC_LANG_PROGRAM pattern):

load("//autoconf:checks.bzl", "utils")
checks.AC_TRY_LINK(
    code = utils.AC_LANG_PROGRAM(["#include <stdio.h>"], "printf("test");"),
    define = "HAVE_PRINTF",
)

Bazel (includes pattern - backward compat):

checks.AC_TRY_LINK(
    includes = ["stdio.h"],
    code = "printf("test");",     # Treated as body of main()
    define = "HAVE_PRINTF",
)

Bazel (raw code pattern):

checks.AC_TRY_LINK(
    code = "#include <stdio.h>\nint main() { printf(\"test\"); return 0; }",
    define = "HAVE_PRINTF",
)

Note: This is similar to AC_TRY_COMPILE but also links the code, which is necessary to verify that functions are available at link time (not just declared).

PARAMETERS

NameDescriptionDefault Value
codeCode to compile and link. If includes is also provided, this is treated as the body of main(). Otherwise, it should be complete C code. For AC_LANG_PROGRAM-style tests use code = utils.AC_LANG_PROGRAM(prologue, body).None
nameCache variable name.None
defineDefine name to set if compilation and linking succeedsNone
includesOptional list of headers to include (backward compatibility). When provided, code is treated as the body of main() function.None
languageLanguage to use for check ("c" or "cpp")"c"
compile_definesOptional list of preprocessor define names from previous checks to add before includes (e.g., ["_GNU_SOURCE", "_DARWIN_C_SOURCE"]). Each string must match the define name of a previous check. The values from those checks will be used automatically.None
requiresRequirements that must be met for this check to run. Can be define names (e.g., "HAVE_FOO"), negated (e.g., "!HAVE_FOO"), or value-based (e.g., "REPLACE_FSTAT==1", "REPLACE_FSTAT!=0").None
if_trueValue to use when check succeeds (currently not used for this check type).1
if_falseValue to use when check fails (currently not used for this check type).0
substIf True, mark as a substitution variable (for @VAR@ replacement in subst.h).None

RETURNS

A JSON-encoded check string for use with the autoconf rule.

checks.M4_VARIABLE

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

checks.M4_VARIABLE(define, value, requires, condition, if_true, if_false)

Define a configuration M4 variable.

Original m4 example:

REPLACE_FOO=1

Conditional example (m4):

if test $HAVE_FOO = yes; then
  REPLACE_FOO=0
else
  REPLACE_FOO=1
fi

Example:

# Simple (always set)
macros.M4_VARIABLE("REPLACE_FOO", "1")

# Conditional (set based on another check's result)
macros.M4_VARIABLE(
    "REPLACE_FOO",
    condition = "HAVE_FOO",
    if_true = "0",    # Value when HAVE_FOO is true
    if_false = "1",   # Value when HAVE_FOO is false
)

Note: This is similar to AC_SUBST but is useful for tracking the difference between actual AC_DEFINE values and M4 shell variables used in macros. Unlike AC_SUBST, this does not set subst=true by default.

PARAMETERS

NameDescriptionDefault Value
defineDefine name (e.g., "REPLACE_FOO")none
valueValue to assign when no condition is specified (defaults to "1")1
requiresList of requirements that must be met before this check runs. Can be simple define names (e.g., "HAVE_FOO") or value-based requirements (e.g., "REPLACE_FSTAT=1" to require specific value)None
conditionSelects which value to use: if_true when condition is true, if_false when false. Does not affect whether the check runs.None
if_trueValue when condition is true (requires condition).None
if_falseValue when condition is false (requires condition).None

RETURNS

A JSON-encoded check string for use with the m4 rule.

macros.AC_CHECK_DECLS

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

macros.AC_CHECK_DECLS(symbols, *, includes, compile_defines, language, requires, if_true, if_false,
                      subst)

Check multiple declarations, creating HAVE_DECL_ defines (AC_CHECK_DECLS).

GNU Autoconf's AC_CHECK_DECLS(symbol, ...) checks whether each symbol is declared (e.g. in a header). This macro runs AC_CHECK_DECL for each symbol and sets define names HAVE_DECL_ following autoconf conventions.

Upstream: https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.72/autoconf.html#index-AC_005fCHECK_002dDECL

M4 example (configure.ac): AC_CHECK_DECLS([NULL, stdout, stderr], [], [], [[#include <stdio.h>]]) AC_CHECK_DECL([NULL], [AC_DEFINE([HAVE_DECL_NULL], [1])], [], [[#include <stddef.h>]])

Bazel example (use #include <foo> in includes): load("//autoconf:checks.bzl", "macros") macros.AC_CHECK_DECLS(["NULL", "stdout", "stderr"], includes = ["#include <stdio.h>"])

Defines: HAVE_DECL_NULL, HAVE_DECL_STDOUT, HAVE_DECL_STDERR

PARAMETERS

NameDescriptionDefault Value
symbolsList of symbol names to check.none
includesOptional list of include directives (e.g. ["#include <stdio.h>"]).None
compile_definesOptional list of preprocessor define names (applies to all checks).None
languageLanguage to use for checks ("c" or "cpp")."c"
requiresRequirements that must be met (applies to all checks).None
if_trueValue to use when check succeeds (applies to all checks).None
if_falseValue to use when check fails (applies to all checks).None
substSubst behavior (applies to all checks).None

RETURNS

List of JSON-encoded check strings.

macros.AC_CHECK_FUNCS

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

macros.AC_CHECK_FUNCS(functions, *, code, language, compile_defines, requires, subst)

Check multiple functions, creating HAVE_ defines (AC_CHECK_FUNCS).

GNU Autoconf's AC_CHECK_FUNCS(function, ...) checks whether each function is available (linkable). This macro runs AC_CHECK_FUNC for each function and sets HAVE_ following autoconf conventions.

Upstream: https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.72/autoconf.html#index-AC_005fCHECK_002dFUNC

M4 example (configure.ac): AC_CHECK_FUNCS([malloc, free, printf])

Bazel example: load("//autoconf:checks.bzl", "macros") macros.AC_CHECK_FUNCS(["malloc", "free", "printf"])

Defines: HAVE_MALLOC, HAVE_FREE, HAVE_PRINTF

PARAMETERS

NameDescriptionDefault Value
functionsList of function names to check.none
codeCustom code to compile (applies to all checks).None
languageLanguage to use for checks ("c" or "cpp")."c"
compile_definesOptional list of preprocessor define names (applies to all checks).None
requiresRequirements that must be met (applies to all checks).None
substSubst behavior (applies to all checks).None

RETURNS

List of JSON-encoded check strings.

macros.AC_CHECK_HEADERS

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

macros.AC_CHECK_HEADERS(headers, *, language, includes, compile_defines, requires)

Check multiple headers, creating HAVE_

defines (AC_CHECK_HEADERS).

GNU Autoconf's AC_CHECK_HEADERS(header, ...) checks whether each header can be compiled. This macro runs AC_CHECK_HEADER for each header and sets HAVE_<HEADER_UPPER> (e.g. HAVE_STDIO_H) following autoconf conventions. Header names are turned into include directives as #include

.

Upstream: https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.72/autoconf.html#index-AC_005fCHECK_002dHEADERS

Original m4 example:

AC_CHECK_HEADERS([stdio.h, stdlib.h, string.h])

Example:

load("//autoconf:checks.bzl", "macros")
macros.AC_CHECK_HEADERS(["stdio.h", "stdlib.h", "string.h"])
# Defines: HAVE_STDIO_H, HAVE_STDLIB_H, HAVE_STRING_H

PARAMETERS

NameDescriptionDefault Value
headersList of header names to check (e.g. "sys/stat.h").none
languageLanguage to use for checks ("c" or "cpp")."c"
includesOptional list of include directives (e.g. ["#include <stdio.h>"]).None
compile_definesOptional list of preprocessor define names (applies to all checks).None
requiresRequirements that must be met (applies to all checks).None

RETURNS

List of JSON-encoded check strings.

macros.AC_CHECK_MEMBERS

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

macros.AC_CHECK_MEMBERS(aggregate_members, *, includes, language, compile_defines, requires,
                        if_true, if_false, subst)

Check multiple structure members, creating HAVE__ defines (AC_CHECK_MEMBERS).

GNU Autoconf's AC_CHECK_MEMBER(aggregate.member, ...) checks whether a structure member exists. This macro runs AC_CHECK_MEMBER for each "aggregate.member" and sets HAVE__ (e.g. HAVE_STRUCT_STAT_ST_RDEV). Use includes with #include <foo> for headers that declare the aggregate.

Upstream: https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.72/autoconf.html#index-AC_005fCHECK_002dMEMBER

M4 example (configure.ac): AC_CHECK_MEMBERS([struct stat.st_rdev, struct tm.tm_zone], [], [], [[#include <sys/stat.h>]]) AC_CHECK_MEMBER([struct stat.st_rdev], [], [], [[#include <sys/stat.h>]])

Bazel example (use #include <foo> in includes): load("//autoconf:checks.bzl", "macros") macros.AC_CHECK_MEMBERS( ["struct stat.st_rdev", "struct tm.tm_zone"], includes = ["#include <sys/stat.h>", "#include <time.h>"], )

PARAMETERS

NameDescriptionDefault Value
aggregate_membersList of member specs (e.g. ["struct stat.st_rdev"]).none
includesOptional list of include directives (e.g. ["#include <sys/stat.h>"]).None
languageLanguage to use for checks ("c" or "cpp")."c"
compile_definesOptional list of preprocessor define names (applies to all checks).None
requiresRequirements that must be met (applies to all checks).None
if_trueValue to use when check succeeds (applies to all checks).None
if_falseValue to use when check fails (applies to all checks).None
substSubst behavior (applies to all checks).None

RETURNS

List of JSON-encoded check strings.

macros.AC_CHECK_TYPES

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

macros.AC_CHECK_TYPES(types, *, includes, language, compile_defines, requires, if_true, if_false,
                      subst)

Check multiple types, creating HAVE_ defines (AC_CHECK_TYPES).

GNU Autoconf's AC_CHECK_TYPE(type, ...) checks whether each type is defined. This macro runs AC_CHECK_TYPE for each type and sets HAVE_ (e.g. HAVE_SIZE_T) following autoconf conventions. Use includes with #include <foo> for the headers that declare the types.

Upstream: https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.72/autoconf.html#index-AC_005fCHECK_002dTYPE

M4 example (configure.ac): AC_CHECK_TYPES([size_t, pthread_t, pid_t], [], [], [[#include <stddef.h>]]) AC_CHECK_TYPE([pthread_t], [], [], [[#include <pthread.h>]])

Bazel example (use #include <foo> in includes): load("//autoconf:checks.bzl", "macros") macros.AC_CHECK_TYPES(["size_t", "pthread_t", "pid_t"], includes = ["#include <stddef.h>", "#include <pthread.h>"])

Defines: HAVE_SIZE_T, HAVE_PTHREAD_T, HAVE_PID_T

PARAMETERS

NameDescriptionDefault Value
typesList of type names to check.none
includesOptional list of include directives (e.g. ["#include <stddef.h>"]).None
languageLanguage to use for checks ("c" or "cpp")."c"
compile_definesOptional list of preprocessor define names (applies to all checks).None
requiresRequirements that must be met (applies to all checks).None
if_trueValue to use when check succeeds (applies to all checks).None
if_falseValue to use when check fails (applies to all checks).None
substSubst behavior (applies to all checks).None

RETURNS

List of JSON-encoded check strings.

utils.AC_LANG_PROGRAM

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

utils.AC_LANG_PROGRAM(prologue, body)

Build program code from prologue and main body (AC_LANG_PROGRAM).

GNU Autoconf's AC_LANG_PROGRAM(prologue, body) expands to a complete test program: prologue (includes/declarations) followed by main() containing body. Use the result as the code argument to AC_TRY_COMPILE or AC_TRY_LINK.

Upstream: https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.72/autoconf.html#index-AC_005fLANG_005fPROGRAM

M4 example (configure.ac): AC_TRY_COMPILE([AC_LANG_PROGRAM([[#include <stdio.h>]], [printf("test");])], ...) AC_TRY_LINK([AC_LANG_PROGRAM([[#include <langinfo.h>]], [char* cs = nl_langinfo(CODESET); return !cs;])], ...)

Bazel example (use #include <foo> in the prologue list): load("//autoconf:checks.bzl", "utils", "checks") checks.AC_TRY_COMPILE( code = utils.AC_LANG_PROGRAM(["#include <stdio.h>"], "printf("test");"), define = "HAVE_PRINTF", ) checks.AC_TRY_LINK( code = utils.AC_LANG_PROGRAM( ["#include <langinfo.h>"], "char* cs = nl_langinfo(CODESET); return !cs;", ), define = "HAVE_LANGINFO_CODESET", )

PARAMETERS

NameDescriptionDefault Value
prologueList of strings (include directives or declarations), joined with newlines.none
bodyCode inside main() — a string, or a list of strings joined with newlines.none

RETURNS

A string suitable for the code parameter of AC_TRY_COMPILE or AC_TRY_LINK.