Jay added a Language
interface which allows it to be extended to more languages, which was originally used for Protocol Buffers.
List of languages
See https://github.com/bazel-contrib/bazel-gazelle#supported-languages:
Built-in to Gazelle:
- Go
- Protobuf
From Aspect:
- Kotlin
- JavaScript/TypeScript
From bazel-contrib (Linux Foundation):
- Python (transfer issue)
- Java
From others:
- Haskell (Tweag)
- R
- Rust
- Starlark
- Swift
Why aren’t there more available?
There are a ton of Gazelle extensions - but they’re mostly in private repositories. That’s because it’s so hard to generalize to support everyone else’s repository conventions.
Having an extension in your own repository has benefits. You can easily modify it to follow your local conventions, and to stamp out your own custom rules. We’ll see how writing extensions in Starlark gives you superpowers.
Writing your own extension
To write an extension in Go, you can follow the instructions here:
https://github.com/bazel-contrib/bazel-gazelle/blob/master/extend.md
However, writing a Go extension is hard work:
- The API is low-level and pretty awkward, and takes a while to learn. Uber has their own alternative API specifically to work around this.
- The API doesn’t have any opinion about how to parse the sources, and techniques vary widely.
- Need to learn Go if you don’t already.
- If you have Go code in your repo already, the deps in your
go.mod
become a mix of those needed for application code and those needed for extensions, sometimes causing conflicts.
It’s also awkward for OSS rulesets because of the distribution problems that come from having a Go dependency. bazel-skylib and rules_python both have gazelle extensions that require a separate Bazel module.