Implementations
Starlark Implementations
Section titled “Starlark Implementations”Starlark has three major implementations, each with different strengths. This guide helps you choose the right one for your project.
Feature Comparison
Section titled “Feature Comparison”| Feature | starlark-go | starlark-rust (Buck2) | starlark-java (Bazel) |
|---|---|---|---|
| Language | Go | Rust | Java |
| Maintainer | Meta | Bazel team | |
| Type annotations | ✅ Basic | ✅ Full | ✅ via Java |
record type | ❌ | ✅ | ❌ |
enum type | ❌ | ✅ | ❌ |
| Union types | ❌ | ✅ | ❌ |
| LSP support | ❌ | ✅ | ❌ |
| DAP debugging | ❌ | ✅ | ❌ |
| Static analysis | ⚠️ Limited | ✅ Experimental | ⚠️ WIP |
| REPL | ✅ | ✅ | ❌ |
| Profiling | ✅ | ✅ | ✅ |
starlark-go
Section titled “starlark-go”Google’s reference implementation in Go. Best for embedding in Go applications.
go get go.starlark.net/starlarkStrengths
Section titled “Strengths”- Simple API - Easy to embed in Go projects
- Stable - Well-tested, production-ready
- Lightweight - Small binary size
- Good documentation - Clear examples and guides
Limitations
Section titled “Limitations”- No advanced type features (records, enums)
- No built-in LSP or debugging
- Limited static analysis
Example: Embedding
Section titled “Example: Embedding”package main
import ( "fmt" "log"
"go.starlark.net/starlark")
func main() { thread := &starlark.Thread{Name: "main"} globals, err := starlark.ExecFile(thread, "config.star", nil, nil) if err != nil { log.Fatal(err) }
if v, ok := globals["message"]; ok { fmt.Println(v) }}starlark-rust
Section titled “starlark-rust”Meta’s implementation in Rust. Powers Buck2 and has the most advanced type system.
# Add to Cargo.tomlstarlark = "0.12"Strengths
Section titled “Strengths”- Rich type system - Records, enums, union types
- Developer tools - Built-in LSP and DAP
- Performance - Optimized for large codebases
- Static analysis - Experimental type checking
Limitations
Section titled “Limitations”- More complex API than Go version
- Rust ecosystem required
- Heavier dependency
Example: Type-safe Code
Section titled “Example: Type-safe Code”# Works in starlark-rustBuildConfig = record( name = str, srcs = list[str], deps = field(list[str], []),)
Status = enum("debug", "release")
def build(config: BuildConfig, mode: Status) -> str: return "{}-{}".format(config.name, mode.value)LSP Features
Section titled “LSP Features”The starlark-rust LSP provides:
- Code completion
- Go to definition
- Hover documentation
- Diagnostics
- Signature help
starlark-java
Section titled “starlark-java”Bazel’s native implementation. Tightly integrated with the Bazel build system.
Strengths
Section titled “Strengths”- Bazel integration - Native to Bazel’s rule system
- Java interop - Easy to add Java-based builtins
- Mature - Powers Bazel’s entire rule ecosystem
Limitations
Section titled “Limitations”- Primarily designed for Bazel
- JVM dependency
- Less portable than Go/Rust versions
- Not published as a standalone library (lives inside Bazel’s monorepo)
Type System
Section titled “Type System”Bazel is working on static types (Issue #27370):
# Proposed syntax for Bazel static typesdef my_rule_impl(ctx: ctx) -> list[Provider]: ...Choosing an Implementation
Section titled “Choosing an Implementation”Use starlark-go when:
Section titled “Use starlark-go when:”- Building a Go application
- Need simple embedding
- Want minimal dependencies
- Targeting lightweight deployments
Use starlark-rust when:
Section titled “Use starlark-rust when:”- Building with Rust or need best performance
- Need advanced type features (records, enums)
- Want built-in LSP/DAP support
- Building a build system like Buck2
Use starlark-java when:
Section titled “Use starlark-java when:”- Working within Bazel ecosystem
- Need Java interoperability
- Building Bazel rules or extensions
Specification Compliance
Section titled “Specification Compliance”All implementations follow the Starlark specification. Language changes are decided at the spec level, not by individual implementations.
Feature Request Process
Section titled “Feature Request Process”To propose new Starlark language features:
- Open an issue on bazelbuild/starlark
- Discuss with maintainers from all implementations
- If accepted, update the specification
- Implementations add support
Example: Type annotations were requested via starlark-go #610, but redirected to the spec repo #106 for cross-implementation discussion.