Skip to content

Latest commit

 

History

History
124 lines (88 loc) · 4.43 KB

workspace.rst

File metadata and controls

124 lines (88 loc) · 4.43 KB

Go workspace rules

Workspace rules are either repository rules, or macros that are intended to be used from the WORKSPACE file.

See also the toolchains rules, which contains the go_register_toolchains workspace rule.


Registers external dependencies needed by rules_go, including the Go toolchain and standard library. All the other workspace rules and build rules assume that this rule is placed in the WORKSPACE.

When nested workspaces arrive this will be redundant, but for now you should always call this macro from your WORKSPACE.

The macro takes no arguments and returns no results. You put

go_rules_dependencies()

in the bottom of your WORKSPACE file and forget about it.

The list of dependencies it adds is quite long, there are a few listed below that you are more likely to want to know about and override, but it is by no means a complete list.

It won't override repositories that were declared earlier, so you can replace any of these with a different version by declaring it before calling this macro.

This rule has moved. See go_repository in the Gazelle repository.

You can override a dependency declared in go_rules_dependencies by declaring a repository rule in WORKSPACE with the same name before the call to go_rules_dependencies.

For example, this is how you would override org_golang_x_sys.

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "io_bazel_rules_go",
    urls = ["https://github.com/bazelbuild/rules_go/releases/download/0.14.0/rules_go-0.14.0.tar.gz"],
    sha256 = "5756a4ad75b3703eb68249d50e23f5d64eaf1593e886b9aa931aa6e938c4e301",
)

http_archive(
    name = "bazel_gazelle",
    urls = ["https://github.com/bazelbuild/bazel-gazelle/releases/download/0.14.0/bazel-gazelle-0.14.0.tar.gz"],
    sha256 = "c0a5739d12c6d05b6c1ad56f2200cb0b57c5a70e03ebd2f7b87ce88cabf09c7b",
)

load("@bazel_gazelle//:deps.bzl", "go_repository")

go_repository(
    name = "org_golang_x_sys",
    commit = "57f5ac02873b2752783ca8c3c763a20f911e4d89",
    importpath = "golang.org/x/sys",
)

load("@io_bazel_rules_go//go:def.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()

go_register_toolchains()

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

gazelle_dependencies()