Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
21 changes: 21 additions & 0 deletions utils/bazel/llvm-project-overlay/clang-tools-extra/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("//:vars.bzl", "LLVM_VERSION_MAJOR")
load("//clang:defs.bzl", "BUILTIN_HEADERS_GEN_DIR")
load("defs.bzl", "symlink")

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

licenses(["notice"])

symlink(
name = "builtin_headers",
srcs = ["//clang:builtin_headers_gen"],
destination = "lib/clang/{0}/include".format(LLVM_VERSION_MAJOR),
partition = BUILTIN_HEADERS_GEN_DIR,
)
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ cc_library(
cc_binary(
name = "clang-tidy",
srcs = ["tool/ClangTidyToolMain.cpp"],
data = ["//clang-tools-extra:builtin_headers"],
stamp = 0,
deps = [":tool"],
)
Expand Down
26 changes: 26 additions & 0 deletions utils/bazel/llvm-project-overlay/clang-tools-extra/defs.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

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

def _symlink_impl(ctx):
copied_files = []
for input_file in ctx.files.srcs:
(_, _, relative_filename) = input_file.path.rpartition(ctx.attr.partition)
output_file = ctx.actions.declare_file(paths.join(ctx.attr.destination, relative_filename))
ctx.actions.symlink(
target_file = input_file,
output = output_file,
)
copied_files.append(output_file)
return DefaultInfo(files = depset(copied_files))

symlink = rule(
implementation = _symlink_impl,
attrs = {
"destination": attr.string(mandatory = True),
"partition": attr.string(mandatory = True),
"srcs": attr.label_list(allow_files = True),
},
)
12 changes: 8 additions & 4 deletions utils/bazel/llvm-project-overlay/clang/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ load(
"LLVM_VERSION_MINOR",
"LLVM_VERSION_PATCH",
)
load("defs.bzl", "BUILTIN_HEADERS_GEN_DIR")

package(
default_visibility = ["//visibility:public"],
Expand Down Expand Up @@ -1696,14 +1697,17 @@ builtin_headers = glob(
genrule(
name = "builtin_headers_gen",
srcs = builtin_headers,
outs = [hdr.replace("lib/Headers/", "staging/include/") for hdr in builtin_headers],
outs = [
header.replace("lib/Headers/", BUILTIN_HEADERS_GEN_DIR)
for header in builtin_headers
],
cmd = """
for src in $(SRCS); do
relsrc=$${src#*"$(WORKSPACE_ROOT)"/clang/lib/Headers}
target=$(@D)/staging/include/$$relsrc
relsrc=$${{src#*"$(WORKSPACE_ROOT)"/clang/lib/Headers}}
target=$(@D)/{resource_dir}$$relsrc
mkdir -p $$(dirname $$target)
cp $$src $$target
done""",
done""".format(resource_dir = BUILTIN_HEADERS_GEN_DIR),
output_to_bindir = 1,
toolchains = [
":workspace_root",
Expand Down
5 changes: 5 additions & 0 deletions utils/bazel/llvm-project-overlay/clang/defs.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

BUILTIN_HEADERS_GEN_DIR = "staging/include/"