Skip to content

zig_library

Zig module provider.

Description

Defines a Zig module with a root source file and optional Zig or C provider dependencies. The target does not compile by itself. Downstream Zig binary, test, static library, and shared library targets compile modules at the use site so Zig can perform whole-program compilation.

If the module depends on a C provider, downstream Zig builds receive a generated c module from zig translate-c, plus the C compile and link inputs.

Canonical module names are generated from target labels with collision-safe escaping. import_names keys must match exactly one Zig module dependency by full label, short label name, import name, or canonical name; ambiguous or unknown keys fail validation.

Attributes

AttributeTypeRequiredDefaultDescription
mainstringyesPackage-relative root Zig module
import_namestringnotarget nameName downstream modules use with @import
import_namesmap<string, string>no{}Rename dependency imports by dependency label, short name, or import name
extra_srcslist<string>no[]Extra source or data globs included in dependent compile input digests
datalist<string>no[]Runtime data globs propagated to dependents
zigoptslist<string>no[]Extra flags attached to this module specification

Dependency Edges

EdgeAcceptsDescription
depszig_module, c_providerZig modules and C provider dependencies consumed by this module

Providers

The target emits zig_module.

Capabilities

CapabilityOutput groups
buildnone

Example

toml
[[target]]
name = "math"
kind = "zig_library"
srcs = ["src/**/*.zig"]

[target.attrs]
main = "src/math.zig"
import_name = "math"

Released under an open-source license.