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