Simplify setting up LLVM as bazel external repo

Only require one intermediate repository instead of two.
Fewer parameters in llvm_config.

Second attempt of https://reviews.llvm.org/D107714, this time also updating `third_party_build` and `deps_impl` paths.

Reviewed By: GMNGeoffrey

Differential Revision: https://reviews.llvm.org/D108274
This commit is contained in:
Christian Sigg 2021-08-18 09:14:42 +02:00
parent 96fbd5cd5e
commit 81d5412439
5 changed files with 34 additions and 58 deletions

View File

@ -16,15 +16,17 @@ http_archive(
],
)
load(":configure.bzl", "llvm_configure")
llvm_configure(
name = "llvm-project",
overlay_path = "llvm-project-overlay",
src_path = "../..",
new_local_repository(
name = "llvm-raw",
path = "../../",
build_file_content = "# empty",
)
load(":terminfo.bzl", "llvm_terminfo_from_env")
load("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure")
llvm_configure(name = "llvm-project")
load("@llvm-raw//utils/bazel:terminfo.bzl", "llvm_terminfo_from_env")
maybe(
llvm_terminfo_from_env,
@ -34,7 +36,7 @@ maybe(
maybe(
http_archive,
name = "zlib",
build_file = "//third_party_build:zlib.BUILD",
build_file = "@llvm-raw//utils/bazel/third_party_build:zlib.BUILD",
sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1",
strip_prefix = "zlib-1.2.11",
urls = [
@ -43,7 +45,7 @@ maybe(
],
)
load(":zlib.bzl", "llvm_zlib_from_env")
load("@llvm-raw//utils/bazel:zlib.bzl", "llvm_zlib_from_env")
maybe(
llvm_zlib_from_env,
@ -54,7 +56,7 @@ maybe(
maybe(
http_archive,
name = "vulkan_headers",
build_file = "//third_party_build:vulkan_headers.BUILD",
build_file = "@llvm-raw//utils/bazel/third_party_build:vulkan_headers.BUILD",
sha256 = "19f491784ef0bc73caff877d11c96a48b946b5a1c805079d9006e3fbaa5c1895",
strip_prefix = "Vulkan-Headers-9bd3f561bcee3f01d22912de10bb07ce4e23d378",
urls = [
@ -62,7 +64,7 @@ maybe(
],
)
load(":vulkan_sdk.bzl", "vulkan_sdk_setup")
load("@llvm-raw//utils/bazel:vulkan_sdk.bzl", "vulkan_sdk_setup")
maybe(
vulkan_sdk_setup,

View File

@ -5,7 +5,6 @@
"""Helper macros to configure the LLVM overlay project."""
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("@bazel_skylib//lib:paths.bzl", "paths")
load(":zlib.bzl", "llvm_zlib_disable", "llvm_zlib_system")
load(":terminfo.bzl", "llvm_terminfo_disable", "llvm_terminfo_system")
@ -33,23 +32,11 @@ DEFAULT_TARGETS = [
]
def _overlay_directories(repository_ctx):
src_workspace_path = str(repository_ctx.path(
repository_ctx.attr.src_workspace,
).dirname)
src_path = repository_ctx.path(Label("//:WORKSPACE")).dirname
bazel_path = src_path.get_child("utils").get_child("bazel")
overlay_path = bazel_path.get_child("llvm-project-overlay")
script_path = bazel_path.get_child("overlay_directories.py")
src_path = paths.join(src_workspace_path, repository_ctx.attr.src_path)
overlay_workspace_path = str(repository_ctx.path(
repository_ctx.attr.overlay_workspace,
).dirname)
overlay_path = paths.join(
overlay_workspace_path,
repository_ctx.attr.overlay_path,
)
overlay_script = repository_ctx.path(
repository_ctx.attr._overlay_script,
)
python_bin = repository_ctx.which("python3")
if not python_bin:
# Windows typically just defines "python" as python3. The script itself
@ -61,7 +48,7 @@ def _overlay_directories(repository_ctx):
cmd = [
python_bin,
overlay_script,
script_path,
"--src",
src_path,
"--overlay",
@ -98,14 +85,6 @@ llvm_configure = repository_rule(
local = True,
configure = True,
attrs = {
"_overlay_script": attr.label(
default = Label("//:overlay_directories.py"),
allow_single_file = True,
),
"overlay_workspace": attr.label(default = Label("//:WORKSPACE")),
"overlay_path": attr.string(default = DEFAULT_OVERLAY_PATH),
"src_workspace": attr.label(default = Label("//:WORKSPACE")),
"src_path": attr.string(mandatory = True),
"targets": attr.string_list(default = DEFAULT_TARGETS),
},
)

View File

@ -17,21 +17,16 @@ http_archive(
],
)
# Or wherever your submodule is located.
SUBMODULE_PATH = "third_party/llvm-project"
local_repository(
name = "llvm-bazel",
path = SUBMODULE_PATH + "/utils/bazel",
new_local_repository(
name = "llvm-raw",
build_file_content = "# empty",
# Or wherever your submodule is located.
path = "third_party/llvm-project",
)
load("@llvm-bazel//:configure.bzl", "llvm_configure", "llvm_disable_optional_support_deps")
load("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure", "llvm_disable_optional_support_deps")
llvm_configure(
name = "llvm-project",
src_path = SUBMODULE_PATH,
src_workspace = "@submodule_example//:WORKSPACE",
)
llvm_configure(name = "llvm-project")
# Disables optional dependencies for Support like zlib and terminfo. You may
# instead want to configure them using the macros in the corresponding bzl

View File

@ -27,7 +27,7 @@ def _llvm_terminfo_disable_impl(repository_ctx):
_terminfo_disable_attrs = {
"_disable_build_template": attr.label(
default = Label("//deps_impl:terminfo_disable.BUILD"),
default = Label("//utils/bazel/deps_impl:terminfo_disable.BUILD"),
allow_single_file = True,
),
}
@ -147,11 +147,11 @@ def _merge_attrs(attrs_list):
_terminfo_system_attrs = _merge_attrs([_terminfo_disable_attrs, {
"_system_build_template": attr.label(
default = Label("//deps_impl:terminfo_system.BUILD"),
default = Label("//utils/bazel/deps_impl:terminfo_system.BUILD"),
allow_single_file = True,
),
"_terminfo_test_source": attr.label(
default = Label("//deps_impl:terminfo_test.c"),
default = Label("//utils/bazel/deps_impl:terminfo_test.c"),
allow_single_file = True,
),
"candidate_system_linkopts": attr.string_list(

View File

@ -33,7 +33,7 @@ llvm_zlib_external = repository_rule(
implementation = _llvm_zlib_external_impl,
attrs = {
"_external_build_template": attr.label(
default = Label("//deps_impl:zlib_external.BUILD"),
default = Label("//utils/bazel/deps_impl:zlib_external.BUILD"),
allow_single_file = True,
),
"external_zlib": attr.string(
@ -56,7 +56,7 @@ llvm_zlib_system = repository_rule(
implementation = _llvm_zlib_system_impl,
attrs = {
"_system_build_template": attr.label(
default = Label("//deps_impl:zlib_system.BUILD"),
default = Label("//utils/bazel/deps_impl:zlib_system.BUILD"),
allow_single_file = True,
),
},
@ -73,7 +73,7 @@ llvm_zlib_disable = repository_rule(
implementation = _llvm_zlib_disable_impl,
attrs = {
"_disable_build_template": attr.label(
default = Label("//deps_impl:zlib_disable.BUILD"),
default = Label("//utils/bazel/deps_impl:zlib_disable.BUILD"),
allow_single_file = True,
),
},
@ -92,15 +92,15 @@ llvm_zlib_from_env = repository_rule(
implementation = _llvm_zlib_from_env_impl,
attrs = {
"_disable_build_template": attr.label(
default = Label("//deps_impl:zlib_disable.BUILD"),
default = Label("//utils/bazel/deps_impl:zlib_disable.BUILD"),
allow_single_file = True,
),
"_external_build_template": attr.label(
default = Label("//deps_impl:zlib_external.BUILD"),
default = Label("//utils/bazel/deps_impl:zlib_external.BUILD"),
allow_single_file = True,
),
"_system_build_template": attr.label(
default = Label("//deps_impl:zlib_system.BUILD"),
default = Label("//utils/bazel/deps_impl:zlib_system.BUILD"),
allow_single_file = True,
),
"external_zlib": attr.label(