Skip to main content

Installation and configuration

Using pre-built binaries

The easiest way to access zkLLVM is to install pre-built binaries of its key components.

info

All pre-built binaries discussed below are only supported on x86-64 systems.

Install zkLLVM binaries

zkLLVM is distributed as a Deb package which can be installed using the following commands.

echo 'deb [trusted=yes]  http://deb.nil.foundation/ubuntu/ all main' >>/etc/apt/sources.list
apt update
apt install -y zkllvm

This will install binaries for nearly all major components of zkLLVM such as assigner and the clang frontend. Note that the Rust frontend needs to be installed separately.

To verify the installation, run:

clang-zkllvm --version

Note that the newly installed clang frontend is accessed via clang-zkllvm, not clang.

Install Rust binaries

First, install rustup.

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Then, install rslang by executing the following command.

curl --proto '=https' --tlsv1.2 -sSf https://cdn.jsdelivr.net/gh/NilFoundation/zkllvm@master/rslang-installer.py | python - --channel nightly

Alternatively, download rslang-installer.py and run it.

curl --proto '=https' --tlsv1.2 -O https://cdn.jsdelivr.net/gh/NilFoundation/zkllvm@master/rslang-installer.py
python rslang-installer.py --channel nightly
Standalone installation

To install rslang without rustup, run the below command.

curl --proto '=https' --tlsv1.2 -O https://cdn.jsdelivr.net/gh/NilFoundation/zkllvm@master/rslang-installer.py
python rslang-installer.py --no-rustup --prefix PATH

If the python command fails, specify Python 3.x explicitly by replacing python with python3.

Verify that the installation has been successful.

rustc +zkllvm -V
Command output

The output to the above command should follow the below format.

rustc x.y.z (abcabcabc yyyy-mm-dd) (zkLLVM x.y.z)

If zkLLVM x.y.z is missing from the output, the zkllvm toolchain needs to be reinstalled.

Building from sources

To build zkLLVM from its source repository, follow the below steps.

Install dependencies

Install the following dependencies.

Every dependency apart from Rust can be installed by executing the following command.

sudo apt install build-essential libssl-dev cmake clang-12 git curl pkg-config zlib

To install Rust, execute the following command.

curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
Ninja

The Ninja build system can make building zkLLVM from sources faster and more convenient. While it is not a direct dependency, using Ninja is preferable to simply using Unix makefiles. Install Ninja by running the below command.

sudo apt-get install ninja-build
Installing Boost

Installing Boost from sources is the most consistent way to ensure that the latest version of Boost is installed that matches the above version constraint.

To install Boost from sources, do the following.

  1. Navigate to the folder where you want to install Boost and download Boost.
wget https://boostorg.jfrog.io/artifactory/main/release/1.84.0/source/boost_1_84_0_rc1.tar.gz
  1. Extract the archive with Boost.
cd boost_1_84_0
  1. Prepare the build system for Boost by running bootstrap.sh.
./bootstrap.sh
  1. Install Boost system-wide.
sudo ./b2 install

Clone the repository

Clone the repository and all of its sub-modules.

git clone --recurse-submodules https://github.com/NilFoundation/zkLLVM.git
cd zkllvm
tip

As the zkLLVM repository contains many large sub-modules, it is recommended to add the following lines to the global Git configuration file before attempting to clone it.

[core]
packedGitLimit = 512m
packedGitWindowSize = 512m
[pack]
deltaCacheSize = 2047m
packSizeLimit = 2047m
windowMemory = 2047m

Configure cmake

This step is needed to define initial build targets and specify that zkLLVM should produce IRs of circuits in the .ll format compatible with Proof Market.

cmake -G "Unix Makefiles" -B ${ZKLLVM_BUILD:-build} -DCMAKE_BUILD_TYPE=Release -DCIRCUIT_ASSEMBLY_OUTPUT=TRUE .

Build clang and assigner

The next step is to build the C++ compiler and the assigner tool.

make -C ${ZKLLVM_BUILD:-build} assigner clang -j$(nproc)

Build the Rust compiler

The first step to building the Rust compiler is adding Rust tools to cmake.

cmake -G "Unix Makefiles" -B ${ZKLLVM_BUILD:-build} -DCMAKE_BUILD_TYPE=Release -DRSLANG_BUILD_EXTENDED=TRUE -DRSLANG_BUILD_TOOLS=cargo .

Afterward, export the path containing LLVM libraries.

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$(pwd)/build/libs/circifier/llvm/lib"

Use the below command to build rustc and cargo.

make -C ${ZKLLVM_BUILD:-build} rslang -j$(nproc)

After the build completes, export the RSLANG environment variable.

export RSLANG="$(pwd)/build/libs/rslang/build/host"

Verify the versions of rustc and cargo by running the following commands.

RUSTC=$RSLANG/stage1/bin/rustc $RSLANG/stage1-tools-bin/cargo --version
Finding rustc and cargo

If the terminal cannot find rustc and cargo, run find ~/zkllvm -name rustc and find ~/zkllvm -name cargo.

Advanced compiling with Rust

To use the original bootstrap system supplied by Rust (x.py), build zkllvm first.

make -C ${ZKLLVM_BUILD:-build} -j$(nproc)