Getting Started
Single-page view · as markdown
Pekit
Pekit / Getting Started
pekit is a build system. You describe what to build in GCSL, a typed scripting language, and pekit works out which steps that needs, runs each one in a sandbox, and keeps every result. When you build again, pekit runs only the steps whose inputs changed.
If you have used Bazel, pekit will be familiar: a build is a graph of cached, sandboxed actions, and the same inputs always give the same outputs. The difference is the language. A pekit build file is an ordinary GCSL program, so a build can compute what to build, and can decide what to do next from what an earlier step made.
The parts of a build #
These are the parts a build is made of:
- Workspace. A directory tree with a
workspace.gcslfile at its root. Everything pekit builds comes from a workspace. - Build file. A
.gcslfile in the workspace that declares what can be built. - Target. A definition in a build file that you can ask pekit to
build, such as
def build hello(). - Step. One cached, sandboxed piece of work, such as compiling a file.
A step is a call of a GCSL function marked
#[hermetic]. - Store. Where pekit keeps the result of every step, shared by every workspace on the machine.
- Output directory.
pekit-out/, at the workspace's root, where pekit puts what each target built.
A target's own code runs outside any sandbox and decides which steps to call. pekit runs the steps, as many at once as the machine allows, and gives their results back to the code that asked for them. Targets and Steps explains how the two fit together.
Why steps are sandboxed #
A step can see only what it's given: the files passed to it as arguments, and the results of the steps before it. pekit keys each step by exactly those inputs. So when none of them has changed, pekit knows the step would give the same result, and takes it from the store instead of running it. If a step could read anything else, a change to that file would go unnoticed, and pekit would reuse a stale result.
The same rule makes builds portable. A step sees the workspace at /w
and earlier results at /pekit-out, wherever your checkout is, so two
machines that build the same commit run the same steps.
What pekit does #
The pekit command builds targets, and also runs the other kinds of
definition a workspace can hold:
| Command | Does |
|---|---|
pekit build | Builds targets. |
pekit test | Runs tests, and doesn't rerun a passing test whose inputs didn't change. |
pekit run | Runs a script, or a program a target built. |
pekit query | Lists what targets reach, or which targets a file change reaches, without building. |
pekit lock | Pins the libraries a workspace imports. |
pekit package and pekit publish | Pack packages, and publish them into a package store. |
pekit release | Builds a package from a commit, checks that it's reproducible, publishes it, and tags the commit. |
pekit clean | Removes pekit-out/, and optionally the store. |
pekit(1) documents every command and option.
Where to go next #
Start with Building a First Program, which builds a C program from an empty directory. Then read Workspaces and the How Pekit Builds topic. pekit's build files are GCSL, and the GCSL documentation covers the language itself.
Building a First Program
Pekit / Getting Started
This page builds a one-file C program from an empty directory. Along the way it shows the parts every pekit build has: a workspace, a build file, a target, and a step. It takes about five minutes.
Before you start #
You need:
- pekit. To build it from its source, run
cargo install --git https://github.com/peios/pekit pekit --locked, orcargo install --path crates/pekit --lockedin a checkout. Building it needs a C compiler andmake, for the compression libraries and the memory allocator it links. - bubblewrap, the
bwrapprogram, which pekit runs every step in. - A C compiler from your distribution's packages, as
/usr/bin/cc. A step can see the host's/usr, but not/usr/local.
Create the workspace #
-
Make a directory for the workspace, and change into it:
-
Create an empty
workspace.gcsl. Its presence makes the directory a workspace; it can hold settings, but this one doesn't need any. -
Save this program as
hello.c:int
Write the build file #
Save this as build.gcsl, beside hello.c:
#[hermetic]
fn compile(source: File) -> File {
let compiled = exec(["cc", "-o", "hello", source.path])
= working_dir().file("hello")
}
def build hello() {
= compile(file("hello.c"))
}
The file declares two things:
compile, a function that runs the compiler on one source file and gives the program it made.#[hermetic]makes each call of it a step: pekit runs the call in a sandbox that holds onlysource, and keeps what it gives.working_dir()is the step's own directory, where the compiler writeshello.hello, a target.def builddeclares a definition you can name topekit build. Its body callscompilewith the filehello.c, found relative to the build file.
Build it #
-
Build the target:
pekit runs the one step, and shows what the target gave:
built /hello: 1 step run, 0 found in the store pekit-out/hello/compile/hello note: steps ran with the host's own tools, so this build is not hermeticThe note says that the step could use your machine's own tools, and this one did: it ran your
cc. That's fine to start with. Hermetic and Strict Builds explains how to build without them. -
Run the program:
It prints
Hello from pekit. -
Build again:
Nothing changed, so pekit takes the step's result from its store instead of running it:
built /hello: 0 steps run, 1 found in the store pekit-out/hello/compile/hello
Change the program #
-
In
hello.c, change the message toHello again. -
Build again. pekit sees that the step's input changed, and runs it:
built /hello: 1 step run, 0 found in the store pekit-out/hello/compile/hello -
Change the message back to
Hello from pekit, and build once more. pekit has run the step with that input before, so it finds the result in the store and runs nothing.
pekit tells a changed file by its contents, never by its modification time. Saving a file without changing it, or changing it and changing it back, rebuilds nothing.
Check the result #
pekit-out/hello/compile/hello is the program the last build made, and
./pekit-out/hello/compile/hello prints Hello from pekit. The path names
the target, hello, then the step that made the file, compile. Where
Results Go describes the rest of pekit-out/.
Next steps #
A real C build compiles and links many files, and uses a compiler pekit pins rather than the host's. The gcc library does both: see Building C. Targets and Steps explains what pekit did during each build.
Workspaces
Pekit / Getting Started
A workspace is the directory tree that pekit builds from. Its root holds a
file called workspace.gcsl, and every directory below the root belongs to
it. pekit finds the workspace from the directory you run it in, by looking
upward for the nearest workspace.gcsl, so you can run pekit from any
directory inside.
A pekit workspace is a GCSL workspace, so GCSL's rules for how files see each other apply unchanged. Workspaces in the GCSL documentation describes them.
Build files #
Any .gcsl file in the workspace can declare targets. A common layout puts
a build.gcsl in each directory beside the sources it builds:
workspace.gcsl
pekit.lock
app/
build.gcsl
main.c
lib/
build.gcsl
greet.c
greet.h
The files of one directory share their public declarations, and a
directory sees the public declarations of the directories above it. So a
helper declared in workspace.gcsl is available everywhere, and a target in
app/build.gcsl can call another in app/package.gcsl without an import.
To use a declaration from a sibling directory, import it by its path from
the root, as import lib.
A definition's full name is its directory and its name: app/hello is the
definition hello in app. Naming Targets
explains how you name one on the command line.
A relative path in a build file, such as file("main.c"), is relative to
the directory of the file it's written in. It's never relative to the
directory you run pekit from.
What pekit leaves out #
pekit reads build files from every directory of the workspace, except:
- A directory or file whose name starts with a dot, such as
.git. - A directory below the root that has a
workspace.gcslof its own. A nested workspace is a separate workspace, built on its own. - A path that
.gcslignoreat the root names. Use it for.gcslfiles that are data, such as test fixtures. Each line names one file or directory, relative to the root, and lines that start with#are comments.
These rules decide only which .gcsl files declare definitions. A build
can read any file under the root, hidden or not. A directory listing such
as dir(".").files() includes hidden files too, but it leaves out three
kinds of directory, with everything in them:
pekit-out/, the output directory. No build reads it as part of the workspace..gitat the root, the workspace's history.- A directory below the root that holds a
.gitof its own, file or directory: a nested checkout, a Git worktree, or a submodule. It's another repository, so a listing doesn't descend into it. A listing of that directory itself, such asdir("other").files(), still includes everything in it.
pekit still loads the .gcsl files of a nested checkout that isn't hidden
and has no workspace.gcsl of its own. To keep pekit out of one, or out of
a large output directory such as Cargo's target/, name it in
.gcslignore.
A step can take the whole workspace, by being given dir(".") at the root.
It receives everything under the root except .git and pekit-out/, so a
commit doesn't rerun the step, but any other file there does, whether or not
Git tracks it. Listing only what a step needs avoids those reruns.
workspace.gcsl and pekitconf #
workspace.gcsl is an ordinary GCSL file. It can be empty, and it can
declare helpers for the whole workspace. pekit also reads one value from
it, pekitconf, a record of the workspace's settings:
import Toolchain::* from "github.com/gcslib/gcc"
import Toolchain from toolchain
import keychain
pekitconf = {
toolchains = [Toolchain::C gcc_x86_64]
keychain = [{profile = "dev"; name = "signing"; file = "keys/test.pem"}]
}
Each field is optional:
toolchains. The compilers and other tools the workspace builds with. See Platforms and Toolchains.keychain. Where each secret the build uses is kept. See Using Secrets.packagers. The package formatspekit packagepacks into. See Packaging.contexts. Values for contexts that the workspace or its libraries declare, by name, ascontexts = {greeting = "Good morning"}. pekit sets each one for every target it builds. See Setting a Context for the Whole Workspace.
toolchains, keychain, and packagers each need the module the setting
belongs to: toolchain for toolchains, keychain for keychain, and
packaging for packagers. A library's import of the module counts, so
importing the gcc library is enough for toolchains. Each name in
contexts must be a context that some file of the workspace declares.
pekit refuses a pekitconf it can't read whole, rather than build without
part of it. It stops before building anything if pekitconf has a field
not in this list, such as one that an older or newer pekit reads, or sets
toolchains, keychain, or packagers without the module that declares
it. The error names the field and the fields pekit reads.
Files pekit adds #
pekit adds these to a workspace:
| Path | Holds | In version control |
|---|---|---|
pekit-out/ | What each target built, and the files of every step that ran. | Ignore it. |
.gcsl/libraries/ | The libraries pekit lock pinned, exported from their repositories. | Ignore it. Any build puts back a pinned library that's missing. |
pekit.lock | The commit each library is pinned at. | Commit it, so every checkout builds with the same libraries. |
Add pekit-out/ and .gcsl/ to your .gitignore. Everything else pekit
keeps, such as its store, is outside the workspace, in your cache
directory. Reuse and the Store describes it.