- Create your repo, such as "BuildWithLLVM"
To add a local repo, copy following files to BuildWithLLVM
- llvm-project/utils/bazel/WORKSPACE
- .bazelrc
- .bazelversion
- .bazelignore
Add workspace name to the start of WORKSPACE file
workspace(name = "build_with_llvm")
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", )
Test the build
bazel build --config=generic_gcc @llvm-project//llvm:all
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