Skip to content

Commit 81d5412

Browse files
committed
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
1 parent 96fbd5c commit 81d5412

File tree

5 files changed

+34
-58
lines changed

5 files changed

+34
-58
lines changed

utils/bazel/WORKSPACE

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@ http_archive(
1616
],
1717
)
1818

19-
load(":configure.bzl", "llvm_configure")
20-
21-
llvm_configure(
22-
name = "llvm-project",
23-
overlay_path = "llvm-project-overlay",
24-
src_path = "../..",
19+
new_local_repository(
20+
name = "llvm-raw",
21+
path = "../../",
22+
build_file_content = "# empty",
2523
)
2624

27-
load(":terminfo.bzl", "llvm_terminfo_from_env")
25+
load("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure")
26+
27+
llvm_configure(name = "llvm-project")
28+
29+
load("@llvm-raw//utils/bazel:terminfo.bzl", "llvm_terminfo_from_env")
2830

2931
maybe(
3032
llvm_terminfo_from_env,
@@ -34,7 +36,7 @@ maybe(
3436
maybe(
3537
http_archive,
3638
name = "zlib",
37-
build_file = "//third_party_build:zlib.BUILD",
39+
build_file = "@llvm-raw//utils/bazel/third_party_build:zlib.BUILD",
3840
sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1",
3941
strip_prefix = "zlib-1.2.11",
4042
urls = [
@@ -43,7 +45,7 @@ maybe(
4345
],
4446
)
4547

46-
load(":zlib.bzl", "llvm_zlib_from_env")
48+
load("@llvm-raw//utils/bazel:zlib.bzl", "llvm_zlib_from_env")
4749

4850
maybe(
4951
llvm_zlib_from_env,
@@ -54,15 +56,15 @@ maybe(
5456
maybe(
5557
http_archive,
5658
name = "vulkan_headers",
57-
build_file = "//third_party_build:vulkan_headers.BUILD",
59+
build_file = "@llvm-raw//utils/bazel/third_party_build:vulkan_headers.BUILD",
5860
sha256 = "19f491784ef0bc73caff877d11c96a48b946b5a1c805079d9006e3fbaa5c1895",
5961
strip_prefix = "Vulkan-Headers-9bd3f561bcee3f01d22912de10bb07ce4e23d378",
6062
urls = [
6163
"https://github.com/KhronosGroup/Vulkan-Headers/archive/9bd3f561bcee3f01d22912de10bb07ce4e23d378.tar.gz",
6264
],
6365
)
6466

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

6769
maybe(
6870
vulkan_sdk_setup,

utils/bazel/configure.bzl

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"""Helper macros to configure the LLVM overlay project."""
66

77
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
8-
load("@bazel_skylib//lib:paths.bzl", "paths")
98
load(":zlib.bzl", "llvm_zlib_disable", "llvm_zlib_system")
109
load(":terminfo.bzl", "llvm_terminfo_disable", "llvm_terminfo_system")
1110

@@ -33,23 +32,11 @@ DEFAULT_TARGETS = [
3332
]
3433

3534
def _overlay_directories(repository_ctx):
36-
src_workspace_path = str(repository_ctx.path(
37-
repository_ctx.attr.src_workspace,
38-
).dirname)
39-
40-
src_path = paths.join(src_workspace_path, repository_ctx.attr.src_path)
41-
42-
overlay_workspace_path = str(repository_ctx.path(
43-
repository_ctx.attr.overlay_workspace,
44-
).dirname)
45-
overlay_path = paths.join(
46-
overlay_workspace_path,
47-
repository_ctx.attr.overlay_path,
48-
)
35+
src_path = repository_ctx.path(Label("//:WORKSPACE")).dirname
36+
bazel_path = src_path.get_child("utils").get_child("bazel")
37+
overlay_path = bazel_path.get_child("llvm-project-overlay")
38+
script_path = bazel_path.get_child("overlay_directories.py")
4939

50-
overlay_script = repository_ctx.path(
51-
repository_ctx.attr._overlay_script,
52-
)
5340
python_bin = repository_ctx.which("python3")
5441
if not python_bin:
5542
# Windows typically just defines "python" as python3. The script itself
@@ -61,7 +48,7 @@ def _overlay_directories(repository_ctx):
6148

6249
cmd = [
6350
python_bin,
64-
overlay_script,
51+
script_path,
6552
"--src",
6653
src_path,
6754
"--overlay",
@@ -98,14 +85,6 @@ llvm_configure = repository_rule(
9885
local = True,
9986
configure = True,
10087
attrs = {
101-
"_overlay_script": attr.label(
102-
default = Label("//:overlay_directories.py"),
103-
allow_single_file = True,
104-
),
105-
"overlay_workspace": attr.label(default = Label("//:WORKSPACE")),
106-
"overlay_path": attr.string(default = DEFAULT_OVERLAY_PATH),
107-
"src_workspace": attr.label(default = Label("//:WORKSPACE")),
108-
"src_path": attr.string(mandatory = True),
10988
"targets": attr.string_list(default = DEFAULT_TARGETS),
11089
},
11190
)

utils/bazel/examples/submodule/WORKSPACE

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,16 @@ http_archive(
1717
],
1818
)
1919

20-
# Or wherever your submodule is located.
21-
SUBMODULE_PATH = "third_party/llvm-project"
22-
23-
local_repository(
24-
name = "llvm-bazel",
25-
path = SUBMODULE_PATH + "/utils/bazel",
20+
new_local_repository(
21+
name = "llvm-raw",
22+
build_file_content = "# empty",
23+
# Or wherever your submodule is located.
24+
path = "third_party/llvm-project",
2625
)
2726

28-
load("@llvm-bazel//:configure.bzl", "llvm_configure", "llvm_disable_optional_support_deps")
27+
load("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure", "llvm_disable_optional_support_deps")
2928

30-
llvm_configure(
31-
name = "llvm-project",
32-
src_path = SUBMODULE_PATH,
33-
src_workspace = "@submodule_example//:WORKSPACE",
34-
)
29+
llvm_configure(name = "llvm-project")
3530

3631
# Disables optional dependencies for Support like zlib and terminfo. You may
3732
# instead want to configure them using the macros in the corresponding bzl

utils/bazel/terminfo.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def _llvm_terminfo_disable_impl(repository_ctx):
2727

2828
_terminfo_disable_attrs = {
2929
"_disable_build_template": attr.label(
30-
default = Label("//deps_impl:terminfo_disable.BUILD"),
30+
default = Label("//utils/bazel/deps_impl:terminfo_disable.BUILD"),
3131
allow_single_file = True,
3232
),
3333
}
@@ -147,11 +147,11 @@ def _merge_attrs(attrs_list):
147147

148148
_terminfo_system_attrs = _merge_attrs([_terminfo_disable_attrs, {
149149
"_system_build_template": attr.label(
150-
default = Label("//deps_impl:terminfo_system.BUILD"),
150+
default = Label("//utils/bazel/deps_impl:terminfo_system.BUILD"),
151151
allow_single_file = True,
152152
),
153153
"_terminfo_test_source": attr.label(
154-
default = Label("//deps_impl:terminfo_test.c"),
154+
default = Label("//utils/bazel/deps_impl:terminfo_test.c"),
155155
allow_single_file = True,
156156
),
157157
"candidate_system_linkopts": attr.string_list(

utils/bazel/zlib.bzl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ llvm_zlib_external = repository_rule(
3333
implementation = _llvm_zlib_external_impl,
3434
attrs = {
3535
"_external_build_template": attr.label(
36-
default = Label("//deps_impl:zlib_external.BUILD"),
36+
default = Label("//utils/bazel/deps_impl:zlib_external.BUILD"),
3737
allow_single_file = True,
3838
),
3939
"external_zlib": attr.string(
@@ -56,7 +56,7 @@ llvm_zlib_system = repository_rule(
5656
implementation = _llvm_zlib_system_impl,
5757
attrs = {
5858
"_system_build_template": attr.label(
59-
default = Label("//deps_impl:zlib_system.BUILD"),
59+
default = Label("//utils/bazel/deps_impl:zlib_system.BUILD"),
6060
allow_single_file = True,
6161
),
6262
},
@@ -73,7 +73,7 @@ llvm_zlib_disable = repository_rule(
7373
implementation = _llvm_zlib_disable_impl,
7474
attrs = {
7575
"_disable_build_template": attr.label(
76-
default = Label("//deps_impl:zlib_disable.BUILD"),
76+
default = Label("//utils/bazel/deps_impl:zlib_disable.BUILD"),
7777
allow_single_file = True,
7878
),
7979
},
@@ -92,15 +92,15 @@ llvm_zlib_from_env = repository_rule(
9292
implementation = _llvm_zlib_from_env_impl,
9393
attrs = {
9494
"_disable_build_template": attr.label(
95-
default = Label("//deps_impl:zlib_disable.BUILD"),
95+
default = Label("//utils/bazel/deps_impl:zlib_disable.BUILD"),
9696
allow_single_file = True,
9797
),
9898
"_external_build_template": attr.label(
99-
default = Label("//deps_impl:zlib_external.BUILD"),
99+
default = Label("//utils/bazel/deps_impl:zlib_external.BUILD"),
100100
allow_single_file = True,
101101
),
102102
"_system_build_template": attr.label(
103-
default = Label("//deps_impl:zlib_system.BUILD"),
103+
default = Label("//utils/bazel/deps_impl:zlib_system.BUILD"),
104104
allow_single_file = True,
105105
),
106106
"external_zlib": attr.label(

0 commit comments

Comments
 (0)