1. Create your repo, such as "BuildWithLLVM"
  2. To add a local repo, copy following files to BuildWithLLVM

    • llvm-project/utils/bazel/WORKSPACE
    • .bazelrc
    • .bazelversion
    • .bazelignore
  3. Add workspace name to the start of WORKSPACE file

    workspace(name = "build_with_llvm")
  4. Change path in WORKSPACE

    new_local_repository(
     name = "llvm-raw",
     build_file_content = "# empty",
    # change path pointing to your llvm-project
     path = "/path/to/llvm-project",
    )
  5. Test the build

    bazel build --config=generic_gcc @llvm-project//llvm:all
  6. Build something depending on llvm

    Add a c++ source file main.cc

    #include <iostream>
    #include "llvm/Support/FormatVariadic.h"
    
    int main() {
     std::cout << llvm::formatv("Hello {0}", "llvm!").str() << std::endl;
     return 0;
    }

    Add BUILD file to src folder

    cc_binary(
     name = "main",
     srcs = ["src/main.cc"],
     deps = ["@llvm-project//llvm:Support"],
    )
    build run --config=generic_gcc //src:main

`Hello llvm!` should be printed.

See https://github.com/AnissL93/build_llvm_with_bazel for the code