jevsnes.git / platforms / execution.bzl

The execution platform: the prelude's own default (local execution on the host's cpu/os) plus an OPT-IN remote action cache.

prelude//platforms:default hard-codes local-only execution, so no [buck2_re_client] config can make it use a cache. This rule is that same platform with remote_cache exposed. BUCK sets it from [buildbuddy] cache, which only the dev machine's user-level buckconfig provides (nixos-config modules/buildbuddy.nix, ~/.buckconfig.d/buildbuddy, together with the endpoint and key). Anywhere that file is absent (CI, another machine) the flag is false and this is exactly the prelude default, so the repo never needs the cache or its credentials to build.

Cache-only: actions always run locally; the cache is checked first and local results are uploaded. Measured 2026-09-23: a clean rebuild and a second checkout at another path both hit 100%. Kept identical across the estate's buck2 repos on purpose; change it everywhere or nowhere.

18load("@prelude//cfg/exec_platform:marker.bzl", "get_exec_platform_marker")
20def _cached_execution_platform_impl(ctx: AnalysisContext) -> list[Provider]:
21    constraints = dict()
22    constraints.update(ctx.attrs.cpu_configuration[ConfigurationInfo].constraints)
23    constraints.update(ctx.attrs.os_configuration[ConfigurationInfo].constraints)
24    cfg = ConfigurationInfo(constraints = constraints, values = {})
25
26    name = ctx.label.raw_target()
27    platform = ExecutionPlatformInfo(
28        label = name,
29        configuration = cfg,
30        executor_config = CommandExecutorConfig(
31            local_enabled = True,
32            remote_enabled = False,
33            remote_cache_enabled = ctx.attrs.remote_cache,
34            allow_cache_uploads = ctx.attrs.remote_cache,
35            use_windows_path_separators = ctx.attrs.use_windows_path_separators,
36        ),
37    )
38
39    return [
40        DefaultInfo(),
41        platform,
42        PlatformInfo(label = str(name), configuration = cfg),
43        ExecutionPlatformRegistrationInfo(
44            platforms = [platform],
45            exec_marker_constraint = get_exec_platform_marker(),
46        ),
47    ]
48
49cached_execution_platform = rule(
50    impl = _cached_execution_platform_impl,
51    attrs = {
52        "cpu_configuration": attrs.dep(providers = [ConfigurationInfo]),
53        "os_configuration": attrs.dep(providers = [ConfigurationInfo]),
54        "remote_cache": attrs.bool(),
55        "use_windows_path_separators": attrs.bool(),
56    },
57)