4.6 KiB
Requirements
- C++14 compatible compiler
- CMake
- GMP (GNU multiprecision library)
Platform-Specific Setup
- Linux (Ubuntu)
- Windows (msys2)
- Windows (Visual Studio)
- macOS (homebrew)
- Linux/macOS (Nix): call
nix-shellin the project root - Emscripten: lean.js
Generic Build Instructions
Setting up a basic release build using make:
git clone https://github.com/leanprover/lean
cd lean
mkdir -p build/release
cd build/release
cmake ../../src
make
Setting up a basic debug build using make:
git clone https://github.com/leanprover/lean
cd lean
mkdir -p build/debug
cd build/debug
cmake -D CMAKE_BUILD_TYPE=DEBUG ../../src
make
Useful CMake Configuration Settings
Pass these along with the cmake ../../src command.
-
-G Ninja
CMake 2.8.11 supports the Ninja build system. Some people report that using Ninja can reduce the build time, esp when a build is incremental. Callninjainstead ofmaketo build the project. -
-D CMAKE_BUILD_TYPE=
Select the build type. Valid values areRELEASE(default),DEBUG,RELWITHDEBINFO, andMINSIZEREL. -
-D CMAKE_C_COMPILER=
-D CMAKE_CXX_COMPILER=
Select the C++ compiler to use. Because of the bootstrapped build (see below), it is highly recommended to use CCache to reduce redundant compilations -
-D CHECK_OLEAN_VERSION=OFF
The.oleanfiles are tagged with the Lean version they were produced with. This means that by default, the core library has to be recompiled after e.g. everygit commit. Use this option to avoid the version check. The.oleanfiles can be removed manually by invokingmake/ninja clean-olean.
Lean Build Pipeline
Since version 4, Lean is a partially bootstrapped program: parts of the frontend
and compiler are written in Lean itself and thus need to be built before
building Lean itself - which is needed to again build those parts. Building the
lean executable (e.g. via make bin) involves roughly the following steps:
- The target
stage0compiles an initialleanexecutable directly from C/C++ code versioned instage0/(via a CMakeExternProject). The C++ code is a previous version of the code insrc/, while the C code was extracted from the Lean stdlib of the same commit. - Using this executable, the stdlib contained in
library/is compiled to.oleanobject files as well as extracted to C insrc/stage1by the targetmake_stdlib. - The static libraries
leanstdlibandleanstaticare built from the extracted files and the current C++ code insrc/, respectively. - These libraries are linked into the final
leanexecutable. - The
bintarget finally copies all these objects intobin/. The initialleanexecutable is calledlean_stage0there.
Development Workflows
- The
make_stdlibtarget can be used to check the standard library without rebuildinglean. - In most cases, the
bintarget can be used to build and test either a Lean or C++ change. Theleantarget can be used to build the same binary without copying it tobin/, which can be useful for quickly building a debug version without changing the binary used by the editor. TheLEAN_PATHvariable may need to be set to the location oflibrary/manually in this case. - Changes in the frontend or compiler do not immediately affect the stdlib because of
the staged build until stage0 is updated by making the
update-stage0target, after which the stdlib can be updated appropriately if necessary.
Troubleshooting
- The
Makefileatlibrary/does not need to be invoked directly. However, we may want to do it while investigating problems, e.g., Lean is looping while compiling a file. To manually invoke thisMakefile, we should use:
cd library/
STAGE1_OUT=<build_dir_path>/stage1 make <build_dir_path>/stage1/libleanstdlib.a
For example, if our build directory is located at build/release/, the command above should be
cd library/
STAGE1_OUT=../build/release/stage1 make ../build/release/stage1/libleanstdlib.a
Further Information
- Using CCache to avoid recompilation
- Measuring Code Coverage
- Compiling Lean with Split Stacks