Title: Running Gazelle on Gazelle
Slug: running-bazel-gazelle-on-gazelle
Date: 2023-04-01 09:15:00
Author: Kartones
Lang: en
Tags: Development, Bazel, Gazelle, Go, Tools
og_image:
Description: How to use Gazelle, a tool for automating Bazel BUILD file management, to build extensions for Go projects. It highlights the benefits of using Gazelle and showcases a small example.

[Gazelle](https://github.com/bazelbuild/bazel-gazelle) is a tool to automate Bazel BUILD file management. Initially, it was built for managing Go projects via Bazel, but it is extensible to other languages via implementing a few interfaces, or via protobuf.

I am building some extensions for it, which means using [Go](https://go.dev/). After learning a bit about the language, I'm structuring the code in submodules, and as both extensions and Gazelle itself are compiled via Bazel, this implies that you need to keep up to date BUILD files for the main module and each of the submodules.

Gazelle's original purpose is precisely for Go projects, so it should be able to help here. And indeed, Running `bazel run //:gazelle` from the extension source code root folder, it works nicely, rebuilding and updating all BUILD files as needed, and `bazel test //...` keeps all nice and green.

I also add a `# gazelle:myExtension disabled` directive to the root BUILD file, but Gazelle tests don't interfere with execution-time crawling so initially shouldn't be needed.

While a small dogfooding example, it is an excellent showcase about how useful this tool can be.
