Browse documentation

The FPC build lives in toolchain.lock, and build.pas compiles with it when it is installed

Date: 2026-12-02 Area: build, ci Related: ADR 0169

Context

The engine needs a 3.3.1 build from fpc-toolchain, and CI pins one build of it. Until now each of six workflows named that build in its own FPC_VERSION variable, scripts/engine/build.sh named it again, and build.pas named it in the message it prints when the compiler is older than 3.3.1. build.pas ran whatever fpc came first on PATH.

fpc-toolchain installs builds side by side, under toolchains/<identity>/ in its root, and a machine's default fpc is often another build. On a machine whose default fpc was 3.2.4, ./build.pas runner stopped with "The engine needs FPC 3.3.1" although the pinned build was installed: every shell had to run eval "$(fpc-toolchain env 3.3.1+11)" first, and an agent's tool shell does not keep that between calls.

fpc-toolchain already has a project pin, toolchain.lock (identity, repo, sha256sums): its action installs the build a lock names when no version is given, install.sh --lock installs it and checks the release's SHA256SUMS against the lock, and fpc-toolchain check --lock refuses another compiler. Its fpc-<version> front-end runs a build's driver by its path with -n and that build's own etc/fpc.cfg, so neither PATH nor a ~/.fpc.cfg or ./fpc.cfg changes what compiles.

Decision

  • toolchain.lock in the repository root is the only place that selects the build. No workflow passes version, so the action reads the lock. pr.yml's build-main writes the PR's lock over its base checkout before installing, so both benchmark builds still use one compiler.
  • build.pas compiles with the pinned build whenever it is installed. source/shared/FPCToolchain.pas reads the lock's identity as fpc-toolchain does and looks for toolchains/<identity>/bin/fpc in $FPC_TOOLCHAIN_ROOT, by default ~/.local/share/fpc-toolchains. When that driver exists, every compile, compiler query and the Win32 SafeSEH check run it as the front-end does, by path with -n @<build>/etc/fpc.cfg; otherwise they run the fpc on PATH, as before. Every build prints the compiler it runs, and on Linux and macOS, when it is not the pinned build, how to install that build. Another compiler is chosen by changing the lock (identity and sha256sums), not the shell.
  • Programs compiled against build.pas's units use the compiler that made them. Each unit directory records the command in compiler-command.txt, and scripts/engine/unit-fpc.sh runs it where the engine's test scripts (run-with-fetch-server.sh, script-artifact-imports-test.sh) compile a program against those units, so the lookup stays in one place. The workflows' own inline compiles keep the fpc on PATH, which the action makes the pinned build.
  • The lookup covers Linux and macOS. On Windows, fpc-toolchain installs a host directory under bin and its helper is PowerShell; build.pas there keeps running the fpc on PATH.
  • build.pas itself stays compiled by the instantfpc on PATH. It and source/shared build on FPC 3.2.2 and later, so the default compiler only runs the build tool; the targets it builds use the pinned compiler.

Consequences

  • On Linux and macOS, a machine with the pinned build installed builds every target with CI's compiler from a plain ./build.pas, and a machine without it gets a line naming the missing build and install.sh --lock toolchain.lock.
  • A compiler bump is one change to toolchain.lock (identity and sha256sums), plus the Win32 manifest re-audit ADR 0169 requires.
  • A shell that selects another build with fpc-toolchain env no longer changes what build.pas compiles with while the pinned build is installed.
  • The workflows depend on the action reading toolchain.lock from the workspace root, so each job checks the repository out before installing FPC, as they already do.