Bazel support: Replace `PREBUILT_LLVM_PATH` with `LLVM_INSTALL_PATH`.
Pre-built LLVM+Clang libraries+headers can be found either at:
1. LLVM's source path (`PREBUILT_LLVM_PATH`) *and* build path
`"${PREBUILT_LLVM_PATH}/${CMAKE_BUILD_DIR}"` taken together, or
2. LLVM's install path (`LLVM_INSTALL_PATH`)
This CL switches from the former to the latter approach because:
1. Bazel's `glob` doesn't like dealing with `..` or absolute paths
(and Chromium places LLVM's build directory outside of LLVM's
source directory).
2. It slightly simplifies Crubit's BUILD files (see the changes
in this CL).
PiperOrigin-RevId: 451898842
diff --git a/README.md b/README.md
index 671119b..dc605f0 100644
--- a/README.md
+++ b/README.md
@@ -20,9 +20,10 @@
```
$ git clone https://github.com/llvm/llvm-project
$ cd llvm-project
-$ CC=clang CXX=clang++ cmake -S llvm -B build -DLLVM_ENABLE_PROJECTS='clang' -DCMAKE_BUILD_TYPE=Release
+$ CC=clang CXX=clang++ cmake -S llvm -B build -DLLVM_ENABLE_PROJECTS='clang' -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install
$ cmake --build build -j
$ # wait...
+$ cmake --install build
$ cd ../crubit
-$ PREBUILT_LLVM_PATH=../llvm-project bazel build //rs_bindings_from_cc:rs_bindings_from_cc_impl
-```
\ No newline at end of file
+$ LLVM_INSTALL_PATH=../llvm-project/install bazel build //rs_bindings_from_cc:rs_bindings_from_cc_impl
+```
diff --git a/bazel/llvm.bzl b/bazel/llvm.bzl
index 47e6273..1998322 100644
--- a/bazel/llvm.bzl
+++ b/bazel/llvm.bzl
@@ -7,9 +7,8 @@
# Create a loader/trampoline repository that we can call into to load LLVM.
#
# Our real goal is to choose between two different sources for LLVM binaries:
-# - if `PREBUILT_LLVM_PATH` is in the environment, we treat it as the root of
-# an LLVM tree that's been built with CMake and try to use headers and
-# libraries from there
+# - if `LLVM_INSTALL_PATH` is in the environment, we treat it as the root of
+# an LLVM installation and try to use headers and libraries from there
# - otherwise, we build LLVM from source
#
# We *could* implement this choice directly as an if/else between `http_archive`
@@ -26,9 +25,9 @@
repository_ctx.file("BUILD")
# Create `llvm.bzl` from one of `llvm_{remote|local}.bzl.tmpl`.
- if "PREBUILT_LLVM_PATH" in repository_ctx.os.environ:
- # Use prebuilt LLVM
- path = repository_ctx.os.environ["PREBUILT_LLVM_PATH"]
+ if "LLVM_INSTALL_PATH" in repository_ctx.os.environ:
+ # Use LLVM install
+ path = repository_ctx.os.environ["LLVM_INSTALL_PATH"]
# If needed, resolve relative to root of *calling* repository
if not path.startswith("/"):
@@ -41,8 +40,7 @@
"llvm.bzl",
Label("//bazel:llvm_local.bzl.tmpl"),
substitutions = {
- "${PREBUILT_LLVM_PATH}": str(path),
- "${CMAKE_BUILD_DIR}": "build",
+ "${LLVM_INSTALL_PATH}": str(path),
},
executable = False,
)
@@ -73,6 +71,6 @@
"file_at_root": attr.label(default = "//:BUILD"),
},
environ = [
- "PREBUILT_LLVM_PATH",
+ "LLVM_INSTALL_PATH",
],
)
diff --git a/bazel/llvm_local.bzl.tmpl b/bazel/llvm_local.bzl.tmpl
index b78d7ad..359d941 100644
--- a/bazel/llvm_local.bzl.tmpl
+++ b/bazel/llvm_local.bzl.tmpl
@@ -4,28 +4,22 @@
# Provide LLVM from a local tree built with CMake.
-prebuilt_llvm_tree_build_file_contents = """
+llvm_install_tree_build_file_contents = """
package(default_visibility = ["//visibility:public"])
# An extremely coarse-grained target that provides *all* headers and libraries.
cc_library(
name = "all",
srcs = glob([
- "${CMAKE_BUILD_DIR}/lib/*.a",
+ "lib/*.a",
], exclude = [
"**/*.i386.a",
]),
hdrs = glob([
- "${CMAKE_BUILD_DIR}/include/**",
- "${CMAKE_BUILD_DIR}/tools/clang/include/**",
- "clang/include/**",
- "llvm/include/**",
+ "include/**",
]),
includes = [
- "${CMAKE_BUILD_DIR}/include/",
- "${CMAKE_BUILD_DIR}/tools/clang/include/",
- "clang/include/",
- "llvm/include/",
+ "include/",
],
linkopts = ["-lncurses", "-lz"],
)
@@ -36,8 +30,8 @@
# prebuilt LLVM tree, yielding the single ":all" target.
native.new_local_repository(
name = "prebuilt-llvm",
- path = "${PREBUILT_LLVM_PATH}", # template value
- build_file_content = prebuilt_llvm_tree_build_file_contents,
+ path = "${LLVM_INSTALL_PATH}", # template value
+ build_file_content = llvm_install_tree_build_file_contents,
)
# Next, create the final repo that emulates the layout of Bazel targets in