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
| Attribute | Type | Required | Default | Description |
|---|---|---|---|---|
compiler | string | no | cc on PATH | C compiler path |
cxx_compiler | string | no | c++ on PATH | C++ compiler path |
archiver | string | no | ar on PATH | Static library archiver path |
archiver_identity | string | no | empty | Stable archiver identity, such as a version or content digest, folded into action cache keys |
hdrs | list<string> | no | [] | Public header files exposed to dependents |
header_globs | list<string> | no | [] | Public header glob patterns exposed to dependents |
includes | list<string> | no | [] | Public include directories propagated to dependents |
quote_includes | list<string> | no | [] | Public quote include directories propagated as regular include directories |
system_includes | list<string> | no | [] | Public system include directories propagated to dependents |
framework_includes | list<string> | no | [] | Public framework search directories propagated to dependents |
defines | list<string> | no | [] | Definitions propagated to dependent compile actions |
copts | list<string> | no | [] | Compiler flags used by this target |
linkopts | list<string> | no | [] | Linker flags propagated to dependents |
dynamic_libraries | list<string> | no | [] | Prebuilt dynamic libraries propagated to dependents |
android_abi | string | no | empty | Android Application Binary Interface directory for dynamic libraries |
data | list<string> | no | [] | Runtime data globs propagated to dependents |
env | map<string, string> | no | {} | Environment variables passed to compile and archive actions |
output_name | string | no | target name | Static library output name without prefix or extension |
Dependency Edges
| Edge | Accepts | Description |
|---|---|---|
deps | c_provider | C 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
| Field | Type | Meaning |
|---|---|---|
archive | string | Static library output when sources are present |
static_library | string | Alias for archive |
static_libraries | list<string> | Direct static libraries exposed by this target |
dynamic_libraries | list<string> | Direct dynamic libraries exposed by this target |
objects | list<string> | Object files compiled from this target's sources |
headers | list<string> | Direct public headers |
include_dirs | list<string> | Direct public include directories |
quote_include_dirs | list<string> | Direct quote include directories passed as regular include dirs |
system_include_dirs | list<string> | Direct system include directories |
framework_include_dirs | list<string> | Direct framework search directories |
defines | list<string> | Direct definitions |
copts | list<string> | Direct compiler options |
linkopts | list<string> | Direct linker options |
transitive_headers | list<string> | Direct and dependency headers |
transitive_include_dirs | list<string> | Direct and dependency include directories |
transitive_quote_include_dirs | list<string> | Direct and dependency quote include directories |
transitive_system_include_dirs | list<string> | Direct and dependency system include directories |
transitive_framework_include_dirs | list<string> | Direct and dependency framework search directories |
transitive_defines | list<string> | Direct and dependency definitions |
transitive_static_libraries | list<string> | Static libraries for dependents |
transitive_dynamic_libraries | list<string> | Dynamic libraries for dependents |
transitive_linkopts | list<string> | Linker flags for dependents |
transitive_data | list<string> | Runtime data propagated to dependents |
transitive_archives | list<string> | Alias for transitive static library archive paths |
android_native_libraries | list<record> | Direct Android native-library records when android_abi is set |
transitive_android_native_libraries | list<record> | Direct and dependency Android native-library records |
affected_inputs | list<string> | Source, header, and runtime inputs associated with this provider |
default_output | string | Static library output when sources are present |
Capabilities
| Capability | Output groups |
|---|---|
build | library |
Example
[[target]]
name = "native_math"
kind = "c_library"
srcs = ["src/*.c"]
[target.attrs]
hdrs = ["include/native_math.h"]
includes = ["include"]