The build matrix, honestly

The hard part of a software factory isn't orchestration — it's that 'every platform' is a matrix, and matrices are where build systems break. The generic shape of the problem, the menu of strategies, and how to keep a target from silently disappearing.

The orchestration is the easy part. Poll a queue, dispatch a job, collect the result. The part that actually breaks is the phrase “build for every platform” — because that’s not one build, it’s a matrix, and matrices are where build systems fall over.

The core problem: one source tree, many targets, and the targets don’t want the same things. Some cross-compile cleanly from a commodity box. Some can only be produced on specific hardware. Some are fast, some take hours. A factory that treats “the build” as a single step hits this wall on day one.

What the matrix actually looks like

                       one source tree
                            │
        ┌──────────────┬────┴─────────────┬──────────────┐
        ▼              ▼                  ▼              ▼
   ┌─────────┐    ┌─────────┐       ┌──────────┐   ┌──────────┐
   │ target A│    │ target B│       │ target C │   │ target D │
   │ cross-  │    │ cross-  │       │ host-    │   │ host-    │
   │ compile │    │ compile │       │ locked   │   │ locked   │
   └────┬────┘    └────┬────┘       └────┬─────┘   └────┬─────┘
        ▼              ▼                 ▼              ▼
   commodity      commodity         dedicated     dedicated
     pool           pool             slice         slice

Two shapes, not one. The left half runs anywhere; the right half can only run where the platform’s toolchain — and often its signing — lives. That split is the whole reason a build farm is a heterogeneous pool, not a homogeneous one, and it’s the first thing the design has to account for.

The three constraints that shape everything

Cross-compilation cuts hardware. Where a target can be built from a host running a different OS or architecture, do that. It’s how you avoid owning hardware for every target. Not every target allows it — but more do than people assume.

Some targets are host-locked. A few can only be built where the platform’s toolchain (and often its signing) lives. You can’t cross-compile a signed build for a locked platform from a generic box. Those targets need a dedicated slice of the pool — a small, separate set of machines that only does that target.

The cache is what makes it affordable. Rebuilding every target on every change is expensive. A remote, incremental cache — keyed on inputs — is the difference between “build the whole matrix on every ticket” being a three-minute incremental and a forty-minute tax. Without a real cache, you don’t have a matrix; you have a bottleneck.

How a repo declares its matrix

The factory should not hardcode the matrix. The repo declares it, and the factory derives host requirements from that declaration. A minimal, provider-agnostic shape:

# the repo declares its matrix; the factory derives hosts from it
matrix:
  reference: target-a        # the target the rest are checked against
  targets:
    - name: target-a
      strategy: cross-compile
      host: any              # builds from a commodity box
    - name: target-b
      strategy: cross-compile
      host: any
    - name: target-c
      strategy: host-locked
      host: platform-c       # toolchain + signing live only here
      sign: true
    - name: target-d
      strategy: host-locked
      host: platform-d
      sign: true

Two properties fall out of making this a declaration rather than a config the factory owns. First, the matrix is a property of the codebase, not the factory — add a target, you edit the repo, not the pipeline. Second, the declaration is the single place where “which targets exist and where they can build” is stated, so there’s exactly one thing to audit when a target goes missing.

Strategies are a menu, not a mandate

The factory does not assume one way to build. It runs whatever toolchain the repo declares — native cross-compilation, a cross-platform app framework, a WASM target, or a mix — and derives the host requirements from that.

One pattern shows up a lot: pick a reference target and build the rest as ports checked against it. Often the reference is the cheapest and fastest platform to build (great tooling, cheap in the cloud); sometimes it’s the product’s primary target for business reasons. That’s a per-repo decision, not a rule — and “the fast platform is usually the reference” is a common default, not a requirement.

Two more things worth designing in:

  • One node can cover several targets. A single worker may legitimately produce multiple targets from the same checkout — a native build plus a WASM and a mobile target, for instance.
  • Incremental over clean, by default. Clean builds on large trees are slow. Keep the build tree and update it to the branch; only go clean on major changes. But the incremental state has to be reproducible or replicated, or a lost node takes the progress with it.

The trade-off, stated plainly

Every target is a bet between two costs, and the matrix is where you pay for the choice:

  • Cross-compile is cheap to run but conditional — the moment a target stops cross-compiling cleanly (a native dependency, a signing step, a toolchain that refuses), you’ve silently lost the ability to build it on the commodity pool and you’ll find out in production, not in the build.
  • Host-locked is reliable but owned — you now pay for hardware that idles most of the time, and it’s the first thing to be starved when the pool is sized down.

There’s no way to get both for free. The honest design is to make the trade-off explicit per target in the declaration (strategy: cross-compile or host-locked), so the cost is visible and deliberate rather than discovered. A target that’s cross-compiling “for now” with a host-locked escape hatch is a different risk profile than one that’s host-locked by design — and the declaration is where that distinction lives.

The factory’s job, reduced

Run the right toolchain on the right host, cache aggressively, collect the artifacts — and never silently drop a target. If a target genuinely can’t be produced (missing hardware, a failing toolchain), the factory says so on the ticket, with the reason. “Done” means every target is either built or explicitly, accountably not.

That’s the whole game. Everything else — scheduling, agents, dashboards — is in service of getting the matrix right.

Open questions

  • How do you choose the reference target? Cheapest-and-fastest is the default, but a product whose primary market is a host-locked platform may want the reference to be that platform. The rule should be per-repo, and I’m not sure there’s a clean way to encode “why this reference” beyond a comment.
  • How deep does the cache have to be? A cache keyed on inputs is the floor, but deciding what is an input (compiler version? toolchain patch level? a generated file?) is where reproducibility quietly breaks.
  • What happens when a host-locked toolchain breaks? The commodity targets are fine, but one locked target now blocks the whole matrix’s “done.” Is that a hard block or a documented partial? I lean hard block, but it’s the case I’m least sure about.

I go deep on the surrounding architecture in the shape of a factory.

This is part of the Software Factory series.

#software-factory#build-systems#cicd
← All posts