Geoffrey Martin-Noble | 4aeb2e6 | 2021-05-18 15:42:25 -0700 | [diff] [blame] | 1 | # Introduction |
| 2 | |
| 3 | *Warning* The Bazel build is experimental and best-effort, supported in line |
| 4 | with the policy for |
| 5 | [LLVM's peripheral support tier](https://llvm.org/docs/SupportPolicy.html). |
| 6 | LLVM's official build system is CMake. If in doubt use that. If you make changes |
| 7 | to LLVM, you're expected to update the CMake build but you don't need to update |
| 8 | Bazel build files. Reviewers should not ask authors to update Bazel build files |
| 9 | unless the author has opted in to support Bazel. Keeping the Bazel build files |
| 10 | up-to-date is on the people who use the Bazel build. |
| 11 | |
| 12 | [Bazel](https://bazel.build/) is a multi-language build system focused on |
| 13 | reproducible builds to enable dependency analysis and caching for fast |
| 14 | incremental builds. |
| 15 | |
| 16 | The main motivation behind the existence of an LLVM Bazel build is that a number |
| 17 | of projects that depend on LLVM use Bazel, and Bazel works best when it knows |
| 18 | about the whole source tree (as opposed to installing artifacts coming from |
| 19 | another build system). Community members are also welcome to use Bazel for their |
| 20 | own development as long as they continue to maintain the official CMake build |
| 21 | system. See also, the |
| 22 | [proposal](https://github.com/llvm/llvm-www/blob/main/proposals/LP0002-BazelBuildConfiguration.md) |
| 23 | for adding this configuration. |
| 24 | |
| 25 | # Quick Start |
| 26 | |
| 27 | 1. `git clone https://github.com/llvm/llvm-project.git; cd llvm-project` if |
| 28 | you don't have a checkout yet. |
| 29 | 2. Install Bazel at the version indicated by [.bazelversion](./bazelversion), |
| 30 | following the official instructions, if you don't have it installed yet: |
| 31 | https://docs.bazel.build/versions/master/install.html. |
| 32 | 3. `cd utils/bazel` |
| 33 | 4. `bazel build --config=generic_clang @llvm-project//...` (if building on Unix |
| 34 | with Clang). `--config=generic_gcc` and `--config=msvc` are also available. |
| 35 | |
| 36 | |
| 37 | # Configuration |
| 38 | |
| 39 | The repository `.bazelrc` will import user-specific settings from a |
| 40 | `user.bazelrc` file (in addition to the standard locations). Adding your typical |
| 41 | config setting is recommended. |
| 42 | |
| 43 | ```.bazelrc |
| 44 | build --config=generic_clang |
| 45 | ``` |
| 46 | |
| 47 | You can enable |
| 48 | [disk caching](https://docs.bazel.build/versions/master/remote-caching.html#disk-cache), |
| 49 | which will cache build results |
| 50 | |
| 51 | ```.bazelrc |
| 52 | build --disk_cache=~/.cache/bazel-disk-cache |
| 53 | ``` |
| 54 | |
| 55 | You can instruct Bazel to use a ramdisk for its sandboxing operations via |
| 56 | [--sandbox_base](https://docs.bazel.build/versions/master/command-line-reference.html#flag--sandbox_base), |
| 57 | which can help avoid IO bottlenecks for the symlink stragegy used for |
| 58 | sandboxing. This is especially important with many inputs and many cores (see |
| 59 | https://github.com/bazelbuild/bazel/issues/11868): |
| 60 | |
| 61 | ```.bazelrc |
| 62 | build --sandbox_base=/dev/shm |
| 63 | ``` |
| 64 | |
| 65 | Bear in mind that this requires that your ramdisk is of sufficient size to hold |
| 66 | any temporary files. Anecdotally, 1GB should be sufficient. |
| 67 | |
| 68 | # Coverage |
| 69 | |
| 70 | The LLVM, MLIR, and Clang subprojects have configurations for Linux (Clang and |
| 71 | GCC), Mac (Clang and GCC), and Windows (MSVC). Configuration options that are |
| 72 | platform-specific are selected for in defines. Many are also hardcoded to the |
| 73 | values currently used by all supported configurations. If there is a |
| 74 | configuration you'd like to use that isn't supported, please send a patch. |
| 75 | |
| 76 | # Usage |
| 77 | |
Geoffrey Martin-Noble | 9cc1ddd | 2021-06-30 16:46:55 -0700 | [diff] [blame^] | 78 | To use in dependent projects using Bazel, you can import LLVM and then use the |
| 79 | provided configuration rule. See example usage in the `examples/` directory. |