Gazelle: Difference between revisions
Line 27: | Line 27: | ||
==<tt>go_repository</tt>== | ==<tt>go_repository</tt>== | ||
{{External|https://github.com/bazel-contrib/bazel-gazelle/blob/master/repository.md#go_repository}} | {{External|https://github.com/bazel-contrib/bazel-gazelle/blob/master/repository.md#go_repository}} | ||
<code>go_repository</code> downloads a Go project and generates build files with Gazelle if they are not already present. This is the simplest way to depend on external Go projects. When <code>go_repository</code> is in module mode, it saves downloaded modules in a shared, internal cache within Bazel's cache. It may be cleared with: | |||
<syntaxhighlight lang='bash'> | |||
bazel clean --expunge | |||
</syntaxhighlight> | |||
<code>repositories.bzl</code> | <code>repositories.bzl</code> | ||
<font color=darkkhaki>Describe the relationship between <code>repositories.bzl</code> and <code>go.mod</code></font> | <font color=darkkhaki>Describe the relationship between <code>repositories.bzl</code> and <code>go.mod</code></font> | ||
==<tt>git_repository</tt>== | ==<tt>git_repository</tt>== | ||
{{External|https://github.com/bazel-contrib/bazel-gazelle/blob/master/repository.md#git_repository}} | {{External|https://github.com/bazel-contrib/bazel-gazelle/blob/master/repository.md#git_repository}} |
Revision as of 07:31, 23 November 2024
External
- https://github.com/bazel-contrib/bazel-gazelle/
- https://github.com/bazel-contrib/bazel-gazelle#gazelle-build-file-generator
Internal
Overview
Gazelle is a BUILD file generator for Bazel projects. It can create new BUILD.bazel
files for a project that follows language conventions, and it can update existing build files to include new sources, dependencies, and options.
Gazelle natively supports Go and protobuf.
Gazelle may be run by Bazel using the gazelle
rule:
bazel run //:gazelle
Alternatively, it may be installed and run as a command line tool.
Aside from generating BUILD files for the local source code, Gazelle can also generate build files for external repositories as part of the go_repository rule.
Generating BUILD Files
Repository Rules
go_repository
go_repository
downloads a Go project and generates build files with Gazelle if they are not already present. This is the simplest way to depend on external Go projects. When go_repository
is in module mode, it saves downloaded modules in a shared, internal cache within Bazel's cache. It may be cleared with:
bazel clean --expunge
repositories.bzl
Describe the relationship between repositories.bzl
and go.mod
git_repository
Deprecated.
Add a go_repository Rule to WORKSPACE File
bazel run //:gazelle -- update-repos golang.org/x/sys@v0.13.0
adds the following line to the WORKSPACE
file:
go_repository(
name = "org_golang_x_sys",
importpath = "golang.org/x/sys",
sum = "h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=",
version = "v0.13.0",
)