|
| 1 | + |
| 2 | +# Build ICICLE from source |
| 3 | + |
| 4 | +This guide will help you get started with building, testing, and installing ICICLE, whether you're using C++, Rust, or Go. It also covers installation of the CUDA backend and important build options. |
| 5 | + |
| 6 | +## Building and Testing ICICLE frontend |
| 7 | + |
| 8 | +### C++: Build, Test, and Install (Frontend) |
| 9 | + |
| 10 | +ICICLE can be built and tested in C++ using CMake. The build process is straightforward, but there are several flags you can use to customize the build for your needs. |
| 11 | + |
| 12 | +#### Build Commands |
| 13 | + |
| 14 | +1. **Clone the ICICLE repository:** |
| 15 | + ```bash |
| 16 | + git clone https://github.com/ingonyama-zk/icicle.git |
| 17 | + cd icicle |
| 18 | + ``` |
| 19 | + |
| 20 | +2. **Configure the build:** |
| 21 | + ```bash |
| 22 | + mkdir -p build && rm -rf build/* |
| 23 | + cmake -S icicle -B build -DFIELD=babybear |
| 24 | + ``` |
| 25 | + |
| 26 | +:::info |
| 27 | +To specify the field, use the flag -DFIELD=field, where field can be one of the following: babybear, stark252, m31, koalabear. |
| 28 | + |
| 29 | +To specify a curve, use the flag -DCURVE=curve, where curve can be one of the following: bn254, bls12_377, bls12_381, bw6_761, grumpkin. |
| 30 | +::: |
| 31 | + |
| 32 | +:::tip |
| 33 | +If you have access to cuda backend repo, it can be built along ICICLE frontend by adding the following to the cmake command |
| 34 | +- `-DCUDA_BACKEND=local` # if you have it locally |
| 35 | +- `-DCUDA_BACKEND=<commit|branch>` # to pull CUDA backend, given you have access |
| 36 | +::: |
| 37 | + |
| 38 | +3. **Build the project:** |
| 39 | + ```bash |
| 40 | + cmake --build build -j |
| 41 | + ``` |
| 42 | + This is building the [libicicle_device](./libraries.md#icicle-device) and the [libicicle_field_babybear](./libraries.md#icicle-core) frontend lib that correspond to the field or curve. |
| 43 | + |
| 44 | +4. **Link:** |
| 45 | +Link you application (or library) to ICICLE: |
| 46 | +```cmake |
| 47 | +target_link_libraries(yourApp PRIVATE icicle_field_babybear icicle_device) |
| 48 | +``` |
| 49 | + |
| 50 | +5. **Installation (optional):** |
| 51 | +To install the libs, specify the install prefix in the [cmake command](./build_from_source.md#build-commands) |
| 52 | +`-DCMAKE_INSTALL_PREFIX=/install/dir/`. Default install path on linux is `/usr/local` if not specified. For other systems it may differ. The cmake command will print it to the log |
| 53 | +``` |
| 54 | +-- CMAKE_INSTALL_PREFIX=/install/dir/for/cmake/install |
| 55 | +``` |
| 56 | +Then after building, use cmake to install the libraries: |
| 57 | +``` |
| 58 | +cmake -S icicle -B build -DFIELD=babybear -DCMAKE_INSTALL_PREFIX=/path/to/install/dir/ |
| 59 | +cmake --build build -j # build |
| 60 | +cmake --install build # install icicle to /path/to/install/dir/ |
| 61 | +``` |
| 62 | + |
| 63 | +6. **Run tests (optional):** |
| 64 | +Add `-DBUILD_TESTS=ON` to the [cmake command](./build_from_source.md#build-commands) and build. |
| 65 | +Execute all tests |
| 66 | +```bash |
| 67 | +cmake -S icicle -B build -DFIELD=babybear -DBUILD_TESTS=ON |
| 68 | +cmake --build build -j |
| 69 | +cd build/tests |
| 70 | +ctest |
| 71 | +``` |
| 72 | +or choose the test-suite |
| 73 | +```bash |
| 74 | +./build/tests/test_field_api # or another test suite |
| 75 | +# can specify tests using regex. For example for tests with ntt in the name: |
| 76 | +./build/tests/test_field_api --gtest_filter="*ntt*" |
| 77 | +``` |
| 78 | +:::note |
| 79 | +Most tests assume a cuda backend exists and will fail otherwise if cannot find a CUDA device. |
| 80 | +::: |
| 81 | + |
| 82 | +#### Build Flags |
| 83 | + |
| 84 | +You can customize your ICICLE build with the following flags: |
| 85 | + |
| 86 | +- `-DCPU_BACKEND=ON/OFF`: Enable or disable built-in CPU backend. `default=ON`. |
| 87 | +- `-DCMAKE_INSTALL_PREFIX=/install/dir`: Specify install directory. `default=/usr/local`. |
| 88 | +- `-DBUILD_TESTS=ON/OFF`: Enable or disable tests. `default=OFF`. |
| 89 | +- `-DBUILD_BENCHMARKS=ON/OFF`: Enable or disable benchmarks. `default=OFF`. |
| 90 | + |
| 91 | +#### Features |
| 92 | + |
| 93 | +By default, all [features](./libraries.md#supported-curves-and-operations) are enabled. |
| 94 | +This is since installed backends may implement and register all APIs. Missing APIs in the frontend would cause linkage to fail due to missing symbols. Therefore by default we include them in the frontend part too. |
| 95 | + |
| 96 | +To disable features, add the following to the cmake command. |
| 97 | +- ntt: `-DNTT=OFF` |
| 98 | +- msm: `-DMSM=OFF` |
| 99 | +- g2 msm: `-DG2=OFF` |
| 100 | +- ecntt: `-DECNTT=OFF` |
| 101 | +- extension field: `-DEXT_FIELD=OFF` |
| 102 | + |
| 103 | +:::tip |
| 104 | +Disabling features is useful when developing with a backend that is slow to compile (e.g. CUDA backend); |
| 105 | +::: |
| 106 | + |
| 107 | +### Rust: Build, Test, and Install |
| 108 | + |
| 109 | +To build and test ICICLE in Rust, follow these steps: |
| 110 | + |
| 111 | +1. **Navigate to the Rust bindings directory:** |
| 112 | +```bash |
| 113 | +cd wrappers/rust # or go to a specific field/curve 'cd wrappers/rust/icicle-fields/icicle-babybear' |
| 114 | +``` |
| 115 | + |
| 116 | +2. **Build the Rust project:** |
| 117 | +```bash |
| 118 | +cargo build --release |
| 119 | +``` |
| 120 | +By default, all [supported features are enabled](#features). |
| 121 | +Cargo features are used to disable features, rather than enable them, for the reason explained [here](#features): |
| 122 | +- `no_g2` to disable G2 MSM |
| 123 | +- `no_ecntt` to disable ECNTT |
| 124 | + |
| 125 | +They can be disabled as follows: |
| 126 | +```bash |
| 127 | +cargo build --release --features=no_ecntt,no_g2 |
| 128 | +``` |
| 129 | + |
| 130 | +:::note |
| 131 | +If you have access to cuda backend repo, it can be built along ICICLE frontend by using the following cargo features: |
| 132 | +- `cuda_backend` : if the cuda backend resides in `icicle/backend/cuda` |
| 133 | +- `pull_cuda_backend` : to pull main branch and build it |
| 134 | +::: |
| 135 | + |
| 136 | + |
| 137 | +3. **Run tests:** |
| 138 | +```bash |
| 139 | +cargo test # optional: --features=no_ecntt,no_g2,cuda_backend |
| 140 | +``` |
| 141 | +:::note |
| 142 | +Most tests assume a CUDA backend is installed and fail otherwise. |
| 143 | +::: |
| 144 | + |
| 145 | +4. **Install the library:** |
| 146 | + |
| 147 | +By default, the libraries are installed to the `target/<buildmode>/deps/icicle` dir. If you want them installed elsewhere, define the env variable: |
| 148 | +```bash |
| 149 | +export ICICLE_INSTALL_DIR=/path/to/install/dir |
| 150 | +``` |
| 151 | + |
| 152 | +#### Use as cargo dependency |
| 153 | +In cargo.toml, specify the ICICLE libs to use: |
| 154 | + |
| 155 | +```bash |
| 156 | +[dependencies] |
| 157 | +icicle-runtime = { git = "https://github.com/ingonyama-zk/icicle.git", branch="main" } |
| 158 | +icicle-core = { git = "https://github.com/ingonyama-zk/icicle.git", branch="main" } |
| 159 | +icicle-babybear = { git = "https://github.com/ingonyama-zk/icicle.git", branch="main" } |
| 160 | +# add other ICICLE crates here if need additional fields/curves |
| 161 | +``` |
| 162 | +
|
| 163 | +Can specify `branch = <branch-name>` or `tag = <tag-name>` or `rev = <commit-id>`. |
| 164 | +
|
| 165 | +To disable features: |
| 166 | +```bash |
| 167 | +icicle-bls12-377 = { git = "https://github.com/ingonyama-zk/icicle.git", features = ["no_g2"] } |
| 168 | +``` |
| 169 | +
|
| 170 | +As explained above, the libs will be built and installed to `target/<buildmode>/deps/icicle` so you can easily link to them. Alternatively you can set `ICICLE_INSTALL_DIR` env variable for a custom install directory. |
| 171 | +
|
| 172 | +:::warning |
| 173 | +Make sure to install icicle libs when installing a library/application that depends on icicle such that it is located at runtime. |
| 174 | +::: |
| 175 | +
|
| 176 | +### Go: Build, Test, and Install (TODO) |
| 177 | +
|
| 178 | +--- |
| 179 | +**To install CUDA backend and license click [here](./install_cuda_backend.md#installation)** |
0 commit comments