xx
.md

zig_cc

zig_cc returns a dependency that sets CC to managed zig cc, sets CXX to managed zig c++, and puts Zig's executable directory first in PATH. With no target, Zig uses its host default. With a target, both compiler commands receive -target <target>.

Arguments

ArgumentRequiredDescription
targetNoNon-empty Zig target string forwarded as one command field. Omit it to use the host default.

The target must be valid for Zig. Dependencies apply in declared order, so later dependencies can replace PATH, CC, or CXX.

On macOS, builds that link system libraries need the macOS SDK. An os_xcode dependency before zig_cc() provides the SDK and keeps Zig first in PATH.

Examples

Use Zig for a host Go build

load("@go@1.26.5", "go_binary")
load("@zig@0.16.0", "zig_cc")

go_binary(
    entry_point="cmd/server",
    deps=[zig_cc()],
)

Select a compiler target

load("@go@1.26.5", "go_binary")
load("@zig@0.16.0", "zig_cc")

go_binary(
    entry_point="cmd/server",
    output="bin/server",
    deps=[zig_cc("x86_64-linux-gnu")],
)

Cross-compile a CGO program

load("@go@1.26.5", "go_binary")
load("@os@1", "env_set")
load("@zig@0.16.0", "zig_cc")

go_binary(
    entry_point="cmd/server",
    output="bin/server",
    deps=[
        zig_cc("x86_64-linux-gnu"),
        env_set("GOOS", "linux"),
        env_set("GOARCH", "amd64"),
        env_set("CGO_ENABLED", "1"),
    ],
)

The Go target variables must match Zig's target, and project dependencies must support the destination platform.