> ## Documentation Index
> Fetch the complete documentation index at: https://site.aspect.build/llms.txt
> Use this file to discover all available pages before exploring further.

# Examples

> Real-world examples of Starlark Gazelle extensions for Bazel, including a port of bzl_library from bazel-skylib and a Kotlin generator from the Aspect CLI repo.

## Ported from Go implementations

### bzl\_library

Here is a simple real-world example. Here we have ported the `bzl_library` generator from the Go code in bazel-skylib.

To query the Starlark language and gather all `load` statements, we use this Tree-sitter query:

```python theme={null}
"loads": aspect.AstQuery(
    grammar = "starlark",
    query = """(module
        (expression_statement
            (call 
                function: (identifier) @id
                arguments: (argument_list
                    (string) @path
                    (string)
                )
            )
            (#eq? @id "load")
        )
    )""",
)
```

Here's the full code listing: [bzl\_library.star](https://gist.github.com/alexeagle/89b73ebf321b886739fd8991f69aca30).

### Kotlin

As another example, we've ported the [Kotlin Go implementation](https://github.com/aspect-build/aspect-gazelle/tree/main/language/kotlin) to Starlark: [kotlin.star](https://gist.github.com/alexeagle/9f3e4c8a0847413ac802086e3f5a2f0e).

## From scratch

### PostCSS

A third-party OSS example: [postcss.star](https://github.com/walkerburgin/starlark-extensions-repro/blob/master/.aspect/cli/postcss.star).

### C++

This rudimentary [rules\_cc.axl extension](https://github.com/aspect-build/bazel-examples/blob/main/.aspect/gazelle/rules_cc.axl) demonstrates the value of being able to hard-code some dependencies like `@sqlite3`. It's not generalized enough to publish as a generic OSS extension, but it's much quicker to iterate on and solves basic cases.
