A template for Lean 4 projects that depend on Mathlib.
Install Lean via elan (see the
Lean installation guide). The correct Lean version is
picked up automatically from lean-toolchain.
After creating your repository from this template, rename it from ProjectTemplate to your
own project name:
./customize.sh MyProjectThis updates lakefile.toml, lake-manifest.json, the Lean imports and this README's title, and
renames ProjectTemplate.lean and ProjectTemplate/ to MyProject.lean and MyProject/.
The name must be a valid Lean module name (letters, digits and underscores, starting with a
letter; UpperCamelCase is conventional). Commit the result, then delete customize.sh.
Compiling Mathlib from source takes hours, so download the prebuilt files instead:
lake exe cache getRe-run this whenever you change the Mathlib version (or if your editor starts rebuilding Mathlib files).
lake build- Put your Lean files under
MyProject/and import each one fromMyProject.lean, so thatlake build(and CI) checks them. - Open the repository folder (not a single file) in VS Code with the Lean 4 extension.
Change the rev under [[require]] in lakefile.toml to the new Mathlib tag, and set
lean-toolchain to match. Then run:
lake update mathlib
lake exe cache get
lake buildAlternatively, run the Update Dependencies workflow from the GitHub Actions tab: it
opens a pull request if the update builds, or an issue if it doesn't. (Uncomment the
schedule block in .github/workflows/update.yml to run it automatically.)
- CI: every push and pull request is built by
.github/workflows/lean_action_ci.yml. - To let the update workflow open pull requests, go to Settings → Actions → General and tick Allow GitHub Actions to create and approve pull requests.
- To publish docs to GitHub Pages, set Settings → Pages → Source to "GitHub Actions" and
uncomment the
docgen-actionline inlean_action_ci.yml.