We’re excited to announce our open-source Rust library for working with the Starlark programming language, including a parser, evaluator, linter and debugger.
Starlark is a programming language designed for configuring applications. It sits between a full programming language (like Python) and a configuration language (like JSON or YAML), providing expressivity and abstraction, but with simplicity and determinism. As an example of where Starlark is used, consider the Buck build system. A simple Buck build file, written in Starlark, looks like:
android_library( name = 'activity', srcs = glob(['*.java']), visibility = [ 'PUBLIC' ], )
It’s not too hard to imagine what that might look like in JSON. But once you have 20 rules, you might want to abstract common details, like making visibility implicit, or adding some standard additional arguments. You might want to take some boolean arguments, or read configuration options. While formats like YAML/HOCON add some limited abstraction, sometimes you need to turn to something more powerful. Starlark offers functions and modules alongside a rich expression language.
But why not turn all the way to a programming language like Python? For a build system, there are three properties we want that Python doesn’t provide:
As an example of a potential problem with Python, consider a module that when evaluated increments a global variable - that would break all the properties above. The elegant solution of Starlark is that after a module is evaluated, its values are frozen, never to be mutated again. If you create a global variable, once the module that defines it finishes executing, it will be frozen - and thus immutable and no longer problematic. This freezing trick, combined with a few simplifications compared to regular Python, gives us Starlark.
Google uses Starlark in their Bazel build system, and wrote a specification for the language. Google engineers also wrote three implementations, in Go, Java and Rust. Facebook is starting to use more Rust, and configuration is always a big part of any project, so naturally the Rust Starlark library was very attractive. Therefore, thanks to the beauty of open source, we were able to fork Google’s Starlark Rust library and improve it, releasing our fork of the library. In cooperation with Google and the Starlark Rust authors, Facebook are now the maintainers of the Starlark Rust library - allowing Rust authors to easily embed Starlark into their projects.
For the Starlark Rust library, starting from the open-source base, we’ve been focusing on four dimensions:
This project was only possible thanks to the open source availability of the Starlark specification and implementations. In particular we owe a debt of gratitude to Damien Martin-Guillerez, who wrote the initial implementation. We’re happy to share our Starlark implementation with the Rust community, and welcome feedback, users and contributors.
Facebook’s Developer Infrastructure team, (DevInfra) owns most of the coding life cycle, from the time code leaves an engineer’s mind until it reaches the people who use our apps. Our mission is to increase developer efficiency so that we can continue to ship awesome products quickly. We lead the industry by building innovative developer tools and automation infrastructure that are reliable and fast, ensuring that every second of engineering time is spent on the things that matter.
Interested in working in Infrastructure at Facebook? Check out our job postings on our Infrastructure career page here.
To learn more about Facebook Open Source, visit our open source site, subscribe to our YouTube channel, or follow us on Twitter and Facebook.
Sign up for monthly updates from Meta for Developers.