Lake packages can expose one or more Lean libraries (collections of importable modules) and binary executables (programs users can run without Lean). Both are declared as targets in the lakefile; Lake builds them on demand or as part of the default build.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.
Lean Libraries
A Lean library target defines a collection of Lean modules that other packages — or other targets within the same package — canimport. Lake compiles each module in the library to a set of binary artefacts: .olean, .ilean, and optionally a compiled C file and native object.
Declaration Syntax
- TOML
- Lean DSL
[[lean_lib]] block declares one library. The name field is required; all other fields are optional.Library Configuration Fields
The name of the library target. Used on the command line (
lake build MyLib) and as the default module root.An array of root module names. Submodules of these roots (e.g.
MyLib.Foo is a submodule of MyLib) are considered part of the library. Defaults to a single root matching the target name.An array of module globs specifying which modules to build when the library is built. A glob can match a single module or all submodules of a root.Glob format:Local imports of glob-matched files are also recursively built.
MyLib— build only theMyLibmodule itselfMyLib.+— build all submodules ofMyLib(notMyLibitself)MyLib.*— buildMyLiband all its submodules
The subdirectory of the package’s source directory containing this library’s Lean source files. Passed to
lean as the -R option.The base name for the library’s native binary files (
.a, .so). Defaults to the mangled target name.When
true, each module is compiled into a native shared library that is loaded at import time. This speeds up metaprogram evaluation and allows @[extern] functions to be called from the interpreter. Applies if either the package-level or library-level setting is true.An array of target specifiers to build before this library’s modules. Use this to declare dependencies on native libraries, generated files, or other custom targets.
Library facets to build on a bare
lake build of this library. The default builds only Lean artefacts (.olean, .ilean, .c). Set to ["shared"] to also produce a shared library.Whether native library artefacts should be prefixed with
lib on Windows (e.g. libMyLib.dll instead of MyLib.dll). On Unix, the lib prefix is always present.Whether downstream packages may use
import all to access private internals of this library’s modules.Library Build Artefacts
When you runlake build MyLib, Lake produces (in .lake/build/):
| Artefact | Location | Description |
|---|---|---|
.olean | lib/lean/MyLib.olean | Binary Lean data for importers |
.ilean | lib/lean/MyLib.ilean | LSP metadata |
.c | ir/MyLib.c | Generated C source |
.a | lib/libMyLib.a | Static library (facet static) |
.so/.dll | lib/libMyLib.so | Shared library (facet shared) |
Marking a Library as a Default Target
- TOML
- Lean DSL
Binary Executables
A Lean executable target builds a binary program from a single Lean module (the root) that must contain amain definition. Lake recursively builds all of the root’s local imports.
Declaration Syntax
- TOML
- Lean DSL
Executable Configuration Fields
The name of the executable target. Used with
lake build hello and lake exe hello.The root module
Name of the executable. This module must define main. Defaults to the target name.Subdirectory of the package’s source directory containing the executable’s source file. Passed to
lean as -R.The file name of the produced binary. Defaults to the target name with
. replaced by - (e.g. My.Exe → My-Exe).When
true, symbols within the executable are exported so the Lean interpreter can access them (needed for executables that call Lean.Elab.runFrontend). On Unix this links with -rdynamic; on Windows it links against Lean’s shared DLLs.Targets to build before this executable’s modules.
Running an Executable
After building, the binary is in.lake/build/bin/. Use lake exe to build and run in one step:
External Libraries (extern_lib)
An extern_lib target declares a non-Lean static library that will be linked to the package’s binaries. In the Lean DSL:
The static library produced by
extern_lib must follow platform naming conventions: foo.a on Windows and libfoo.a on Unix. Use Lake.nameToStaticLib to compute the correct filename.Custom Targets
Atarget declaration lets you build arbitrary artefacts that can be referenced by other targets or triggered by lake build <name>.
Complete Example
A package with a library and two executables:- TOML
- Lean DSL