|
| 1 | +# [Local build of ReactantExtra](@ref local-build) |
| 2 | + |
| 3 | +In the `deps/` subdirectory of the Reactant repository there is a script to do local builds of ReactantExtra, including debug builds. |
| 4 | + |
| 5 | +## Requirements |
| 6 | + |
| 7 | +* Julia. If you don't have it already, you can obtain it from the [official Julia website](https://julialang.org/downloads/) |
| 8 | +* A reasonably recent C/C++ compiler, ideally GCC 12+. |
| 9 | + Older compilers may not work. |
| 10 | +* Bazel. If you don't have it already, you can download a build for your platform from [the latest `bazelbuild/bazelisk` release](https://github.com/bazelbuild/bazelisk/releases/latest) and put the `bazel` executable in `PATH` |
| 11 | +* not necessary in general, but for debug builds with CUDA support, you'll need a fast linker, like `lld` or `mold` |
| 12 | + Binutils `ld` won't work, don't even try using it. |
| 13 | + You can obtain `mold` for your platform from the [latest `rui314/mold` release](https://github.com/rui314/mold/releases/latest) and put the `mold` executable in `PATH` |
| 14 | + |
| 15 | +## Building |
| 16 | + |
| 17 | +At a high-level, after you `cd` to the `deps/` directory you can run the commands |
| 18 | + |
| 19 | +```bash |
| 20 | +julia --project -e 'using Pkg; Pkg.instantiate()' # needed only the first time to install dependencies for this script |
| 21 | +julia -O0 --color=yes --project build_local.jl |
| 22 | +``` |
| 23 | + |
| 24 | +There are a few of options you may want to use to tweak the build. |
| 25 | +For more information run the command (what's show below may not be up to date, run the command locally to see the options available to you): |
| 26 | + |
| 27 | +```console |
| 28 | +% julia -O0 --project build_local.jl --help |
| 29 | +usage: build_local.jl [--debug] [--backend BACKEND] |
| 30 | + [--gcc_host_compiler_path GCC_HOST_COMPILER_PATH] |
| 31 | + [--cc CC] |
| 32 | + [--hermetic_python_version HERMETIC_PYTHON_VERSION] |
| 33 | + [--jobs JOBS] [--copt COPT] [--cxxopt CXXOPT] |
| 34 | + [--extraopt EXTRAOPT] [--color COLOR] [-h] |
| 35 | + |
| 36 | +optional arguments: |
| 37 | + --debug Build with debug mode (-c dbg). |
| 38 | + --backend BACKEND Build with the specified backend (auto, cpu, |
| 39 | + cuda). (default: "auto") |
| 40 | + --gcc_host_compiler_path GCC_HOST_COMPILER_PATH |
| 41 | + Path to the gcc host compiler. (default: |
| 42 | + "/usr/bin/gcc") |
| 43 | + --cc CC (default: "/usr/bin/cc") |
| 44 | + --hermetic_python_version HERMETIC_PYTHON_VERSION |
| 45 | + Hermetic Python version. (default: "3.10") |
| 46 | + --jobs JOBS Number of parallel jobs. (type: Int64, |
| 47 | + default: <MAXIMUM NUMBER OF CPUs>) |
| 48 | + --copt COPT Options to be passed to the C compiler. Can |
| 49 | + be used multiple times. |
| 50 | + --cxxopt CXXOPT Options to be passed to the C++ compiler. Can |
| 51 | + be used multiple times. |
| 52 | + --extraopt EXTRAOPT Extra options to be passed to Bazel. Can be |
| 53 | + used multiple times. |
| 54 | + --color COLOR Set to `yes` to enable color output, or `no` |
| 55 | + to disable it. Defaults to same color setting |
| 56 | + as the Julia process. (default: "no") |
| 57 | + -h, --help show this help message and exit |
| 58 | +``` |
| 59 | + |
| 60 | +### Doing a build on a system with memoryor number of processes restrictions |
| 61 | + |
| 62 | +If you try to do the build on certain systems where there are in place restrictions on the number of processes or memory that your user can use (for example login node of clusters), you may have to limit the number of parallel jobs used by Bazel. |
| 63 | +By default Bazel would try to use the maximum number of CPUs available on the system, if you need reduce that pass the `--jobs JOBS` flag option. |
| 64 | +The Bazel server may be terminated abruptly if using too much memory (e.g. if concurrent compiler processes are cumulatively using a large amount of memory), also in this case reducing the number of parallel jobs may be beneficial. |
| 65 | + |
| 66 | +### CUDA debug build |
| 67 | + |
| 68 | +A CUDA debug build (`--debug --backend=cuda`) requires a recent GCC compiler (at least v12) and also a fast linker (see requirements above). |
| 69 | +You can tell GCC to use either `lld` or `mold` with `--extraopt '--linkopt=-fuse-ld=lld'` or `--extraopt '--linkopt=-fuse-ld=mold'` respectively. |
| 70 | +NOTE: the option `-fuse-ld=mold` was added in GCC 12, if you're trying to use an older version you can have some luck by making a symlink named `ld` pointing to `mold` in `PATH`, with higher precendce than Binutils `ld`. |
| 71 | + |
| 72 | +### Using ccache |
| 73 | + |
| 74 | +If you want to use `ccache` as your compiler, you may have to add the flag `--extraopt "--sandbox_writable_path=/path/to/ccache/directory"` to let `ccache` write to its own directory. |
0 commit comments