![]() This required substantially more invasive changes. We need to handle some of the LLVM `config.h` changes differently from the old pattern. These aren't always safe on the commandline, and the Windows ones specifically break Clang. Instead, use conditional defines in the header itself. This more closely matches how CMake builds see the definitions. I think this is also just cleaner and we should maybe move more of the macros out of Bazel. The config defines for Windows that I've kept in Bazel are the ones that LLVM's CMake does at the commandline as well. I've also added numerous ones that CMake uses and we didn't replicate in Bazel. I also needed a different approach to get `libclang` working well. This, IMO, improves things on all platforms. Now we build the plugin and actually wrap it back up with `cc_import`. We have to use a collection of manually tagged `cc_binary` rules to get the naming to work out the right way, but this isn't too different from the prior approach. By directly having a `cc_binary` rule for each platform spelling of `libclang`, we can actually extract the interface library from it and correctly depend on it with `cc_import`. I think the result now is much closer to the intent and to the CMake build for libclang. Sadly, some tests also needed disabling. This is actually narrower than what CMake does. The issue isn't indicative of anything serious -- the test just assumes Unix-style paths. I also have cleaned up the Windows flags in `.bazelrc` to much more closely match what CMake does. Differential Revision: https://reviews.llvm.org/D112399 |
||
---|---|---|
.. | ||
deps_impl | ||
examples | ||
llvm-project-overlay | ||
llvm_configs | ||
third_party_build | ||
.bazelignore | ||
.bazelrc | ||
.bazelversion | ||
.gitignore | ||
BUILD.bazel | ||
README.md | ||
WORKSPACE | ||
configure.bzl | ||
overlay_directories.py | ||
terminfo.bzl | ||
vulkan_sdk.bzl | ||
zlib.bzl |
README.md
Introduction
Warning The Bazel build is experimental and best-effort, supported in line with the policy for LLVM's peripheral support tier. LLVM's official build system is CMake. If in doubt use that. If you make changes to LLVM, you're expected to update the CMake build but you don't need to update Bazel build files. Reviewers should not ask authors to update Bazel build files unless the author has opted in to support Bazel. Keeping the Bazel build files up-to-date is on the people who use the Bazel build.
Bazel is a multi-language build system focused on reproducible builds to enable dependency analysis and caching for fast incremental builds.
The main motivation behind the existence of an LLVM Bazel build is that a number of projects that depend on LLVM use Bazel, and Bazel works best when it knows about the whole source tree (as opposed to installing artifacts coming from another build system). Community members are also welcome to use Bazel for their own development as long as they continue to maintain the official CMake build system. See also, the proposal for adding this configuration.
Quick Start
git clone https://github.com/llvm/llvm-project.git; cd llvm-project
if you don't have a checkout yet.- Install Bazel at the version indicated by .bazelversion, following the official instructions, if you don't have it installed yet: https://docs.bazel.build/versions/master/install.html.
cd utils/bazel
bazel build --config=generic_clang @llvm-project//...
(if building on Unix with Clang).--config=generic_gcc
and--config=msvc
are also available.
Configuration
The repository .bazelrc
will import user-specific settings from a
user.bazelrc
file (in addition to the standard locations). Adding your typical
config setting is recommended.
build --config=generic_clang
You can enable disk caching, which will cache build results
build --disk_cache=~/.cache/bazel-disk-cache
You can instruct Bazel to use a ramdisk for its sandboxing operations via --sandbox_base, which can help avoid IO bottlenecks for the symlink stragegy used for sandboxing. This is especially important with many inputs and many cores (see https://github.com/bazelbuild/bazel/issues/11868):
build --sandbox_base=/dev/shm
Bear in mind that this requires that your ramdisk is of sufficient size to hold any temporary files. Anecdotally, 1GB should be sufficient.
Coverage
The LLVM, MLIR, and Clang subprojects have configurations for Linux (Clang and GCC), Mac (Clang and GCC), and Windows (MSVC). Configuration options that are platform-specific are selected for in defines. Many are also hardcoded to the values currently used by all supported configurations. If there is a configuration you'd like to use that isn't supported, please send a patch.
Usage
To use in dependent projects using Bazel, you can import LLVM and then use the
provided configuration rule. See example usage in the examples/
directory.