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
| Argument | Required | Description |
|---|---|---|
target | No | Non-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.
Examples
Use Zig for a host Go build
load("@[email protected]", "go_binary")
load("@[email protected]", "zig_cc")
go_binary(
entry_point="cmd/server",
deps=[zig_cc()],
)
Select a compiler target
load("@[email protected]", "go_binary")
load("@[email protected]", "zig_cc")
go_binary(
entry_point="cmd/server",
output="bin/server",
deps=[zig_cc("x86_64-linux-gnu")],
)
Cross-compile a CGO program
load("@[email protected]", "go_binary")
load("@os@1", "env_set")
load("@[email protected]", "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.