xx
.md

go_binary

go_binary builds one Go source file or one package directory with the selected managed SDK. The build runs during xx run; pass the returned dependency to deps when another task needs the output.

Arguments

ArgumentRequiredDescription
entry_pointYesProject-relative Go source file or package directory passed to go build.
depsNoDependencies activated before the build, in list order. Defaults to [].
outputNoProject-relative output file. Defaults to .xx/out/<entrypoint-name>.
flagsNoAdditional go build options. Use output instead of -o. Defaults to [].

The selected SDK is implicit; do not add go to deps. A source file uses its filename without extension for the default output. A package directory uses its directory name, while entry_point="." uses the project directory name. Windows adds .exe to default and custom outputs unless the name already ends with .exe, case-insensitively. xx creates missing parent directories.

Entrypoints and outputs must remain inside the project after symlinks are resolved. Outputs cannot replace entrypoints, name directories, or overlap another task's output.

Examples

Build one source file

load("@[email protected]", "go_binary")

go_binary(entry_point="main.go")

This writes .xx/out/main, or .xx/out/main.exe on Windows.

Build a package to a chosen path

load("@[email protected]", "go_binary")

go_binary(
    entry_point="cmd/server",
    output="bin/server",
)

Build a reproducible static binary

load("@[email protected]", "go_binary")
load("@os@1", "env_set")

go_binary(
    entry_point="cmd/server",
    output="dist/server",
    flags=["-trimpath", "-ldflags=-s -w"],
    deps=[env_set("CGO_ENABLED", "0")],
)