Skip to content

Commit 9cc1ddd

Browse files
committedJun 30, 2021
[Bazel] Update README with examples
Reviewed By: chandlerc Differential Revision: https://reviews.llvm.org/D105245
1 parent 627733b commit 9cc1ddd

File tree

4 files changed

+77
-54
lines changed

4 files changed

+77
-54
lines changed
 

‎utils/bazel/.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Bazel artifacts
2-
/bazel-*
2+
**/bazel-*
33

44
# Per-user bazelrc files
55
user.bazelrc

‎utils/bazel/README.md

+2-53
Original file line numberDiff line numberDiff line change
@@ -75,56 +75,5 @@ configuration you'd like to use that isn't supported, please send a patch.
7575

7676
# Usage
7777

78-
To use in dependent projects using Bazel, you can import LLVM (e.g. as a
79-
submodule or using `http_archive`) and then use the provided configuration rule.
80-
81-
FIXME: This needs to be updated to a commit that exists once such a commit
82-
exists.
83-
FIXME: It shouldn't be necessary to configure `http_archive` twice for the same
84-
archive (though caching means this isn't too expensive).
85-
86-
```starlark
87-
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
88-
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
89-
90-
LLVM_COMMIT = "0a1f0ee78122fc0642e8a1a18e1b2bc89c813387"
91-
92-
LLVM_SHA256 = "4f59737ccfdad2cfb4587d796ce97c1eb5433de7ea0f57f248554b83e92d81d2"
93-
94-
http_archive(
95-
name = "llvm-project-raw",
96-
build_file_content = "#empty",
97-
sha256 = LLVM_SHA256,
98-
strip_prefix = "llvm-project-" + LLVM_COMMIT,
99-
urls = ["https://github.com/llvm/llvm-project/archive/{commit}.tar.gz".format(commit = LLVM_COMMIT)],
100-
)
101-
102-
http_archive(
103-
name = "llvm-bazel",
104-
sha256 = LLVM_SHA256,
105-
strip_prefix = "llvm-project-{}/utils/bazel".format(LLVM_COMMIT),
106-
urls = ["https://github.com/llvm/llvm-project/archive/{commit}.tar.gz".format(commit = LLVM_COMMIT)],
107-
)
108-
109-
load("@llvm-bazel//:configure.bzl", "llvm_configure")
110-
111-
llvm_configure(
112-
name = "llvm-project",
113-
src_path = ".",
114-
src_workspace = "@llvm-project-raw//:WORKSPACE",
115-
)
116-
117-
load("@llvm-bazel//:terminfo.bzl", "llvm_terminfo_system")
118-
119-
maybe(
120-
llvm_terminfo_system,
121-
name = "llvm_terminfo",
122-
)
123-
124-
load("@llvm-bazel//:zlib.bzl", "llvm_zlib_system")
125-
126-
maybe(
127-
llvm_zlib_system,
128-
name = "llvm_zlib",
129-
)
130-
```
78+
To use in dependent projects using Bazel, you can import LLVM and then use the
79+
provided configuration rule. See example usage in the `examples/` directory.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
2+
# See https://llvm.org/LICENSE.txt for license information.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
"""An example WORKSPACE for configuring LLVM using http_archive."""
6+
7+
workspace(name = "http_archive_example")
8+
9+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
10+
11+
# Replace with the LLVM commit you want to use.
12+
LLVM_COMMIT = "09ac97ce350316b95b8cddb796d52f71b6f68296"
13+
14+
# The easiest way to calculate this for a new commit is to set it to empty and
15+
# then run a bazel build and it will report the digest necessary to cache the
16+
# archive and make the build reproducible.
17+
LLVM_SHA256 = "2fb1aa06d12f8db349a27426cb0ced062987c5c2a75143c69f4284929e2750ff"
18+
19+
# FIXME: It shouldn't be necessary to use http_archive twice here. Caching
20+
# should mean that this isn't too expensive though.
21+
22+
http_archive(
23+
name = "llvm-project-raw",
24+
build_file_content = "#empty",
25+
sha256 = LLVM_SHA256,
26+
strip_prefix = "llvm-project-" + LLVM_COMMIT,
27+
urls = ["https://github.com/llvm/llvm-project/archive/{commit}.tar.gz".format(commit = LLVM_COMMIT)],
28+
)
29+
30+
http_archive(
31+
name = "llvm-bazel",
32+
sha256 = LLVM_SHA256,
33+
strip_prefix = "llvm-project-{}/utils/bazel".format(LLVM_COMMIT),
34+
urls = ["https://github.com/llvm/llvm-project/archive/{commit}.tar.gz".format(commit = LLVM_COMMIT)],
35+
)
36+
37+
load("@llvm-bazel//:configure.bzl", "llvm_configure", "llvm_disable_optional_support_deps")
38+
39+
llvm_configure(
40+
name = "llvm-project",
41+
src_path = ".",
42+
src_workspace = "@llvm-project-raw//:WORKSPACE",
43+
)
44+
45+
# Disables optional dependencies for Support like zlib and terminfo. You may
46+
# instead want to configure them using the macros in the corresponding bzl
47+
# files.
48+
llvm_disable_optional_support_deps()
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
2+
# See https://llvm.org/LICENSE.txt for license information.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
"""An example WORKSPACE for configuring LLVM using a git submodule."""
6+
7+
workspace(name = "submodule_example")
8+
9+
# Or wherever your submodule is located.
10+
SUBMODULE_PATH = "third_party/llvm-project"
11+
12+
local_repository(
13+
name = "llvm-bazel",
14+
path = SUBMODULE_PATH + "/utils/bazel",
15+
)
16+
17+
llvm_configure(
18+
name = "llvm-project",
19+
src_path = SUBMODULE_PATH,
20+
src_workspace = "@submodule_example//:WORKSPACE",
21+
)
22+
23+
# Disables optional dependencies for Support like zlib and terminfo. You may
24+
# instead want to configure them using the macros in the corresponding bzl
25+
# files.
26+
llvm_disable_optional_support_deps()

0 commit comments

Comments
 (0)
Please sign in to comment.