llvm-capstone/utils/bazel
2023-01-16 13:14:15 +01:00
..
deps_impl
examples Update bazel examples. 2021-08-20 08:10:57 +02:00
llvm_configs Revert "[Bazel] Remove define HAVE_LSEEK64 to match cmake config." 2022-12-20 20:33:20 +01:00
llvm-project-overlay [Bazel] Use LLVM_VERSION from llvm/CMakeLists.txt 2023-01-14 10:26:01 +09:00
third_party_build [bazel] Restore libpfm as a conditional dependency for exegesis. 2022-12-28 08:13:20 -08:00
.bazelignore [Bazel] Add examples to bazelignore 2021-07-16 13:58:21 -07:00
.bazelrc [bazel] Restore libpfm as a conditional dependency for exegesis. 2022-12-28 08:13:20 -08:00
.bazelversion [Bazel] Bump bazel version to 5.0. 2022-09-13 20:09:13 +02:00
.gitignore [Bazel] Update README with examples 2021-06-30 16:50:23 -07:00
BUILD.bazel
configure.bzl [bazel] Another blank-line format fix for the utils/bazel/configure.bzl, NFC 2023-01-16 13:14:15 +01:00
overlay_directories.py
README.md [bazel][docs] Mention how to provide path to compiler 2022-08-22 10:13:47 -07:00
terminfo.bzl Initialize terminfo.bzl linkopts to None 2022-01-26 11:03:26 -08:00
vulkan_sdk.bzl
WORKSPACE [bazel] Update the mpfr URL to a stable one 2023-01-09 10:36:15 +01:00
zlib.bzl Simplify setting up LLVM as bazel external repo 2021-08-19 09:37:26 +02:00

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

  1. git clone https://github.com/llvm/llvm-project.git; cd llvm-project if you don't have a checkout yet.
  2. 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/main/install.html.
  3. cd utils/bazel
  4. bazel build --config=generic_clang @llvm-project//... (if building on Unix with Clang/LLD). --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 strategy 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.

To specify a specific local compiler to use, add the following bazel flag:

build --repo_env=CC=$PATH_TO_CC

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.

Continuous Testing

A Buildkite pipeline runs the full Bazel build on every commit to the main branch. Notifications of failures are sent to the llvm-bazel-alerts google group, which anyone is free to join. Currently, the behavior is just to send an email on each failure using Buildkite's built-in notification system, so if you subscribe, it is highly recommended that you set up email filters or some other mechanism to not flood your inbox. More sophisticated notifications, e.g. only on status change or routed based on blamelist are TODO (contributions welcome).

Pre-merge Testing

A Buildkite pipeline runs the full Bazel build as a pre-merge test using the LLVM pre-merge testing. It is triggered on all changes to the utils/bazel directory and when the patch author is a member of the Bazel Phabricator project. If you use or benefit from the Bazel build, please join the project so that you can help keep it green. As a bonus, it runs in under 5 minutes, much faster than any of the other pre-merge builds.

Usage in Downstream Projects

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.