2022-07-27 04:08:42 +08:00
|
|
|
Unless you really need to build Codon for whatever reason, we strongly
|
|
|
|
recommend using pre-built binaries if possible.
|
|
|
|
|
|
|
|
# Dependencies
|
|
|
|
|
2024-03-03 05:30:03 +08:00
|
|
|
Codon uses an LLVM fork based on LLVM 17. To build it, you can do:
|
2022-07-27 04:08:42 +08:00
|
|
|
|
|
|
|
``` bash
|
2022-10-14 21:31:10 +08:00
|
|
|
git clone --depth 1 -b codon https://github.com/exaloop/llvm-project
|
2025-01-30 04:41:43 +08:00
|
|
|
cmake -S llvm-project/llvm -B llvm-project/build \
|
2022-07-27 04:08:42 +08:00
|
|
|
-DCMAKE_BUILD_TYPE=Release \
|
|
|
|
-DLLVM_INCLUDE_TESTS=OFF \
|
|
|
|
-DLLVM_ENABLE_RTTI=ON \
|
|
|
|
-DLLVM_ENABLE_ZLIB=OFF \
|
2025-01-30 04:41:43 +08:00
|
|
|
-DLLVM_ENABLE_ZSTD=OFF \
|
2022-07-27 04:08:42 +08:00
|
|
|
-DLLVM_ENABLE_TERMINFO=OFF \
|
2022-10-14 21:31:10 +08:00
|
|
|
-DLLVM_TARGETS_TO_BUILD=all
|
2022-12-05 08:45:21 +08:00
|
|
|
cmake --build llvm-project/build
|
2023-04-13 06:13:54 +08:00
|
|
|
cmake --install llvm-project/build --prefix=llvm-project/install
|
2022-07-27 04:08:42 +08:00
|
|
|
```
|
|
|
|
|
2023-04-13 06:13:54 +08:00
|
|
|
You can also add `-DLLVM_ENABLE_PROJECTS=clang` if you do not have `clang` installed
|
|
|
|
on your system. We also recommend setting a local prefix during installation to
|
|
|
|
avoid clashes with the system LLVM.
|
|
|
|
|
2022-07-27 04:08:42 +08:00
|
|
|
# Build
|
|
|
|
|
2025-01-30 04:41:43 +08:00
|
|
|
Codon requires `libgfortran`, the parent directory of which must be specified via the
|
|
|
|
`CODON_SYSTEM_LIBRARIES` environment variable. For example, on macOS, with a
|
|
|
|
`brew`-installed `libgfortran` (obtainable via `brew install gcc`):
|
|
|
|
|
|
|
|
```bash
|
|
|
|
export CODON_SYSTEM_LIBRARIES=/opt/homebrew/opt/gcc/lib/gcc/current
|
|
|
|
```
|
|
|
|
|
|
|
|
On Linux:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
export CODON_SYSTEM_LIBRARIES=/usr/lib/x86_64-linux-gnu
|
|
|
|
```
|
|
|
|
|
|
|
|
Then, the following can generally be used to build Codon. The build process
|
2022-07-27 04:08:42 +08:00
|
|
|
will automatically download and build several smaller dependencies.
|
|
|
|
|
2023-04-13 06:13:54 +08:00
|
|
|
```bash
|
2025-01-30 04:41:43 +08:00
|
|
|
cmake -S . -B build \
|
2022-12-05 08:45:21 +08:00
|
|
|
-DCMAKE_BUILD_TYPE=Release \
|
|
|
|
-DLLVM_DIR=$(llvm-config --cmakedir) \
|
|
|
|
-DCMAKE_C_COMPILER=clang \
|
|
|
|
-DCMAKE_CXX_COMPILER=clang++
|
2022-07-27 04:08:42 +08:00
|
|
|
cmake --build build --config Release
|
2023-04-13 06:13:54 +08:00
|
|
|
cmake --install build --prefix=install
|
2022-07-27 04:08:42 +08:00
|
|
|
```
|
|
|
|
|
2023-04-13 06:13:54 +08:00
|
|
|
This will produce the `codon` executable in the `install/bin` directory, as
|
|
|
|
well as `codon_test` in the `build` directory which runs the test suite.
|
|
|
|
Additionally, a number of shared libraries are produced in `install/lib/codon`:
|
2022-12-05 08:45:21 +08:00
|
|
|
|
2023-04-13 06:13:54 +08:00
|
|
|
- `libcodonc`: The compiler library used by the `codon` command-line tool.
|
2022-12-05 08:45:21 +08:00
|
|
|
- `libcodonrt`: The runtime library used during execution.
|
|
|
|
- `libomp`: OpenMP runtime used to execute parallel code.
|
|
|
|
|
2023-04-13 06:13:54 +08:00
|
|
|
{% hint style="warning" %}
|
|
|
|
Make sure the `llvm-config` being used corresponds to Codon's LLVM. You can also use
|
|
|
|
`-DLLVM_DIR=llvm-project/install/lib/cmake/llvm` on the first `cmake` command if you
|
|
|
|
followed the instructions above for compiling LLVM.
|
|
|
|
{% endhint %}
|
|
|
|
|
|
|
|
# GPU support
|
|
|
|
|
|
|
|
Add `-DCODON_GPU=ON` to the first `cmake` command above to enable GPU support.
|
|
|
|
|
|
|
|
# Jupyter support
|
|
|
|
|
|
|
|
To enable Jupyter support, you will need to build the Jupyter plugin:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# Linux version:
|
|
|
|
cmake -S jupyter -B jupyter/build \
|
|
|
|
-DCMAKE_BUILD_TYPE=Release \
|
|
|
|
-DCMAKE_C_COMPILER=clang \
|
|
|
|
-DCMAKE_CXX_COMPILER=clang++ \
|
|
|
|
-DLLVM_DIR=$(llvm-config --cmakedir) \
|
|
|
|
-DCODON_PATH=install \
|
|
|
|
-DOPENSSL_ROOT_DIR=$(openssl version -d | cut -d' ' -f2 | tr -d '"') \
|
|
|
|
-DOPENSSL_CRYPTO_LIBRARY=/usr/lib64/libssl.so \
|
|
|
|
-DXEUS_USE_DYNAMIC_UUID=ON
|
|
|
|
# n.b. OPENSSL_CRYPTO_LIBRARY might differ on your system.
|
2022-12-05 08:45:21 +08:00
|
|
|
|
2023-04-13 06:13:54 +08:00
|
|
|
# On macOS, do this instead:
|
|
|
|
OPENSSL_ROOT_DIR=/usr/local/opt/openssl cmake -S jupyter -B jupyter/build \
|
|
|
|
-DCMAKE_BUILD_TYPE=Release \
|
|
|
|
-DCMAKE_C_COMPILER=clang \
|
|
|
|
-DCMAKE_CXX_COMPILER=clang++ \
|
|
|
|
-DLLVM_DIR=$(llvm-config --cmakedir) \
|
|
|
|
-DCODON_PATH=install
|
2022-12-05 08:45:21 +08:00
|
|
|
|
2023-04-13 06:13:54 +08:00
|
|
|
# Then:
|
|
|
|
cmake --build jupyter/build
|
|
|
|
cmake --install jupyter/build
|
|
|
|
```
|