jevsnes.git / platforms / README.md
1# Chapter 30: platforms, where build actions run, and a cache
2
3Last chapter, and the most backstage. Every compile, link and test that
4buck2 runs is an *action*, and an *execution platform* says where actions
5may run: here, on this machine, or on a remote build farm, and whether a
6shared cache of results may be consulted first. `.buckconfig` names this
7folder's one platform, `root//platforms:execution`.
8
9It is the prelude's own default (run everything locally on the host's CPU
10and OS) with one switch exposed: an **opt-in remote action cache**. The
11prelude's default hard-codes local-only execution, so no amount of
12configuration elsewhere can make it use a cache; this rule is the same
13platform with that one door unlocked.
14
15```mermaid
16flowchart LR
17  action["a build action"] --> q{"[buildbuddy] cache = true?"}
18  q -- no --> local["run it locally (the prelude default)"]
19  q -- yes --> hit{"already in the remote cache?"}
20  hit -- yes --> done["use the cached result"]
21  hit -- no --> run["run it locally, upload the result"]
22```
23
24The switch is `read_config("buildbuddy", "cache", "false")`. Only a
25user-level buckconfig on the owner's development machine sets it, together
26with the cache's endpoint and key. Anywhere that file is absent (a fresh
27clone, CI, another machine) the flag is false and this is exactly the
28prelude default, so the repository never needs the cache, or its
29credentials, to build.
30
31> **Aside: cache-only, never remote execution.** Actions always run
32> locally; the cache is only checked first, and local results uploaded.
33> Measured 2026-09-23: a clean rebuild, and a second checkout at another
34> path, both hit 100%.
35
36> **Try it.** `grep -n -A1 '^\[build\]' .buckconfig` shows `.buckconfig`
37> selecting this platform. Without the user-level config it builds exactly
38> as the prelude's default would.
39
40That is the whole guide. Back to the [prologue](../) for the map.
41
42## For the people who maintain it
43
44### In this folder
45
46| Path | What |
47| --- | --- |
48| [BUCK](BUCK) | `cached_execution_platform(name = "execution", ...)`, with `remote_cache` from `[buildbuddy] cache` and the host's CPU and OS. |
49| [execution.bzl](execution.bzl) | The rule: the prelude's `ExecutionPlatformInfo` with `local_enabled = True`, `remote_enabled = False`, and `remote_cache_enabled`/`allow_cache_uploads` from the flag. |
50| [README.md](README.md) | This chapter. |
51| [CLAUDE.md](CLAUDE.md) | Keep it identical across repositories, for agents. |
52
53← Previous: [Chapter 29, toolchains/](../toolchains/) · Up: [jevsnes](../)