sandboxed-api/sandboxed_api/tools/clang_generator/BUILD
Christian Blichmann 74bb2c35ca bazel: Add build rules for the new interface generator
This adds a workspace rule that inspects the current system first and
downloads a suitable version of LLVM/Clang from GitHub if it can't
find one. In the latter case, the necessary parts are build from source,
which can take a while (~10-15m, depending on the build machine).

In order to be found, LLVM/Clang system libraries must be version 11
or higher. On Debian/Ubuntu, install `llvm-13-dev` and `libclang-13-dev`.

The new `llvm_config.bzl` implements this logic. It is loosely based on
upstream's https://github.com/llvm/llvm-project/blob/main/utils/bazel/configure.bzl.
Note that due to the way Bazel separates local repositories, we have to
duplictate some of this code.

PiperOrigin-RevId: 438759950
Change-Id: Ia65f473b4cdef6507e3816bf09794ea10963d87a
2022-04-01 00:55:30 -07:00

108 lines
3.3 KiB
Python

# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
load("//sandboxed_api/bazel:build_defs.bzl", "sapi_platform_copts")
licenses(["notice"])
cc_library(
name = "generator",
srcs = [
"diagnostics.cc",
"emitter.cc",
"generator.cc",
"types.cc",
],
hdrs = [
"diagnostics.h",
"emitter.h",
"generator.h",
"types.h",
],
copts = sapi_platform_copts(),
deps = [
"@com_google_absl//absl/container:btree",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/memory",
"@com_google_absl//absl/random",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:cord",
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/types:optional",
"@llvm-project//clang:ast",
"@llvm-project//clang:basic",
"@llvm-project//clang:format",
"@llvm-project//clang:frontend",
"@llvm-project//clang:lex",
"@llvm-project//clang:tooling",
"@llvm-project//llvm:Support",
"//sandboxed_api/util:fileops",
"//sandboxed_api/util:status",
],
)
cc_test(
name = "generator_test",
srcs = [
"emitter_test.cc",
"frontend_action_test_util.cc",
"frontend_action_test_util.h",
],
copts = sapi_platform_copts(),
deps = [
":generator",
"@com_google_googletest//:gtest_main",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/memory",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@llvm-project//clang:basic",
"@llvm-project//clang:frontend",
"@llvm-project//clang:tooling",
"@llvm-project//llvm:Support",
"//sandboxed_api:testing",
"//sandboxed_api/util:status_matchers",
],
)
# Clang tool that generates Sandboxed API headers
cc_binary(
name = "generator_tool",
srcs = [
"compilation_database.cc",
"compilation_database.h",
"generator_tool.cc",
],
copts = sapi_platform_copts(),
visibility = ["//visibility:public"],
deps = [
":generator",
"@com_google_absl//absl/memory",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@llvm-project//clang:ast",
"@llvm-project//clang:driver",
"@llvm-project//clang:frontend",
"@llvm-project//clang:tooling",
"@llvm-project//llvm:Support",
"//sandboxed_api/util:file_helpers",
"//sandboxed_api/util:fileops",
"//sandboxed_api/util:status",
],
)