Skip to content

go_binary

Buildable and runnable Go executable or exported native library.

The target accepts every common Go attribute plus the link and run attributes below.

Attributes

AttributeTypeDefaultDescription
outstringemptyExact output file name
basename, output_namestringtarget nameBazel and Buck2 output base-name spellings
build_modestringexeexe, pie, plugin, c-archive, c-shared, shared, or archive
linkmodestringautoBazel-compatible build mode alias
link_stylestringstaticBuck2-compatible static, static_pic, or shared style
link_modestringautoBuck2-compatible Go linker mode: auto, internal, or external
gc_linkopts, linker_flagslist<string>[]Go linker options
external_linker_flagslist<string>[]Options passed to the external linker
x_defsmap<string, string>{}Link-time string definitions lowered to -X
stripboolfalseStrip symbol and debugging tables
staticstringautoStatic linking policy: auto, on, or off
android_abistringinferredAndroid Application Binary Interface directory for C shared outputs
generate_exported_headerboolfalseBuck2-compatible request for the header emitted by C archive and C shared modes
argslist<string>[]Arguments passed by once run
run_envmap<string, string>{}Runtime environment values
env_inheritlist<string>[]Host environment names inherited before run_env overrides

The dependency roles match go_source.

Providers

The target emits Go package and binary providers. c-archive and c-shared also emit the generic C and native-linkable providers, including the generated header and transitive native metadata.

Capabilities and Outputs

CapabilityOutput groupsRequires
buildbinarynone
rundefaultbinary

Only exe and pie can run. Other build modes remain buildable outputs. once run writes its log and result marker under .once/out/<target>/run/.

Starter

The go-binary-minimal starter contains one executable and no external dependencies. Discover its descriptor through once query schema go_binary, then create it with once edit materialize-example go_binary go-binary-minimal.

Released under an open-source license.