lean-build
Agnostic Lake-build skill, mirrored from vendor/leanprover-skills
with the Mathlib-specific lake exe cache get note retained. The
Mathlib-only mathlib-build slug now redirects here (W4 Wave 1).
Routing
- USE FOR: running
lake env lean, lake build <Module>, lake exe cache get, lake clean, lake exe runLinter, lake update <dep> — including merge-conflict resolution, targeted iteration, and CI-quality local checks across any Lake-managed project.
- DO NOT USE FOR: bisecting a Lean version-pin regression (use
@lean-bisect); minimising a build failure to a self-contained MWE (use @lean-mwe); repairing or installing the Lean toolchain itself (use @lean-setup); fixing the underlying proof error that the build surfaces (use @lean-proof).
- TRIGGERS: build, lake, lake env lean, lake exe cache get, stale artifacts, lake clean, "build is slow", "CI failed locally", CI prep.
Workflow
- Pick scope — single-file (
lake env lean MyFile.lean), targeted module (lake build <Module>.Foo.Bar -q --log-level=info), or full suite (only when broad / pre-CI). Default to targeted iteration to save tokens.
- Fetch cache — for Mathlib projects,
lake exe cache get (or lake exe cache get! if cache appears corrupt); for non-Mathlib Lake projects, skip this step (no shared cache).
- Build + parse — run with
-q --log-level=info. If unexpected results appear, run lake clean + cache-get + re-build before treating the diagnostic as real.
- Hand off the diagnostic — proof failures →
@lean-proof; toolchain version mismatch → @lean-setup; minimisation needed → @lean-mwe; suspect upstream regression → @lean-bisect; ready-to-file → @lean-pr.
Recovery & STOP
- Build result looks impossible (e.g. ghost errors, missing oleans for a built module) →
lake clean; for Mathlib, also lake exe cache get; re-run targeted build once. If still impossible, STOP and re-anchor.
- Build hangs > 10 min on a small target → STOP, suspect dependency cycle or runaway elaboration; hand to
@lean-mwe to isolate.
lake update accidentally invoked mid-iteration → STOP, git diff lake-manifest.json; revert unless the task is explicitly a dependency update.
- Bare
lean MyFile.lean invoked instead of lake env lean → STOP, results are unreliable; re-run inside the Lake env.
Handoffs
- Predecessors / successors: see FM
handoffs. Typical inbound: @lean-setup (after a clean install) or @lean-proof (after a tactic write). Typical outbound: @lean-mwe / @lean-bisect / @lean-pr for any failure that survives a clean rebuild.
- Sister skill:
@lean-setup for toolchain repair (which often manifests as build failures).
- REDIRECT pointer:
mathlib-build slug routes here (preserved per Chesterton-protocol).
- Source notes: vendor mirror at
vendor/leanprover-skills/skills/lean-build/SKILL.md.
Building Lean Projects with Lake
This skill is the agnostic counterpart of mathlib-build (now a
REDIRECT stub — W4 Wave 1 / move A3 of
lab/design/07-cluster-workflow.md). The content is Lake-generic; the
single Mathlib-specific note (lake exe cache get) is called out
explicitly because the cache lives in the
leanprover-community/mathlib4 repo, not in Lake itself.
Build rule of thumb
Use the repository's Lake environment for every command. Prefer
targeted builds while iterating, and only run the full suite when the
change is broad or ready for CI.
Mathlib-specific: fetch the Mathlib olean cache before build:
lake exe cache get
Use lake exe cache get! (with !) to force re-download if the cache
appears corrupt. This script is provided by Mathlib; other Lake projects
typically do not ship an olean cache.
When building a large Lake project reduce verbosity to save on tokens:
lake build -q --log-level=info
For merge-conflict resolution or small fixes build only the affected
files: lake build <Module>.Foo.Bar -q --log-level=info. Often it is
fine to leave a complete build to CI. If you need a thorough local
build, run targeted commands per host repository; in Mathlib:
lake build Mathlib MathlibTest Archive Counterexamples && lake exe runLinter.
Lake command reference
lake env lean MyFile.lean # check one file in the project env
lake env lean --version # verify the active Lean toolchain
lake build <Module>.Foo.Bar -q --log-level=info
lake exe runLinter # Mathlib-specific linter pass
lake clean # remove build artifacts (current package only)
lake update <dep> # update one dependency intentionally
Do not use bare lean MyFile.lean inside a Lake project; it can bypass
the project toolchain, package path, and Lake environment.
Stale artifact recovery
If a build result looks impossible, reset only generated artifacts:
lake clean
lake exe cache get # if the project is Mathlib (otherwise omit)
lake build <Module>.Foo.Bar -q --log-level=info
Avoid lake update during routine validation unless the task is
explicitly a dependency update.
See also
1---2name: lean-build3description: USE FOR: building Lean 4 projects with Lake, validating Lean changes with `lake env lean`, picking targeted build commands (`lake build <Module>`), resolving stale build artifacts via `lake clean` + `lake exe cache get`, preparing CI-quality local checks. Applies to any Lake-managed project (Mathlib, Cslib, or downstream repositories). DO NOT USE FOR: bisecting which Lean version caused a regression (use @lean-bisect), minimising an error to a bug-report repro (use @lean-mwe), repairing the toolchain itself (use @lean-setup), writing or fixing the proof (use @lean-proof). TRIGGERS: build, lake, lake env lean, lake exe cache get, stale artifacts, lake clean, build error, CI prep.4---56# lean-build78> Agnostic Lake-build skill, mirrored from `vendor/leanprover-skills`9> with the Mathlib-specific `lake exe cache get` note retained. The10> Mathlib-only `mathlib-build` slug now redirects here (W4 Wave 1).1112## Routing1314- **USE FOR:** running `lake env lean`, `lake build <Module>`, `lake exe cache get`, `lake clean`, `lake exe runLinter`, `lake update <dep>` — including merge-conflict resolution, targeted iteration, and CI-quality local checks across any Lake-managed project.15- **DO NOT USE FOR:** bisecting a Lean version-pin regression (use `@lean-bisect`); minimising a build failure to a self-contained MWE (use `@lean-mwe`); repairing or installing the Lean toolchain itself (use `@lean-setup`); fixing the underlying proof error that the build surfaces (use `@lean-proof`).16- **TRIGGERS:** build, lake, lake env lean, lake exe cache get, stale artifacts, lake clean, "build is slow", "CI failed locally", CI prep.1718## Workflow19201. **Pick scope** — single-file (`lake env lean MyFile.lean`), targeted module (`lake build <Module>.Foo.Bar -q --log-level=info`), or full suite (only when broad / pre-CI). Default to targeted iteration to save tokens.212. **Fetch cache** — for Mathlib projects, `lake exe cache get` (or `lake exe cache get!` if cache appears corrupt); for non-Mathlib Lake projects, skip this step (no shared cache).223. **Build + parse** — run with `-q --log-level=info`. If unexpected results appear, run `lake clean` + cache-get + re-build before treating the diagnostic as real.234. **Hand off the diagnostic** — proof failures → `@lean-proof`; toolchain version mismatch → `@lean-setup`; minimisation needed → `@lean-mwe`; suspect upstream regression → `@lean-bisect`; ready-to-file → `@lean-pr`.2425## Recovery & STOP2627- Build result looks impossible (e.g. ghost errors, missing oleans for a built module) → `lake clean`; for Mathlib, also `lake exe cache get`; re-run targeted build once. If still impossible, STOP and re-anchor.28- Build hangs > 10 min on a small target → STOP, suspect dependency cycle or runaway elaboration; hand to `@lean-mwe` to isolate.29- `lake update` accidentally invoked mid-iteration → STOP, `git diff lake-manifest.json`; revert unless the task is explicitly a dependency update.30- Bare `lean MyFile.lean` invoked instead of `lake env lean` → STOP, results are unreliable; re-run inside the Lake env.3132## Handoffs3334- **Predecessors / successors**: see FM `handoffs`. Typical inbound: `@lean-setup` (after a clean install) or `@lean-proof` (after a tactic write). Typical outbound: `@lean-mwe` / `@lean-bisect` / `@lean-pr` for any failure that survives a clean rebuild.35- **Sister skill:** `@lean-setup` for toolchain repair (which often manifests as build failures).36- **REDIRECT pointer:** `mathlib-build` slug routes here (preserved per Chesterton-protocol).37- **Source notes:** vendor mirror at `vendor/leanprover-skills/skills/lean-build/SKILL.md`.3839---4041# Building Lean Projects with Lake4243This skill is the agnostic counterpart of `mathlib-build` (now a44REDIRECT stub — W4 Wave 1 / move A3 of45`lab/design/07-cluster-workflow.md`). The content is Lake-generic; the46single Mathlib-specific note (`lake exe cache get`) is called out47explicitly because the cache lives in the48`leanprover-community/mathlib4` repo, not in Lake itself.4950## Build rule of thumb5152Use the repository's Lake environment for every command. Prefer53targeted builds while iterating, and only run the full suite when the54change is broad or ready for CI.5556**Mathlib-specific:** fetch the Mathlib olean cache before build:5758```bash59lake exe cache get60```6162Use `lake exe cache get!` (with `!`) to force re-download if the cache63appears corrupt. This script is provided by Mathlib; other Lake projects64typically do not ship an olean cache.6566When building a large Lake project reduce verbosity to save on tokens:6768```bash69lake build -q --log-level=info70```7172For merge-conflict resolution or small fixes build only the affected73files: `lake build <Module>.Foo.Bar -q --log-level=info`. Often it is74fine to leave a complete build to CI. If you need a thorough local75build, run targeted commands per host repository; in Mathlib:76`lake build Mathlib MathlibTest Archive Counterexamples && lake exe runLinter`.7778## Lake command reference7980```bash81lake env lean MyFile.lean # check one file in the project env82lake env lean --version # verify the active Lean toolchain83lake build <Module>.Foo.Bar -q --log-level=info84lake exe runLinter # Mathlib-specific linter pass85lake clean # remove build artifacts (current package only)86lake update <dep> # update one dependency intentionally87```8889Do not use bare `lean MyFile.lean` inside a Lake project; it can bypass90the project toolchain, package path, and Lake environment.9192## Stale artifact recovery9394If a build result looks impossible, reset only generated artifacts:9596```bash97lake clean98lake exe cache get # if the project is Mathlib (otherwise omit)99lake build <Module>.Foo.Bar -q --log-level=info100```101102Avoid `lake update` during routine validation unless the task is103explicitly a dependency update.104105---106107## See also108109- [`../../../templates/Template_Lakefile.md`](../../../templates/Template_Lakefile.md) — Template: Annotated lakefile and CI patterns110- [`../../../references/lean4-module-dependency-guide.md`](../../../references/lean4-module-dependency-guide.md) — DAG enforcement and splitting workflow111- [`../mathlib-build/SKILL.md`](../mathlib-build/SKILL.md) — REDIRECT stub (legacy slug)