- List the source files, to create or update a
cc_librarytarget with those in thesrcs - Read the source files and find the
includestatements. - Each included symbol comes from a header file. Locate the
cc_librarytarget which provides the symbol and add it todeps. - Merge the results with the original BUILD file
# keep comment.
Gazelle extension written in Go
Gazelle has aLanguage interface allowing extensions to add support for more languages. EngFlow have open-sourced an extension, which expects import statements to be relative to the repository root:
https://github.com/EngFlow/gazelle_cc
Gazelle extension written in Starlark
Aspect CLI includes a bridge that allows writing extensions in Starlark, Bazel’s configuration language. See Extend Gazelle BUILD file generation for details. Here’s an example: https://github.com/aspect-build/bazel-examples/blob/main/.aspect/gazelle/rules_cc.axlDemo
We can modify source files in the bazel-examples repo and regenerate BUILD files with the Aspect CLI’sgazelle task: aspect gazelle. With the tools/bazel wrapper installed you can also type bazel gazelle; without the CLI, run the target directly with bazel run //tools/gazelle:gazelle.
