Gazelle: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 26: Line 26:
{{External|https://github.com/bazel-contrib/bazel-gazelle/blob/master/repository.md#repository-rules}}
{{External|https://github.com/bazel-contrib/bazel-gazelle/blob/master/repository.md#repository-rules}}
==Add a <tt>go_repository</tt> Rule to <tt>WORKSPACE</tt> File==
==Add a <tt>go_repository</tt> Rule to <tt>WORKSPACE</tt> File==
<syntaxhighlight lang='bash'>
bazel run //:gazelle -- update-repos golang.org/x/sys@v0.13.0
</syntaxhighlight>
adds the following line to the <code>WORKSPACE</code> file:
<syntaxhighlight lang='go'>
go_repository(
    name = "org_golang_x_sys",
    importpath = "golang.org/x/sys",
    sum = "h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=",
    version = "v0.13.0",
)
</syntaxhighlight>
==<tt>go_repository</tt>==
==<tt>go_repository</tt>==

Revision as of 07:26, 23 November 2024

External

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

https://github.com/bazel-contrib/bazel-gazelle#gazelle-build-file-generator

Repository Rules

https://github.com/bazel-contrib/bazel-gazelle/blob/master/repository.md#repository-rules

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",
)

go_repository