Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Try loading per-user configuration.
try-import %workspace%/user.bazelrc

# On Windows clang.exe tries to find the MSVC toolchain by looking at environmental variables,
# querying Visual Studio instances via COM (>=2017) and reading Registry keys (<=2015).
# ProgramData data is typically required for COM api querying, unless a custom location for
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ jobs:
tag: [10, 11]
env:
LLVM_INSTALL_PATH: /usr/lib/llvm-${{ matrix.tag }}

steps:
- uses: actions/checkout@v2

- name: Setup LLVM-${{ matrix.tag }}
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x ./llvm.sh
sudo ./llvm.sh ${{ matrix.tag }}
sudo apt install -y llvm-${{ matrix.tag }}-dev libclang-${{ matrix.tag }}-dev liblldb-${{ matrix.tag }}-dev

- name: Build
run: bazel build :all

- name: Test
run: bazel test --test_output=errors :all
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# Bazel directories/symlinks
bazel-*
user.bazelrc

# YouCompleteMe
.ycm_extra_conf.py
10 changes: 2 additions & 8 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,8 @@ cc_library(
data = [
"//testdata:test_binary_gen",
"//testdata:test_binary_srcs",
] + select({
"@bazel_tools//src/conditions:windows": [
# There is no lldb-server on Windows.
],
"//conditions:default": [
"@llvm_project_local//:lldb-server",
],
}),
"@llvm_project_local//:lldb-server",
],
deps = [
"@bazel_tools//tools/cpp/runfiles",
"@llvm_project_local//:lldb-api",
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ bazel test :all
bazel run :main -- "(1 + 2) * 42 / 4"
```

Depending on your distribution of LLVM, you may need to provide
`--@llvm_project_local//:llvm_build={static,dynamic}` flag. For example, if your
`liblldb.so` is linked dynamically (this is the case when installing via `apt`),
then you need to use `llvm_build=dynamic`. The build script [tries to choose the
correct default value automatically](/build_defs/repo_rules.bzl#L21), but it can
be wrong in some situations (please, report and contribute 🙂).

> **Hint:** You can add this option to your `user.bazelrc`.

## Disclamer

This is not an officially supported Google product.
15 changes: 12 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ workspace(name = "lldb_eval")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "bazel_skylib",
sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c",
urls = [
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
],
)

http_archive(
name = "com_google_googletest",
sha256 = "ff7a82736e158c077e76188232eac77913a15dac0b22508c390ab3f88e6d6d86",
strip_prefix = "googletest-b6cd405286ed8635ece71c72f118e659f4ade3fb",
urls = ["https://github.com/google/googletest/archive/b6cd405286ed8635ece71c72f118e659f4ade3fb.zip"], # 2019-01-07
sha256 = "94c634d499558a76fa649edb13721dce6e98fb1e7018dfaeba3cd7a083945e91",
strip_prefix = "googletest-release-1.10.0",
urls = ["https://github.com/google/googletest/archive/release-1.10.0.zip"],
)

load("//build_defs:repo_rules.bzl", "llvm_project_configure")
Expand Down
125 changes: 103 additions & 22 deletions build_defs/llvm_project_local.BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,44 @@
load("@bazel_skylib//lib:selects.bzl", "selects")
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("@rules_cc//cc:defs.bzl", "cc_library")

package(default_visibility = ["//visibility:public"])

string_flag(
name = "llvm_build",
build_setting_default = "{LLVM_BUILD_DEFAULT}",
values = [
"static",
"dynamic",
],
)

config_setting(
name = "llvm_build_static",
flag_values = {":llvm_build": "static"},
)

config_setting(
name = "llvm_build_dynamic",
flag_values = {":llvm_build": "dynamic"},
)

selects.config_setting_group(
name = "linux_dynamic",
match_all = [
"@bazel_tools//src/conditions:linux_x86_64",
":llvm_build_dynamic",
],
)

selects.config_setting_group(
name = "linux_static",
match_all = [
"@bazel_tools//src/conditions:linux_x86_64",
":llvm_build_static",
],
)

LLVM_LINKOPTS = select({
"@bazel_tools//src/conditions:windows": [],
"//conditions:default": [
Expand Down Expand Up @@ -68,6 +105,17 @@ filegroup(
]),
)

filegroup(
name = "libllvm-so",
srcs = select({
"@bazel_tools//src/conditions:windows": [
],
"//conditions:default": glob([
"lib/libLLVM*.so*",
]),
}),
)

filegroup(
name = "clang-headers",
srcs = glob([
Expand All @@ -80,21 +128,36 @@ filegroup(
]),
)

filegroup(
name = "libclang-cpp-so",
srcs = select({
"@bazel_tools//src/conditions:windows": [
],
"//conditions:default": glob([
"lib/libclang-cpp*.so*",
]),
}),
)

cc_library(
name = "llvm-support",
srcs = select({
"@bazel_tools//src/conditions:windows": [
"lib/LLVMSupport.lib",
"lib/LLVMDemangle.lib",
],
"//conditions:default": [
":linux_dynamic": [
":libllvm-so",
],
":linux_static": [
"lib/libLLVMSupport.a",
"lib/libLLVMDemangle.a",
],
}),
hdrs = [":llvm-headers"],
includes = ["include"],
linkopts = LLVM_LINKOPTS,
linkstatic = 1,
)

cc_library(
Expand All @@ -107,8 +170,10 @@ cc_library(
"lib/LLVMBitstreamReader.lib",
"lib/LLVMBinaryFormat.lib",
],
"//conditions:default": [
# $(llvm-config --libs mc core support)
":linux_dynamic": [
":libllvm-so",
],
":linux_static": [
"lib/libLLVMCore.a",
"lib/libLLVMRemarks.a",
"lib/libLLVMBitstreamReader.a",
Expand All @@ -117,6 +182,7 @@ cc_library(
}),
hdrs = [":llvm-headers"],
includes = ["include"],
linkstatic = 1,
deps = [":llvm-support"],
)

Expand All @@ -128,33 +194,27 @@ cc_library(
"lib/LLVMDebugInfoCodeView.lib",
"lib/LLVMDebugInfoMSF.lib",
],
"//conditions:default": [
":linux_dynamic": [
":libllvm-so",
],
":linux_static": [
"lib/libLLVMMC.a",
"lib/libLLVMDebugInfoCodeView.a",
"lib/libLLVMDebugInfoMSF.a",
],
}),
hdrs = [":llvm-headers"],
includes = ["include"],
linkstatic = 1,
deps = [":llvm-core"],
)

cc_library(
name = "llvm-shared",
srcs = select({
"@bazel_tools//src/conditions:windows": [
],
"//conditions:default": glob([
"lib/libLLVM*.so",
]),
}),
srcs = [":libllvm-so"],
hdrs = [":llvm-headers"],
includes = ["include"],
deps = [
":llvm-core",
":llvm-mc",
":llvm-support",
],
linkstatic = 1,
)

cc_library(
Expand All @@ -163,12 +223,16 @@ cc_library(
"@bazel_tools//src/conditions:windows": [
"lib/clangBasic.lib",
],
"//conditions:default": [
":linux_dynamic": [
":libclang-cpp-so",
],
":linux_static": [
"lib/libclangBasic.a",
],
}),
hdrs = [":clang-headers"],
includes = ["include"],
linkstatic = 1,
deps = [
":llvm-core",
":llvm-mc",
Expand All @@ -182,18 +246,30 @@ cc_library(
"@bazel_tools//src/conditions:windows": [
"lib/clangLex.lib",
],
"//conditions:default": [
":linux_dynamic": glob([
"lib/libclang-cpp*.so*",
]),
":linux_static": [
"lib/libclangLex.a",
],
}),
hdrs = [":clang-headers"],
includes = ["include"],
linkstatic = 1,
deps = [
":clang-basic",
":llvm-support",
],
)

cc_library(
name = "clangcpp-shared",
srcs = [":libclang-cpp-so"],
hdrs = [":clang-headers"],
includes = ["include"],
linkstatic = 1,
)

cc_library(
name = "lldb-api",
srcs = select({
Expand All @@ -211,8 +287,13 @@ cc_library(
"include/lldb/**/*.inc",
]),
includes = ["include"],
deps = [
":llvm-shared", # liblldb can be dynamically linked and depend on libLLVM.
":llvm-support",
],
deps = select({
":llvm_build_dynamic": [
":llvm-shared",
":clangcpp-shared",
],
":llvm_build_static": [
# Don't have any dependencies if linked statically.
],
}),
)
31 changes: 28 additions & 3 deletions build_defs/repo_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,25 @@
This module configures a local repository for an llvm-project.
"""

load("@bazel_skylib//lib:paths.bzl", "paths")

def _get_llvm_build_type(ctx, llvm_path):
if ctx.os.name.startswith("windows"):
# There are no prebuilt binaries for Windows, so always assume static.
return "static"

ldd = ctx.which("ldd")
if ldd == None:
# No `ldd`, can't do without it.
return "static"

# Execute `ldd liblldb.so` to figure out whether it depends on libLLVM.so.
result = ctx.execute([ldd, paths.join(llvm_path, "lib", "liblldb.so")])
if result.stdout.find("libLLVM") != -1:
return "dynamic"

return "static"

def _impl(repository_ctx):
llvm_path = repository_ctx.os.environ.get("LLVM_INSTALL_PATH")
if llvm_path == None:
Expand All @@ -24,15 +43,21 @@ def _impl(repository_ctx):
"with LLVM {bin,lib,include} directories. E.g. \"/usr/lib/llvm\".",
)

repository_ctx.symlink(llvm_path + "/bin", "bin")
repository_ctx.symlink(llvm_path + "/lib", "lib")
repository_ctx.symlink(llvm_path + "/include", "include")
# Try to guess a default value for :llvm_build flag. It should be "dynamic"
# if liblldb.so is built dynamically and "static" otherwise.
llvm_build = _get_llvm_build_type(repository_ctx, llvm_path)

repository_ctx.symlink(paths.join(llvm_path, "bin"), "bin")
repository_ctx.symlink(paths.join(llvm_path, "lib"), "lib")
repository_ctx.symlink(paths.join(llvm_path, "include"), "include")
repository_ctx.template(
"BUILD",
Label("//build_defs:llvm_project_local.BUILD"),
substitutions = {"{LLVM_BUILD_DEFAULT}": llvm_build},
)

llvm_project_configure = repository_rule(
implementation = _impl,
environ = ["LLVM_INSTALL_PATH"],
local = True,
)
12 changes: 3 additions & 9 deletions tools/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,11 @@ cc_binary(
data = [
"//testdata:fuzzer_binary_gen",
"//testdata:fuzzer_binary_srcs",
] + select({
"@bazel_tools//src/conditions:windows": [
# There is no lldb-server on Windows.
],
"//conditions:default": [
"@llvm_project_local//:lldb-server",
],
}),
"@llvm_project_local//:lldb-server",
],
deps = [
":fuzzer_lib",
"//:lldb-eval",
"//tools:fuzzer_lib",
"@bazel_tools//tools/cpp/runfiles",
"@llvm_project_local//:lldb-api",
],
Expand Down