4.3 KiB
Requirements
- C++11 compatible compiler
- CMake
- GMP (GNU multiprecision library)
Platform-Specific Setup
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 NinjaCMake 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_CXX_COMPILER=Select the C++ compiler to use. -
-D LEAN_IGNORE_OLEAN_VERSIONThe.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:
- An initial executable
lean_stage0is compiled directly from the repository contents (binaries are generally built by a target of the same name). These include:src/stage0: the Lean standard library extracted to C++ from a previous commit- other parts of
src/: the non-bootstrapped parts of Lean written in C++
- Using
lean_stage0, the stdlib contained inlibrary/is compiled to.oleanobject files as well as extracted to C++ insrc/stage1by the targetstdlib. - The target
build_libleanstdlibbuilds the static librarystage1/libleanstdlib.afrom the extracted files. - This library is linked with the C++ source files into
libleanstatic.aand ultimately into the executablelean. - The
bintarget finally copies the executable and libraries intobin/.
Development Workflows
- The
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. Conversely, if you did a C++ change but the stdlib fails to build, you can use thebin_lean_stage0target to temporarily uselean_stage0asbin/leanso that you can fix the stdlib in your editor. - When making a parallel change in both Lean and C++, there usually is no simple
way of writing C++ code that builds in both stage0 and stage1. In this case,
temporarily set
-DREBUILD_STAGE0=OFFto deactivate rebuildinglean_stage0, which, as described above, is used to compile the standard library. When the change is complete and stage1 is working as expected, make the targetupdate-stage0to copy stage1 to stage0 - this is the re-bootstrapping step. ReactivateREBUILD_STAGE0and stage0 should compile again.
Further Information
- Using CCache to avoid recompilation
- Measuring Code Coverage
- Compiling Lean with Split Stacks