Installing LEAN on arm based Mac — Manually compile and install
Installing LEAN on arm based Mac — Manually compile and install
This is a tutorial on how to compile LEAN from source code and
install it. Next, we will see how to move it to elan
(next
post)
Problem with elan
elan
does not provide any installation for lean3 on arm
based Mac anymore.
1 |
|
Thus, we should install LEAN manually, there are two choices:
- Download the binary file directly, then put to
~/.elan/toolchains/
, I demonstrated how to do that in my blog: Setting Up Lean on an M1 Mac: A Debugging Journey - Download the source code, compile yourself, install, then move the
binary files to
elan
folder.
This blog will focus mainly on the second way.
Links for downloading LEAN:
- Community: This could be confusing. You might checked the link at https://github.com/leanprover-community/mathlib, yet this will lead you to the official website. If you want to install it manually (so that you can regulate versions), you want to check this link, which is written in the OLD_README.md.
- Official release: https://github.com/leanprover/lean3/releases
- For arm based mac, you may want to download the
lean-3.4.2-darwin.zip
, but you might meet the problem of the following1
2
3
4
5❯ ./lean --version
dyld[22512]: Library not loaded: /usr/local/opt/gmp/lib/libgmp.10.dylib
Referenced from: <A8A24233-8885-3A1A-83F9-0071B27AF08A> /Users/ray/.elan/toolchains/lean3-manual/bin/lean
Reason: tried: '/usr/local/opt/gmp/lib/libgmp.10.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/opt/gmp/lib/libgmp.10.dylib' (no such file), '/usr/local/opt/gmp/lib/libgmp.10.dylib' (no such file), '/usr/local/lib/libgmp.10.dylib' (no such file), '/usr/lib/libgmp.10.dylib' (no such file, not in dyld cache)
[1] 22512 abort ./lean --version
- For arm based mac, you may want to download the
Download source code for LEAN (community)
The process is similar for official release. You can download either
Source code(zip)
or Source code(tar.gz)
from
the official release.
Download source code for specific version
Remember, clone this link: https://github.com/leanprover-community/lean
Here are the full steps (I will use v3.42.1 as an example):
1 |
|
Here is the full output (don’t copy this)
1 |
|
Compile and Install
To compile Lean from this source code, you typically use tools like
cmake
and
make
.
Here's a step-by-step guide to building Lean 3.4.2 from source on macOS:
Install Required Dependencies: First, ensure you have the necessary dependencies installed. You'll typically need: -
cmake
: for configuring the build process. -g++
or an equivalent C++ compiler: for compiling the source code. If you use Homebrew, you can install them using:1
brew install cmake gcc
Navigate to the Source Directory: Change directory to the root of the source code: If you followed the steps aforementioned, you don’t need to do this
1
cd path/to/your/lean
Configure and Build: Now, configure and compile Lean:
1
2
3
4mkdir -p build/release
cd build/release
cmake ../../src
makeThis will create a
release
build of Lean. The binary will be available in thebuild/release
directory once the build process completes. This step take a while and you might see some warning. Those are fine as long as no error. Here is an example of warning1
2
3
4
5
6
7
8...
.../lean/src/library/typed_expr.cpp:59:18: warning: 'write' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
virtual void write(serializer & s) const {
.../lean/src/kernel/expr.h:370:18: note: overridden virtual function is here
virtual void write(serializer & s) const = 0;
^
4 warnings generated.Installation (Optional): If you wish to install Lean system-wide (or in a specified directory), you can use the
install
target withmake
:1
make install
By default, this might install Lean to
/usr/local/bin
. If you wish to specify a different install directory, you can provide a prefix during thecmake
configuration step:1
cmake -DCMAKE_INSTALL_PREFIX:PATH=/path/to/your/desired/install/location ../../src
Using with
elan
: If you wish to integrate this build withelan
, you can either: - Copy the binaries to the appropriateelan
toolchain directory. - Or, point your system'sPATH
variable to the directory containing the compiled binaries.Potential Issues:
- Keep an eye out for any error messages during the build process. They can indicate missing dependencies or other issues.
- Ensure you have adequate disk space and permissions to write to the specified directories.
Once you've successfully built Lean from source, you should be able
to run the lean
binary and verify its
version using lean --version
.
Now, you have successfully installed LEAN, try it out by
1 |
|
It should output something like
1 |
|
Now you have installed LEAN, in my next blog, I will demonstrate how
to put your manually installed LEAN to elan