Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Build Files

A build file is a Lua file named build.lua. It says what can be built: which files go in, which command runs, and what comes out. It never runs that command itself. buildl reads every build file first, and only then decides what to run.

This chapter covers:

What a build file sees

A build file starts with two globals:

GlobalWhat it holds
buildlthe declaration functions: buildl.target, buildl.test, buildl.rule and the rest
airsstackthe helper modules json, path, regex, hash and glob, and buildl again

They are not two copies. buildl and airsstack.buildl are one table with two names, so most build files begin with a short local name for it:

local b = buildl

What a build file does not see

A build file must declare the same targets every time it is read, on every machine. So the parts of Lua that could make it answer differently are not there:

  • print is gone. A build file has nowhere to write to.
  • math.random and math.randomseed are gone. A random name would change on every run.
  • os, io, load and dofile are gone. A build file cannot read the clock, the environment or a file. require answers only airsstack itself, so it cannot load another build file's code either.

Calling one of them is an ordinary Lua error, and the build file fails:

-- build.lua
print(buildl == airsstack.buildl)
$ buildl check
error: build.lua: runtime error: lua error in build.lua: runtime error: build.lua:1: attempt to call a nil value (global 'print')
stack traceback:
	[C]: in global 'print'
	build.lua:1: in main chunk

buildl check reads every build file and runs nothing, which makes it the quickest way to see whether your build files are well formed. A build file that fails exits with code 5.

The one way a build file looks at the disk is buildl.sources, which lists files in its own directory. Inputs, Outputs and Dependencies covers it.