Skip to main content

Go SDK

RBS provides hermetic Go support with automatic Go SDK management, hermetic builds with GOPROXY=off, and cross-compilation via platform flags.

Setup

Toolchain

Register a Go toolchain in WORKSPACE.rbs:
RBS downloads the Go SDK for your platform and uses it for all Go builds.

Rules

go_library

Creates a reusable Go library (source packaging for dependents).
AttributeTypeDescription
namestringUnique target name (required).
srcslistGo source files (can include go.mod, go.sum, vendor files).
depslistLocal go_library dependencies.
cgoboolEnable CGO (default False).

go_binary

Creates an executable Go binary.
AttributeTypeDescription
namestringUnique target name (required).
srcslistGo source files (required).
depslistLocal go_library dependencies.
goflagslistExtra flags passed to go build (e.g., -ldflags).
cgoboolEnable CGO (default False).

go_test

Runs Go tests.

Hermetic Builds

By default, RBS runs Go builds with GOPROXY=off and GOSUMDB=off, ensuring the Go tool cannot fetch modules from the network at build time. All dependencies must be vendored or pre-fetched. For stdlib-only builds (no go.mod), RBS automatically sets GO111MODULE=off so go build works without a module root.

Cross-Compilation

Use the RBS_TARGET_PLATFORM environment variable to cross-compile:

Example