Skip to content

Cross-compiling the product cross-compiles the build tools too #639

Closed

Description

@David-Noble-at-work

Found 2026-08-24 while verifying #572. Fixing #572's grouped-target staleness removed one cause of GOOS=linux make build failing; this is the other, and it is a distinct defect.

$ GOOS=linux make build
fork/exec /var/folders/.../exe/devlore-inventory: exec format error
make[1]: *** [Makefile:535: inventory] Error 1

The defect

GOOS/GOARCH are ambient, so they reach every go invocation in the build — including the ones that build and run host tools:

  • inventory (Makefile:535-536) — go run ./cmd/devlore-inventory … cross-compiles the generator for the target, then tries to execute it on the host.
  • star (Makefile:127) — go build -o build/star ./cmd/star produces a target-architecture star, which every codegen recipe then invokes as $(STAR).

A build tool must be built for the host and only the product for the target. Today the two share one setting, so any cross-compile of the product silently poisons the toolchain that generates its sources.

Why it stayed hidden

GOOS=linux make vet and GOOS=windows make vet work fine — vet compiles but runs nothing — so the standing cross-platform gate never exercises this path. Only targets that execute a tool break, which is why it surfaces as an exec-format error rather than a compile error.

Fix sketch

Pin the host toolchain for tool builds and tool runs, e.g. a HOST_GO = GOOS= GOARCH= go (or explicit $(shell go env GOHOSTOS)/GOHOSTARCH) used by the star, inventory, and $(STAR)-producing recipes, leaving build's product compilation on the ambient values.

Exit: GOOS=linux make build and GOOS=windows make build complete; the produced product binaries are target-architecture and build/star is host-architecture; a second consecutive build still runs zero codegen (the #572 staleness property, preserved).

Related: #572 (the grouped-target half, fixed 2026-08-24), #568.

Activity

  1. David-Noble-at-work commented on Aug 24, 2026

    @David-Noble-at-work
    ContributorAuthor

    Ruled (USER, 2026-08-24).

    Mechanism: explicit. Pin the host toolchain with $(shell go env GOHOSTOS) / GOHOSTARCH rather than by emptying GOOS/GOARCH. Self-documenting at the call site; a reader sees why the recipe differs.

    Intent, which is wider than this fix: cross-compilation is to be a first-class workflow, not a repair. The goal is to build on one machine and test on many — no maintained Linux or Windows environment on every box being targeted; instead, ship built binaries and verify via self-install on the target.

    What the tree already has

    The host/product split is latent in the Makefile but unpinned:

    • Makefile:127 — go build $(LDFLAGS) -o build/star ./cmd/star, no $(GOEXE). This is the tool that codegen invokes as $(STAR).
    • Makefile:137 — go build $(LDFLAGS) -o build/star$(GOEXE) ./cmd/star. This is the product copy, and it already anticipates cross-compilation via $(GOEXE).

    The same file already draws the distinction this issue needs; it just does not enforce it. inventory (Makefile:535-536) has no such split — go run ./cmd/devlore-inventory is unambiguously a host tool.

    Cross-compiling products is also already partly done: dist (Makefile:286-287) builds writ and lore under explicit GOOS/GOARCH/CGO_ENABLED=0 — 2 of the 7 binaries make build produces (lore, star, writ, devlore-test, devlore-docs, devlore-index, devlore-inventory).

    Scope note

    This issue stays the narrow fix: pin the host toolchain for tool builds and tool runs so GOOS=linux make build and GOOS=windows make build complete, with a second consecutive build still running zero codegen (#572's property, preserved).

    The build-once/test-many workflow — full product set cross-compiled, dist widened beyond writ/lore, a CI job that actually runs a cross-compile build, and self-install verification on target platforms — is larger than one task and wants its own feature. make vet compiles without running anything, which is precisely why this defect hid, so a guard that only vets will not protect the fix.

  2. David-Noble-at-work commented on Aug 24, 2026

    @David-Noble-at-work
    ContributorAuthor

    The build-once/test-many workflow is now tracked separately as #652 — this issue stays the narrow host-toolchain pin.

    Note #652's item 6: a CI step that actually runs GOOS=linux make build is the cheap half of the guard and needs none of that issue's open questions settled. Worth landing right behind this one, since make vet compiles without executing and therefore cannot protect this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions