Files
carbon-lang/toolchain/base/BUILD
T
Chandler CarruthandGeoff Romer 1459332031 Add subcommands and busybox entry points for LLVM tools (#5049)
This adds support for most of the remaining LLVM command line tools
using a generic, generated wrapper. The subcommand interface for these
is (much) less interesting than our other subcommands, but it gives us
a uniform and consistent layer.

Note that I structured these as nested sub-sub-commands below an `llvm`
subcommand because of an expectation that we will want to add more, and
ones that don't use this generic layer. Some concrete future work:

- Add the `opt` and `llc` tools as subcommands for easier debugging and
  experimentation with LLVM IR output from Carbon's toolchain.
- Potentially sink `lld` below the `llvm` layer given that it has
  significantly less user visibility than commands like `clang`.

Unfortunately, the current driver subcommand APIs make nested
subcommands awkward. I've added a somewhat rough hack here to let the
LLVM tools go in, but there are some TODOs that I want to address in
a follow-up that works to adjust the structure of this code to be more
conducive to nesting like this.

Depends on #5048 -- only the last commit should be reviewed here.

---------

Co-authored-by: Geoff Romer <gromer@google.com>
2025-03-04 18:00:06 +00:00

189 lines
3.9 KiB
Python

# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
# Exceptions. See /LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load("llvm_tools.bzl", "LLVM_MAIN_TOOLS", "generate_llvm_tools_def")
package(default_visibility = ["//visibility:public"])
cc_library(
name = "index_base",
hdrs = ["index_base.h"],
deps = [
"//common:ostream",
"@llvm-project//llvm:Support",
],
)
cc_library(
name = "kind_switch",
hdrs = ["kind_switch.h"],
deps = [
"@llvm-project//llvm:Support",
],
)
cc_library(
name = "pretty_stack_trace_function",
hdrs = ["pretty_stack_trace_function.h"],
deps = [
"@llvm-project//llvm:Support",
],
)
cc_library(
name = "mem_usage",
hdrs = ["mem_usage.h"],
deps = [
":yaml",
"//common:map",
"//common:set",
"@llvm-project//llvm:Support",
],
)
cc_library(
name = "timings",
hdrs = ["timings.h"],
deps = [
":yaml",
"@llvm-project//llvm:Support",
],
)
cc_library(
name = "value_ids",
hdrs = ["value_ids.h"],
deps = [
":index_base",
"//common:check",
"//common:ostream",
"@llvm-project//llvm:Support",
],
)
cc_library(
name = "value_store",
hdrs = ["value_store.h"],
deps = [
":mem_usage",
":yaml",
"//common:check",
"//common:hashtable_key_context",
"//common:ostream",
"//common:set",
"@llvm-project//llvm:Support",
],
)
cc_test(
name = "value_store_test",
size = "small",
srcs = ["value_store_test.cpp"],
deps = [
":value_ids",
":value_store",
"//common:raw_string_ostream",
"//testing/base:gtest_main",
"//toolchain/testing:yaml_test_helpers",
"@googletest//:gtest",
],
)
cc_library(
name = "int",
srcs = ["int.cpp"],
hdrs = ["int.h"],
deps = [
":index_base",
":mem_usage",
":value_store",
":yaml",
"//common:check",
"//common:hashtable_key_context",
"//common:ostream",
"//common:set",
"@llvm-project//llvm:Support",
],
)
cc_test(
name = "int_test",
size = "small",
srcs = ["int_test.cpp"],
deps = [
":int",
"//common:raw_string_ostream",
"//testing/base:gtest_main",
"//toolchain/testing:yaml_test_helpers",
"@googletest//:gtest",
],
)
generate_llvm_tools_def(
name = "llvm_tools_def",
out = "llvm_tools.def",
)
config_setting(
name = "is_macos",
constraint_values = ["@platforms//os:macos"],
)
cc_library(
name = "llvm_tools",
srcs = ["llvm_tools.cpp"],
hdrs = ["llvm_tools.h"],
linkopts = select({
# TODO: This should be moved upstream to LLVM's tool libraries that
# require it.
":is_macos": [
"-framework",
"CoreFoundation",
],
"//conditions:default": [],
}),
deps = [
":llvm_tools_def",
"//common:command_line",
"//common:enum_base",
"@llvm-project//llvm:Support",
] + [info.lib for info in LLVM_MAIN_TOOLS.values()],
)
cc_library(
name = "shared_value_stores",
hdrs = ["shared_value_stores.h"],
deps = [
":int",
":mem_usage",
":value_ids",
":value_store",
":yaml",
],
)
cc_test(
name = "shared_value_stores_test",
size = "small",
srcs = ["shared_value_stores_test.cpp"],
deps = [
":shared_value_stores",
"//common:raw_string_ostream",
"//testing/base:gtest_main",
"//toolchain/testing:yaml_test_helpers",
"@googletest//:gtest",
],
)
cc_library(
name = "yaml",
hdrs = ["yaml.h"],
deps = [
"//common:check",
"//common:ostream",
"@llvm-project//llvm:Support",
],
)