Gazelle is the standard tool for generating or updating Bazel build definitions (files namedDocumentation Index
Fetch the complete documentation index at: https://docs.aspect.build/llms.txt
Use this file to discover all available pages before exploring further.
BUILD, which Bazel uses to describe build targets) based on the content of source files.
Gazelle offers a Go API so you can extend it with support for additional languages.
See the Extending Gazelle documentation for details. Learning this API requires effort and adds a compile-time dependency for developers. Instead, you can use the Aspect Extension Language (AXL), a Starlark dialect, to write Starlark extensions that augment Gazelle.
Install Orion
Before you can write Gazelle extensions in Starlark, you need to configure Gazelle to include the “Orion” language. This hosts the Starlark interpreter inside the Gazelle runtime.Prebuilt
Theaspect-gazelle repo publishes pre-compiled binaries of Gazelle with the Orion language included.
See https://github.com/aspect-build/aspect-gazelle#install for instructions.
From source (advanced)
You can compile your own Gazelle from source and include the Orion language. Unlike the prebuilt approach, this lets you add your own Gazelle extensions written in Go. This includes first-party sources written in your repo, as well as third-party extensions not included in the prebuilt binary. Follow the standard setup instructions at https://github.com/bazel-contrib/bazel-gazelle#setup. Then add the https://github.com/aspect-build/aspect-gazelle/tree/main/language/orion Go module to your project, and finally add itsgo_library target to the languages list in gazelle_binary.
Define an extension
Start by registering the rule kinds your extension will generate. For example, to generateBUILD files that include:
prepare: Specify what information your extension needs from the source files, such as file extensions or regular expression queries.declare: Implement the logic to generate new build targets based on the collected information.
aspect.register_configure_extension() to register your extension with Gazelle. You can use named functions or anonymous lambdas as needed.
The following code continues the example:

