extensions.md

May 19, 2026 ยท View on GitHub

Extensions for bzlmod.

zig

zig = use_extension("@rules_zig//zig:extensions.bzl", "zig")
zig.toolchain(name, default, extra_exec_compatible_with, extra_target_compatible_with,
              extra_target_settings, zig_version)
zig.extra_exec_compatible_with(constraints)
zig.extra_target_compatible_with(constraints)
zig.extra_target_settings(settings)
zig.index(file)
zig.mirrors(urls)

Installs a Zig toolchain.

Every module can define multiple toolchain versions. All these versions will be registered as toolchains and you can select the toolchain using the @zig_toolchains//:version build flag.

The latest version will be the default unless the root module explicitly declares one as the default.

TAG CLASSES

toolchain

Fetch and define toolchain targets for the given Zig SDK version.

Defaults to the latest known version.

Attributes

NameDescriptionTypeMandatoryDefault
nameA descriptive suffix for generated toolchain targets. Leave empty for the default wrapper names.Nameoptional""
defaultMake this the default Zig SDK version. Can only be used once, and only in the root module.BooleanoptionalFalse
extra_exec_compatible_withAdditional execution platform constraints for generated Zig SDK toolchain targets.List of labelsoptional[]
extra_target_compatible_withAdditional target platform constraints for generated Zig SDK toolchain targets.List of labelsoptional[]
extra_target_settingsAdditional target settings for generated Zig SDK toolchain targets.List of labelsoptional[]
zig_versionThe Zig SDK version.Stringrequired

extra_exec_compatible_with

Add execution platform constraints to all generated Zig SDK toolchain targets.

Attributes

NameDescriptionTypeMandatoryDefault
constraintsAdditional execution platform constraints for generated Zig SDK toolchain targets.List of labelsoptional[]

extra_target_compatible_with

Add target platform constraints to all generated Zig SDK toolchain targets.

Attributes

NameDescriptionTypeMandatoryDefault
constraintsAdditional target platform constraints for generated Zig SDK toolchain targets.List of labelsoptional[]

extra_target_settings

Add target settings to all generated Zig SDK toolchain targets.

Attributes

NameDescriptionTypeMandatoryDefault
settingsAdditional target settings for generated Zig SDK toolchain targets.List of labelsoptional[]

index

Extend the set of known Zig SDK versions based on a Zig version index.

The provided index must use a schema that is compatible with the upstream index.

Attributes

NameDescriptionTypeMandatoryDefault
fileThe Zig version index JSON file.Labelrequired

mirrors

Attributes

NameDescriptionTypeMandatoryDefault
urlsThe mirrors base URLs.List of stringsrequired