Skip to content

Commit

Permalink
Simplify setting up LLVM as bazel external repo
Browse files Browse the repository at this point in the history
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
  • Loading branch information
chsigg committed Aug 19, 2021
1 parent 96fbd5c commit 81d5412
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 58 deletions.
24 changes: 13 additions & 11 deletions utils/bazel/WORKSPACE
Expand Up @@ -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,
Expand All @@ -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 = [
Expand All @@ -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,
Expand All @@ -54,15 +56,15 @@ 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 = [
"https://github.com/KhronosGroup/Vulkan-Headers/archive/9bd3f561bcee3f01d22912de10bb07ce4e23d378.tar.gz",
],
)

load(":vulkan_sdk.bzl", "vulkan_sdk_setup")
load("@llvm-raw//utils/bazel:vulkan_sdk.bzl", "vulkan_sdk_setup")

maybe(
vulkan_sdk_setup,
Expand Down
31 changes: 5 additions & 26 deletions utils/bazel/configure.bzl
Expand Up @@ -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")

Expand Down Expand Up @@ -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 = 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,
)
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")

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
Expand All @@ -61,7 +48,7 @@ def _overlay_directories(repository_ctx):

cmd = [
python_bin,
overlay_script,
script_path,
"--src",
src_path,
"--overlay",
Expand Down Expand Up @@ -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),
},
)
Expand Down
19 changes: 7 additions & 12 deletions utils/bazel/examples/submodule/WORKSPACE
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions utils/bazel/terminfo.bzl
Expand Up @@ -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,
),
}
Expand Down Expand Up @@ -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(
Expand Down
12 changes: 6 additions & 6 deletions utils/bazel/zlib.bzl
Expand Up @@ -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(
Expand All @@ -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,
),
},
Expand All @@ -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,
),
},
Expand All @@ -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(
Expand Down

0 comments on commit 81d5412

Please sign in to comment.