• Stars
    star
    2,435
  • Rank 18,894 (Top 0.4 %)
  • Language Starlark
  • License
    Apache License 2.0
  • Created over 6 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Starlark Language

Starlark

Build status

Overview

Starlark (formerly known as Skylark) is a language intended for use as a configuration language. It was designed for the Bazel build system, but may be useful for other projects as well. This repository is where Starlark features are proposed, discussed, and specified. It contains information about the language, including the specification. There are multiple implementations of Starlark.

Starlark is a dialect of Python. Like Python, it is a dynamically typed language with high-level data types, first-class functions with lexical scope, and garbage collection. Independent Starlark threads execute in parallel, so Starlark workloads scale well on parallel machines. Starlark is a small and simple language with a familiar and highly readable syntax. You can use it as an expressive notation for structured data, defining functions to eliminate repetition, or you can use it to add scripting capabilities to an existing application.

A Starlark interpreter is typically embedded within a larger application, and the application may define additional domain-specific functions and data types beyond those provided by the core language. For example, Starlark was originally developed for the Bazel build tool. Bazel uses Starlark as the notation both for its BUILD files (like Makefiles, these declare the executables, libraries, and tests in a directory) and for its macro language, through which Bazel is extended with custom logic to support new languages and compilers.

Design Principles

  • Deterministic evaluation. Executing the same code twice will give the same results.
  • Hermetic execution. Execution cannot access the file system, network, system clock. It is safe to execute untrusted code.
  • Parallel evaluation. Modules can be loaded in parallel. To guarantee a thread-safe execution, shared data becomes immutable.
  • Simplicity. We try to limit the number of concepts needed to understand the code. Users should be able to quickly read and write code, even if they are not experts. The language should avoid pitfalls as much as possible.
  • Focus on tooling. We recognize that the source code will be read, analyzed, modified, by both humans and tools.
  • Python-like. Python is a widely used language. Keeping the language similar to Python can reduce the learning curve and make the semantics more obvious to users.

Tour

The code provides an example of the syntax of Starlark:

# Define a number
number = 18

# Define a dictionary
people = {
    "Alice": 22,
    "Bob": 40,
    "Charlie": 55,
    "Dave": 14,
}

names = ", ".join(people.keys())  # Alice, Bob, Charlie, Dave

# Define a function
def greet(name):
    """Return a greeting."""
    return "Hello {}!".format(name)

greeting = greet(names)

above30 = [name for name, age in people.items() if age >= 30]

print("{} people are above 30.".format(len(above30)))

def fizz_buzz(n):
    """Print Fizz Buzz numbers from 1 to n."""
    for i in range(1, n + 1):
        s = ""
        if i % 3 == 0:
            s += "Fizz"
        if i % 5 == 0:
            s += "Buzz"
        print(s if s else i)

fizz_buzz(20)

If you've ever used Python, this should look very familiar. In fact, the code above is also a valid Python code. Still, this short example shows most of the language. Starlark is indeed a very small language.

For more information, see:

Build API

The first use-case of the Starlark language is to describe builds: how to compile a C++ or a Scala library, how to build a project and its dependencies, how to run tests. Describing a build can be surprisingly complex, especially as a codebase mixes multiple languages and targets multiple platforms.

In the future, this repository will contain a complete description of the build API used in Bazel. The goal is to have a clear specification and precise semantics, in order to interoperate with other systems. Ideally, other tools will be able to understand the build API and take advantage of it.

Evolution

Read about the design process if you want to suggest improvements to the specification. Follow the mailing-list to discuss the evolution of Starlark.

Implementations, tools, and users

See the Starlark implementations, tools, and users page.

More Repositories

1

bazel

a fast, scalable, multi-language and extensible build system
Java
22,794
star
2

bazelisk

A user-friendly launcher for Bazel.
Go
2,060
star
3

rules_go

Go rules for Bazel
Go
1,356
star
4

bazel-gazelle

Gazelle is a Bazel build file generator for Bazel projects. It natively supports Go and protobuf, and it may be extended to support new languages and custom rule sets.
Go
1,156
star
5

rules_docker

Rules for building and handling Docker images with Bazel
Starlark
1,074
star
6

buildtools

A bazel BUILD file formatter and editor
Go
1,007
star
7

examples

Examples for Bazel
Starlark
831
star
8

intellij

IntelliJ plugin for Bazel projects
Java
762
star
9

rules_rust

Rust rules for Bazel
Starlark
660
star
10

bazel-buildfarm

Bazel remote caching and execution service
Java
650
star
11

tulsi

An Xcode Project Generator For Bazel
Swift
547
star
12

rules_python

Bazel Python Rules
Starlark
521
star
13

rules_apple

Bazel rules to build apps for Apple platforms.
Starlark
509
star
14

bazel-watcher

Tools for building Bazel targets when source files change.
Go
440
star
15

bazel-skylib

