Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/leanprover/lean4/llms.txt

Use this file to discover all available pages before exploring further.

Lake provides a set of CLI commands for compiling Lean source files, running executables, and managing build outputs. All build artefacts are written into the .lake/build/ directory so they never pollute your source tree.

lake build — Build Targets

lake build [<targets>...] [-o <mappings>]
A bare lake build builds all default targets configured in the workspace’s root package (those listed in defaultTargets in lakefile.toml, or tagged @[default_target] in a Lean lakefile). If no default targets are configured, the command exits with an error unless --allow-empty is passed. Package dependencies are not updated during a build. Run lake update separately to refresh the manifest.

Building Specific Targets

Pass one or more target specifiers to build only those targets:
lake build MyLib          # build the library named MyLib
lake build hello          # build the executable named hello
lake build @myPkg         # build the default targets of package myPkg
lake build +MyModule      # build module MyModule (Lean arts: .olean, .ilean, .c)
lake build +MyModule:c    # build only the C file for MyModule
lake build MyLib:static   # build the static library artifact (.a)
lake build MyLib:shared   # build the shared library artifact (.so/.dll/.dylib)

Target Specifier Syntax

[@[<package>]/][<target>|[+]<module>][:<facet>]
SpecifierWhat is built
aDefault facet(s) of target a
@aDefault target(s) of package a
+ADefault facet(s) of module A
@/aDefault facet(s) of target a in the root package
@a/bDefault facet(s) of target b in package a
@a/+A:cThe C file facet of module A in package a
You can also use a source file path as a target:
lake build Foo/Bar.lean:o   # compile Foo/Bar.lean into a native object file

Library Facets

FacetProduces
leanArts.olean, .ilean, .c files (default)
staticStatic library (.a)
sharedShared library (.so, .dll, .dylib)

Module Facets

FacetProduces
leanArts.olean, .ilean, .c files (default)
oleanBinary blob of Lean data for importers
ileanBinary metadata for the Lean LSP server
cCompiled C file
bcCompiled LLVM bitcode file
oNative object file (compiled from C or LLVM backend)
c.oObject file compiled from the C file
bc.oObject file compiled from the LLVM bitcode file
dynlibShared library (e.g. for --load-dynlib)

lake exe — Build and Run an Executable

lake exe <exe-target> [<args>...]
lake exe is the most convenient way to build an executable and immediately run it. It:
  1. Looks up the named executable target in the workspace.
  2. Builds it if it is out-of-date.
  3. Runs it in Lake’s environment (with LEAN_PATH, PATH, and library search paths configured correctly).
lake exe hello              # build and run the 'hello' executable
lake exe hello -- arg1 arg2 # pass arguments to the executable
lake exe cache get          # run the 'cache' tool (common for Mathlib)
lake exe is also available as lake exec. The tool it runs must be defined as a lean_exe target in the workspace.

lake clean — Remove Build Outputs

lake clean [<package>...]
Deletes build directories. If no package names are specified, the build directories of every package in the workspace are removed. To clean only specific packages, list their names:
lake clean             # clean everything in the workspace
lake clean hello       # clean only the 'hello' package
lake clean hello foo   # clean 'hello' and 'foo'
lake clean removes the .lake/build/ directory contents but does not delete downloaded dependencies in .lake/packages/. To also remove dependencies, delete the .lake/packages/ directory manually.

lake check-build — Verify Default Targets Are Configured

lake check-build
Exits with code 0 if the workspace’s root package has any default targets configured, or code 1 otherwise. This command is useful in CI pipelines to fail early if no targets are set up.
lake check-build only verifies that some default targets are specified — it does not validate that those targets actually exist or build successfully.

Build Output Directory Layout

Lake writes all build outputs inside .lake/build/ (relative to the package root):
.lake/
  build/
    bin/        # compiled binary executables
    lib/        # native libraries (.a, .so, .dll, .dylib)
    lib/lean/   # Lean binary artifacts (.olean, .ilean files)
    ir/         # intermediate results (.c, .o files)
  packages/     # downloaded remote dependencies
The subdirectory names are controlled by fields in lakefile.toml: binDir (default bin), nativeLibDir (default lib), leanLibDir (default lib/lean), and irDir (default ir). The buildDir field controls the top-level build directory (default: .lake/build).

Build Flags

--old — Only Rebuild Modified Modules

lake build --old
With --old, Lake only rebuilds modules whose own source file has changed. Normally, Lake also rebuilds any module that transitively depends on a changed module (i.e. if A imports B, and B changes, A is also rebuilt). The --old flag skips those transitive rebuilds, making incremental builds faster at the cost of potentially leaving some artefacts stale.
Using --old can produce inconsistent build outputs if transitive dependencies have changed. It is most useful during active development when you know your changes are isolated.

--verbose / -v — Show Build Trace

lake build --verbose
lake build -v
The --verbose flag shows trace logs (the exact command invocations Lake runs) and prints the path of each successfully built target. This is useful for debugging build issues or inspecting what Lake is doing.

--no-build — Check Without Building

lake build --no-build
Exits immediately with an error if any build target is not already up-to-date. Useful in CI to verify that committed artefacts are current.

--rehash / -H — Force Hash Recomputation

lake build --rehash
Forces Lake to recompute hashes for all files rather than trusting cached .hash files. Use this if you suspect trace files have become corrupted.

--reconfigure / -R — Re-elaborate Config Files

lake build --reconfigure
Forces Lake to re-elaborate the lakefile from source rather than using cached .olean files for the configuration. Useful when the lakefile itself has been changed.

Other Useful Commands

lake query — Build and Print Results

lake query [<targets>...]
Like lake build, but also outputs the build results to stdout. With --json, results are formatted as JSON.

lake serve — Start the Language Server

lake serve [-- <args>...]
Starts the Lean language server (lean --server) with the package’s moreServerArgs configuration applied. This is typically invoked by editors (VS Code, Emacs, etc.) automatically.

lake env — Run a Command in Lake’s Environment

lake env <cmd> [<args>...]
Runs a command with LEAN_PATH, PATH, and library search paths configured for the workspace. A bare lake env prints the environment variables that would be set.

lake lean — Elaborate a File in the Workspace

lake lean <file> [-- <args>...]
Builds the imports of the given file and then runs lean on it using the workspace configuration. The process runs in Lake’s environment like lake env lean.

Complete Example

# Create and build a new package
lake new myproject
cd myproject

# Build all default targets
lake build

# Run the generated executable
lake exe myproject

# Build only the library's static artifact
lake build MyLib:static

# Check what Lake would do without rebuilding
lake build --verbose --no-build

# Clean all build outputs
lake clean

Build docs developers (and LLMs) love