Scripts2026年7月18日·1 分钟阅读

Starlark — Configuration Language for Build Systems

A deterministic dialect of Python designed for configuration and build system definitions, used by Bazel, Buck2, and other build tools.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Starlark Config Language
直接安装命令
npx -y tokrepo@latest install 3ff0e9fb-82e9-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

Starlark (formerly known as Skylark) is a configuration language designed by Google for use in build systems. It is a strict subset of Python with intentional restrictions — no classes, no exceptions, no mutation after freezing — that guarantee deterministic, hermetic evaluation suitable for parallel and cached builds.

What Starlark Does

  • Defines build targets, rules, and dependencies in a Python-like syntax
  • Guarantees deterministic evaluation for reproducible builds
  • Provides sandboxed execution with no file I/O or network access
  • Enables macro and rule authoring for custom build logic
  • Powers configuration in Bazel, Buck2, Pants, and other build systems

Architecture Overview

Starlark is an interpreted language with a two-phase execution model: a loading phase that evaluates BUILD files and produces a dependency graph, and an analysis phase that resolves configurations. The language is frozen after loading — all values become immutable — preventing non-determinism. Implementations exist in Go (go.starlark.net), Java (within Bazel), and Rust.

Self-Hosting & Configuration

  • Used automatically when writing BUILD or .bzl files for Bazel
  • Go implementation available: go get go.starlark.net/starlark
  • Rust implementation: starlark-rust crate for embedding
  • REPL available via starlark command for interactive testing
  • Linting via Buildifier for Bazel-specific Starlark files

Key Features

  • Python-like syntax with near-zero learning curve for Python developers
  • Guaranteed termination — no while loops or recursion allowed
  • Hermetic execution with no side effects or I/O
  • First-class functions and comprehensions for expressive configs
  • Parallel-safe evaluation due to immutability after load phase

Comparison with Similar Tools

  • CUE — Stronger typing and validation; Starlark is more flexible and imperative
  • Jsonnet — Similar functional config language; Starlark has Python syntax
  • Nickel — Contract-based with gradual typing; newer and less ecosystem support
  • HCL (Terraform) — Domain-specific for infrastructure; Starlark is general-purpose for builds

FAQ

Q: Is Starlark the same as Python? A: No. It is a subset with no classes, exceptions, global state, or I/O. Most simple Python expressions work, but programs that depend on mutation or side effects do not.

Q: Can I use Starlark outside of Bazel? A: Yes. The Go and Rust implementations can be embedded in any application as a configuration or scripting language.

Q: Why does Starlark forbid while loops? A: To guarantee termination. All iteration uses for loops over finite sequences, ensuring every evaluation completes in bounded time.

Q: How do I debug Starlark code? A: Use the print() function for logging during evaluation, or use the interactive REPL. Bazel also provides --output=starlark for query debugging.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产