Skip to content

c_library

C and C++ static library provider.

Description

Compiles C and C++ sources into object files, archives them into a static library when sources are present, and exposes headers plus link inputs through the c_provider record. Header-only targets are valid and still propagate include directories, definitions, and data.

Zig target kinds consume this provider directly. Other native target kinds can also read the same record fields by convention.

Object outputs preserve the workspace-relative source path under objects/, so sources with similar names such as foo-bar.c and foo_bar.c do not collide. The C compiler is probed for every source-bearing target. The C++ compiler is only probed when at least one source uses a C++ extension. Set archiver_identity when the selected archiver path is mutable and the action cache should distinguish different archiver builds.

Attributes

AttributeTypeRequiredDefaultDescription
compilerstringnocc on PATHC compiler path
cxx_compilerstringnoc++ on PATHC++ compiler path
archiverstringnoar on PATHStatic library archiver path
archiver_identitystringnoemptyStable archiver identity, such as a version or content digest, folded into action cache keys
hdrslist<string>no[]Public header files exposed to dependents
header_globslist<string>no[]Public header glob patterns exposed to dependents
includeslist<string>no[]Public include directories propagated to dependents
quote_includeslist<string>no[]Public quote include directories propagated as regular include directories
system_includeslist<string>no[]Public system include directories propagated to dependents
framework_includeslist<string>no[]Public framework search directories propagated to dependents
defineslist<string>no[]Definitions propagated to dependent compile actions
coptslist<string>no[]Compiler flags used by this target
linkoptslist<string>no[]Linker flags propagated to dependents
dynamic_librarieslist<string>no[]Prebuilt dynamic libraries propagated to dependents
android_abistringnoemptyAndroid Application Binary Interface directory for dynamic libraries
datalist<string>no[]Runtime data globs propagated to dependents
envmap<string, string>no{}Environment variables passed to compile and archive actions
output_namestringnotarget nameStatic library output name without prefix or extension

Dependency Edges

EdgeAcceptsDescription
depsc_providerC provider dependencies whose headers and link inputs are propagated

Providers

The target emits c_provider, native_linkable, apple_linkable, and android_native_library.

Provider Record

FieldTypeMeaning
archivestringStatic library output when sources are present
static_librarystringAlias for archive
static_librarieslist<string>Direct static libraries exposed by this target
dynamic_librarieslist<string>Direct dynamic libraries exposed by this target
objectslist<string>Object files compiled from this target's sources
headerslist<string>Direct public headers
include_dirslist<string>Direct public include directories
quote_include_dirslist<string>Direct quote include directories passed as regular include dirs
system_include_dirslist<string>Direct system include directories
framework_include_dirslist<string>Direct framework search directories
defineslist<string>Direct definitions
coptslist<string>Direct compiler options
linkoptslist<string>Direct linker options
transitive_headerslist<string>Direct and dependency headers
transitive_include_dirslist<string>Direct and dependency include directories
transitive_quote_include_dirslist<string>Direct and dependency quote include directories
transitive_system_include_dirslist<string>Direct and dependency system include directories
transitive_framework_include_dirslist<string>Direct and dependency framework search directories
transitive_defineslist<string>Direct and dependency definitions
transitive_static_librarieslist<string>Static libraries for dependents
transitive_dynamic_librarieslist<string>Dynamic libraries for dependents
transitive_linkoptslist<string>Linker flags for dependents
transitive_datalist<string>Runtime data propagated to dependents
transitive_archiveslist<string>Alias for transitive static library archive paths
android_native_librarieslist<record>Direct Android native-library records when android_abi is set
transitive_android_native_librarieslist<record>Direct and dependency Android native-library records
affected_inputslist<string>Source, header, and runtime inputs associated with this provider
default_outputstringStatic library output when sources are present

Capabilities

CapabilityOutput groups
buildlibrary

Example

toml
[[target]]
name = "native_math"
kind = "c_library"
srcs = ["src/*.c"]

[target.attrs]
hdrs = ["include/native_math.h"]
includes = ["include"]

Released under an open-source license.