Skip to content

Latest commit

 

History

History
111 lines (77 loc) · 4.75 KB

File metadata and controls

111 lines (77 loc) · 4.75 KB

Rules to declare Zig toolchains.

zig_target_toolchain

load("@rules_zig//zig:toolchain.bzl", "zig_target_toolchain")

zig_target_toolchain(name, dynamic_linker, target)

Defines a Zig target configuration toolchain.

The Zig compiler toolchain, defined by the zig_toolchain rule, has builtin cross-compilation support. Meaning, most Zig toolchains can target any platform supported by Zig independent of the execution platform.

Therefore, there is no need to couple the execution platform with the target platform, at least not by default.

Use this rule to configure a Zig target platform and declare the corresponding Bazel target platform constraints using the builtin toolchain rule.

Use the target @rules_zig//zig/target:resolved_toolchain to access the resolved toolchain for the current target platform. You can build this target to obtain a JSON file capturing the relevant Zig compiler flags.

See https://bazel.build/extending/toolchains#defining-toolchains.

EXAMPLE

zig_target_toolchain(
    name = "x86_64-linux",
    target = "x86_64-linux",
)

toolchain(
    name = "x86_64-linux_toolchain",
    target_compatible_with = [
        "@platforms//os:linux",
        "@platforms//cpu:x86_64",
    ],
    toolchain = ":x86_64-linux",
    toolchain_type = "@rules_zig//zig/target:toolchain_type",
)

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
dynamic_linker The value of the --dynamic-linker flag. String optional ""
target The value of the -target flag. String required

zig_toolchain

load("@rules_zig//zig:toolchain.bzl", "zig_toolchain")

zig_toolchain(name, zig_cache, zig_exe, zig_exe_path, zig_lib, zig_lib_path, zig_version)

Defines a Zig compiler toolchain.

The Zig compiler toolchain, defined by the zig_toolchain rule, has builtin cross-compilation support. Meaning, most Zig toolchains can target any platform supported by Zig independent of the execution platform.

Therefore, there is no need to couple the execution platform with the target platform, at least not by default.

This rule configures a Zig compiler toolchain and the corresponding Bazel execution platform constraints can be declared using the builtin toolchain rule.

You will rarely need to invoke this rule directly. Instead, use the zig module extension provided by @rules_zig//zig:extensions.bzl.

Use the target @rules_zig//zig:resolved_toolchain to access the resolved toolchain for the current execution platform.

See https://bazel.build/extending/toolchains#defining-toolchains.

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
zig_cache The Zig cache directory prefix. Used for both the global and local cache. String required
zig_exe A hermetically downloaded Zig executable for the target platform. Label optional None
zig_exe_path Path to an existing Zig executable for the target platform. String optional ""
zig_lib Files of a hermetically downloaded Zig library for the target platform. List of labels optional []
zig_lib_path Absolute path to an existing Zig library for the target platform or a the path to a hermetically downloaded Zig library relative to the Zig executable. String optional ""
zig_version The Zig toolchain's version. String required