rules_go_simple is a simple set of Bazel rules for building Go code. It
is intended to be a simple, clean, minimal example of how to write Bazel
rules for new languages.
The rules are divided into versions (v1, v2, etc.). Each version builds upon the last and includes all the functionality of the previous versions. The solutions are fully commented.
The process of writing each version is documented in a series of blog posts.
You can also find a slide deck for the workshop based on these rules.
- v1: A minimal
example of a rule that produces an executable (
go_binary). Described in Simple binary rule. - v2: Adds a small
rule that produces a library (
go_library). Described in Library rule, depsets, providers. - v3: Adds a
dataattribute. Described in Data and runfiles. - v4: Moves most of the implementation out of Starlark into a "builder" binary. Described in Moving logic to execution.
- v5: Downloads the Go distribution and registers a Bazel toolchain. Described in Repository rules.
- v6: Defines a module extension that selects a Go version, instantiates the previous repository rule, and registers toolchains to avoid redundant downloads. Described in Module extensions.