Skip to content

go_source

Reusable Go package sources, embedded files, data, and dependency metadata.

go_source performs no compilation. Connect it to go_library, go_binary, or go_test through the embed dependency role to compile its sources into the consuming package.

Common Go Attributes

The following attributes are also accepted by go_library, go_binary, and go_test.

AttributeTypeDefaultDescription
module_rootstringmanifest packageWorkspace-relative Go module root
package, package_rootstringtarget packageGo package pattern, with package_root as the Buck2-compatible alias
go_workstringemptyWorkspace-relative go.work file, otherwise GOWORK=off
mod_modestringvendorvendor or readonly; external modules require the vendor mode
gostringGo on PATHGo command override
goos, goarchstringhostDestination operating system and architecture
cc, cxxstringhost commandsC and C++ compilers used by cgo
importpath, importmapstringemptyPublic and compiler import identities
package_namestringemptyBuck2-compatible public import identity
importpath_aliaseslist<string>[]Bazel-compatible migration aliases
embedsrcs, embed_srcslist<string>[]Files consumed by //go:embed, with Bazel and Buck2 spellings
headerslist<string>[]Buck2-compatible cgo header inputs
header_namespacestringemptyBuck2-compatible logical header namespace retained during migration
data, resourceslist<string>[]Runtime data globs and their Buck2-compatible spelling
gc_goopts, compiler_flagslist<string>[]Go compiler options using Bazel or Buck2 spelling
assembler_flagslist<string>[]Go assembler options
tags, gotags, build_tagslist<string>[]Go build constraint tags
cgoboolfalseEnable cgo
purestringautoBazel-compatible cgo policy: on, off, or auto
copts, cppopts, cxxopts, clinkoptslist<string>[]Native compile, preprocessing, and link options propagated through cgo
envmap<string, string>{}Environment passed to Go build actions
trimpathbooltrueRemove host paths from compiled artifacts
racestringautoRace detector mode: auto, on, or off
msan, asanstringautoMemory or address sanitizer mode: auto, on, or off
pgoprofilestringemptyPackage-relative profile for profile-guided optimization
coverage, coverage_enabledboolfalseEnable coverage instrumentation
coverage_modestringemptyCoverage mode: set, count, or atomic

Dependency Edges

EdgeAcceptsDescription
depsgo_package, go_dependency_set, c_providerGo packages, locked modules, and native providers
embedgo_packageSources compiled into the same Go package
cdepsc_providerNative dependencies consumed through cgo

Providers and Capabilities

The target emits go_package and exposes build with no output group.

Released under an open-source license.