Common useful functions and rules for Bazel
Starlark
393
star
16

sandboxfs

A virtual file system for sandboxing
Rust
371
star
17

rules_scala

Scala rules for Bazel
Starlark
360
star
18

rules_kotlin

Bazel rules for Kotlin
Kotlin
331
star
19

remote-apis

An API for caching and execution of actions on a remote system.
Go
328
star
20

rules_swift

Bazel rules to build Swift on Apple and Linux platforms
Starlark
311
star
21

rules_k8s

This repository contains rules for interacting with Kubernetes configurations / clusters.
Starlark
289
star
22

rules_typescript

MOVED to https://github.com/bazelbuild/rules_nodejs/tree/3.x/third_party/github.com/bazelbuild/rules_typescript
TypeScript
275
star
23

continuous-integration

Bazel's Continuous Integration Setup
Python
258
star
24

bazel-central-registry

The central registry of Bazel modules for the Bzlmod external dependency system.
Starlark
247
star
25

rules_pkg

Bazel rules for creating packages of many types (zip, tar, deb, rpm, ...)
Starlark
225
star
26

rules_cc

C++ Rules for Bazel
Starlark
184
star
27

bazel-toolchains

Repository that hosts Bazel toolchain configs for remote execution and related support tools.
Go
183
star
28

rules_android

Android rules for Bazel
Starlark
175
star
29

rules_proto

Protocol buffer rules for Bazel
Starlark
163
star
30

rules_closure

Closure rules for Bazel
Java
153
star
31

vim-bazel

Vim support for Bazel
Vim Script
144
star
32

platforms

Constraint values for specifying platforms and toolchains
Starlark
108
star
33

stardoc

Stardoc: Starlark Documentation Generator
Java
107
star
34

proposals

Index of all Bazel proposals and design documents
106
star
35

rules_webtesting

Bazel rules to allow testing against a browser with WebDriver.
Go
96
star
36

apple_support

Apple support for Bazel rules
Starlark
83
star
37

emacs-bazel-mode

Emacs mode for Bazel
Emacs Lisp
80
star
38

rules_license

Starlark
77
star
39

rules_java

Java rules for Bazel
Starlark
72
star
40

reclient

Go
65
star
41

setup-bazelisk

Set up your GitHub Actions workflow with a specific version of Bazelisk
TypeScript
56
star
42

rules_sass

Sass rules for Bazel
Starlark
51
star
43

remote-apis-sdks

This repository contains client libraries for the Remote Execution API https://github.com/bazelbuild/remote-apis
Go
48
star
44

bazel-federation

Starlark
47
star
45

skydoc

Documentation generator for Skylark
Python
46
star
46

migration-tooling

Migration tools for Bazel
Java
44
star
47

codelabs

Shell
39
star
48

BUILD_file_generator

Generate BUILD files for your Java files
Java
39
star
49

eclipse

Eclipse For Bazel (deprecated, see https://github.com/salesforce/bazel-eclipse instead)
Java
32
star
50

bazel-integration-testing

Framework for integration tests that call Bazel
Java
32
star
51

rules_appengine

AppEngine rules for Bazel
Starlark
30
star
52

rules_android_ndk

Starlark
29
star
53

tools_remote

Java
28
star
54

bazel-bench

Benchmarking tool for bazel
Python
27
star
55

vim-ft-bzl

Vim Script
27
star
56

rules_perl

Perl rules for Bazel
Starlark
25
star
57

tools_android

Tools for use with building Android apps with Bazel
Starlark
24
star
58

homebrew-tap

This repository contains a collection of Homebrew (aka, Brew) "formulae" for Bazel
24
star
59

rules_d

D rules for Bazel
Starlark
24
star
60

bazel-blog

Content of the Bazel blog
HTML
20
star
61

bzlmod

Go
20
star
62

rules_testing

Starlark testing framework and utility libraries
Starlark
20
star
63

rules_gwt

Bazel rules for GWT
Starlark
19
star
64

bazel-website

Website for Bazel, a fast, scalable, multi-language and extensible build system
HTML
17
star
65

bazelcon

Artifacts from BazelCon
15
star
66

java_tools

Python
12
star
67

rules_groovy

Groovy rules for Bazel
Starlark
11
star
68

rules_postcss

PostCSS rules for Bazel
Starlark
10
star
69

rules_platform

Starlark
8
star
70

bazel_metrics

Python
7
star
71

community

Resources for community management efforts, such as SIGs
6
star
72

rules_angular

OBSOLETE see https://github.com/angular/angular/tree/master/packages/bazel
Python
5
star
73

gmaven_rules

This repository is deprecated. Please instead use https://github.com/bazelbuild/rules_jvm_external
Python
3
star
74

rules_utp

Starlark
2
star
75

.allstar

1
star
76

.github

1
star
77

bazel-worker-api

Java
1
star
78

build-event-stream

1
star
79

rules_sh

1
star