blob: 87fac64996f0e9a46dbfccecce52ffeb0c7ae644 [file] [log] [blame]
Ulf Adams3e87c622017-06-13 10:53:13 +02001# Bazel - Google's Build System
2
Yun Peng136dae12023-09-08 12:39:10 -07003load("@bazel_skylib//rules:write_file.bzl", "write_file")
Tony Aiuto881fc802022-05-25 06:30:17 -07004load("@rules_license//rules:license.bzl", "license")
Googler8c41763f72022-07-08 06:09:05 -07005load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
Yun Peng136dae12023-09-08 12:39:10 -07006load("@rules_python//python:defs.bzl", "py_binary")
7load("//src/tools/bzlmod:utils.bzl", "get_canonical_repo_name")
8load("//tools/distributions:distribution_rules.bzl", "distrib_jar_filegroup")
brandjondb063a82019-07-30 21:41:37 -07009
Damien Martin-Guillerezd019eea2015-07-24 12:40:48 +000010package(default_visibility = ["//scripts/release:__pkg__"])
11
Tony Aiuto881fc802022-05-25 06:30:17 -070012license(
13 name = "license",
14 package_name = "bazelbuild/bazel",
15 copyright_notice = "Copyright © 2014 The Bazel Authors. All rights reserved.",
16 license_kinds = [
17 "@rules_license//licenses/spdx:Apache-2.0",
18 ],
19 license_text = "LICENSE",
20)
21
Googler824cf9f2024-09-30 10:30:34 -070022exports_files([
23 "LICENSE",
24 "MODULE.bazel.lock",
25])
Philipp Wollermann02401d92017-03-17 13:51:14 +000026
Damien Martin-Guillerezd019eea2015-07-24 12:40:48 +000027filegroup(
Ulf Adams3e87c622017-06-13 10:53:13 +020028 name = "srcs",
29 srcs = glob(
30 ["*"],
31 exclude = [
Xdng Yngfb84c012024-02-13 13:39:23 -080032 "MODULE.bazel.lock", # Use MODULE.bazel.lock.dist instead
Yun Peng136dae12023-09-08 12:39:10 -070033 "WORKSPACE.bzlmod", # Needs to be filtered.
Ulf Adams3e87c622017-06-13 10:53:13 +020034 "bazel-*", # convenience symlinks
35 "out", # IntelliJ with setup-intellij.sh
36 "output", # output of compile.sh
37 ".*", # mainly .git* files
38 ],
39 ) + [
Xdng Yngfb84c012024-02-13 13:39:23 -080040 "//:MODULE.bazel.lock.dist",
Yun Peng136dae12023-09-08 12:39:10 -070041 "//:WORKSPACE.bzlmod.filtered",
Ulf Adams3e87c622017-06-13 10:53:13 +020042 "//examples:srcs",
43 "//scripts:srcs",
44 "//site:srcs",
45 "//src:srcs",
fweikert69895ba2022-07-13 04:56:04 -070046 "//src/main/java/com/google/devtools/build/docgen/release:srcs",
Yun Peng3029a7d2023-06-07 07:40:12 -070047 "//src/main/starlark/tests/builtins_bzl:srcs",
48 "//third_party:srcs",
49 "//tools:srcs",
50 ] + glob([".bazelci/*"]) + [
51 ".bazelrc",
52 ".bazelversion",
53 ],
Tony Aiuto881fc802022-05-25 06:30:17 -070054 applicable_licenses = ["@io_bazel//:license"],
Damien Martin-Guillerez0baff0f2017-08-22 17:40:37 +020055 visibility = ["//src/test/shell/bazel:__pkg__"],
Ulf Adams3e87c622017-06-13 10:53:13 +020056)
57
58filegroup(
Lukacs Berki678ba232015-09-03 13:28:55 +000059 name = "dummy",
60 visibility = ["//visibility:public"],
61)
Han-Wen Nienhuys47182322015-10-09 17:56:52 +000062
Damien Martin-Guillerezde54bca2016-02-29 10:49:43 +000063filegroup(
Tobias Werth70e80a12024-06-06 06:35:21 -070064 name = "workspace-deps-bzl",
cushonb6646232018-09-07 01:44:10 -070065 srcs = [
Yun Pengc1f2aff2023-11-07 09:51:02 -080066 ":workspace_deps.bzl",
cushonb6646232018-09-07 01:44:10 -070067 ],
Cal Peyser2152bc12016-04-22 17:08:59 +000068 visibility = [
John Cater214a7ae2017-08-09 17:24:53 +020069 "//src/test/shell/bazel:__subpackages__",
Cal Peyser2152bc12016-04-22 17:08:59 +000070 ],
Damien Martin-Guillerez9b889202016-03-03 00:35:13 +000071)
72
73filegroup(
Yun Penga50635d2016-07-26 13:29:03 +000074 name = "changelog-file",
75 srcs = [":CHANGELOG.md"],
76 visibility = [
John Caterb0308d42017-01-30 17:49:26 +000077 "//scripts/packages:__subpackages__",
Yun Penga50635d2016-07-26 13:29:03 +000078 ],
79)
80
John Cater1e005022020-07-20 07:50:49 -070081genrule(
82 name = "filtered_WORKSPACE",
Yun Peng136dae12023-09-08 12:39:10 -070083 srcs = ["WORKSPACE.bzlmod"],
84 outs = ["WORKSPACE.bzlmod.filtered"],
John Cater1e005022020-07-20 07:50:49 -070085 cmd = "\n".join([
86 "cp $< $@",
87 # Comment out the android repos if they exist.
Googlercd8a1552024-08-05 14:30:59 -070088 "sed -i.bak -e 's/^android_sdk_repository/# android_sdk_repository/' $@",
John Cater1e005022020-07-20 07:50:49 -070089 ]),
90)
91
Xdng Yngfb84c012024-02-13 13:39:23 -080092genrule(
93 name = "generate_dist_lockfile",
94 srcs = [
95 "MODULE.bazel",
Xdng Yngfb84c012024-02-13 13:39:23 -080096 "//third_party/remoteapis:MODULE.bazel",
Fabian Meumertzheimc4131922024-09-24 12:15:43 -070097 "//third_party:BUILD",
98 "//third_party:rules_jvm_external_6.0.patch",
Xdng Yngc46b9ce2024-10-01 14:21:54 -070099 "//third_party/protobuf:BUILD",
100 "//third_party/protobuf:remove_rules_rust.patch",
Xdng Yngfb84c012024-02-13 13:39:23 -0800101 ],
102 outs = ["MODULE.bazel.lock.dist"],
Googlera3f778c2024-02-14 10:45:30 -0800103 cmd = " && ".join([
104 "ROOT=$$PWD",
105 "TMPDIR=$$(mktemp -d)",
106 "trap 'rm -rf $$TMPDIR' EXIT",
107 "mkdir -p $$TMPDIR/workspace",
108 "touch $$TMPDIR/workspace/BUILD.bazel",
109 "for i in $(SRCS); do dir=$$TMPDIR/workspace/$$(dirname $$i); mkdir -p $$dir; cp $$i $$dir; done",
110 "cd $$TMPDIR/workspace",
111 # Instead of `bazel mod deps`, we run a simpler command like `bazel query :all` here
112 # so that we only trigger module resolution, not extension eval.
113 # Also use `--batch` so that Bazel doesn't keep a server process alive.
Googler702118b2024-02-29 07:31:14 -0800114 "$$ROOT/$(location //src:bazel) --batch --output_user_root=$$TMPDIR/output_user_root query --check_direct_dependencies=error --lockfile_mode=update :all",
Googlera3f778c2024-02-14 10:45:30 -0800115 "mv MODULE.bazel.lock $$ROOT/$@",
116 ]),
Xdng Yngfb84c012024-02-13 13:39:23 -0800117 tags = ["requires-network"],
118 tools = ["//src:bazel"],
119)
120
Yannic Bonenbergerd5d39442020-02-04 10:01:52 -0800121pkg_tar(
122 name = "bootstrap-jars",
123 srcs = [
Xdng Yngc46b9ce2024-10-01 14:21:54 -0700124 "//third_party/googleapis:dist_jars",
125 "//third_party/grpc-java:grpc_jars",
Googler401ed582024-10-02 05:55:37 -0700126 "@protobuf//:protobuf_java",
127 "@protobuf//:protobuf_java_util",
128 "@protobuf//:protobuf_javalite",
Alessandro Patti6da80862021-11-11 22:49:37 -0800129 "@zstd-jni//:zstd-jni",
Yannic Bonenbergerd5d39442020-02-04 10:01:52 -0800130 ],
Tony Aiuto99079b32021-04-06 06:41:17 -0700131 package_dir = "derived/jars",
Googler164500d2024-05-03 01:41:31 -0700132 remap_paths = {
133 "external/": "",
134 "../": "",
135 },
136 strip_prefix = ".",
Yannic Bonenbergerd5d39442020-02-04 10:01:52 -0800137 # Public but bazel-only visibility.
138 visibility = ["//:__subpackages__"],
139)
140
Yun Peng37b3a092020-05-25 06:54:48 -0700141distrib_jar_filegroup(
Yannic Bonenbergerd5d39442020-02-04 10:01:52 -0800142 name = "bootstrap-derived-java-jars",
143 srcs = glob(
144 ["derived/jars/**/*.jar"],
145 allow_empty = True,
146 ),
Yun Peng37b3a092020-05-25 06:54:48 -0700147 enable_distributions = ["debian"],
Yannic Bonenbergerd5d39442020-02-04 10:01:52 -0800148 visibility = ["//:__subpackages__"],
149)
150
Yun Penga50635d2016-07-26 13:29:03 +0000151filegroup(
Jakob Buchgraber6073f1d2017-06-06 11:58:26 -0400152 name = "bootstrap-derived-java-srcs",
Laurent Le Brun6fbfe5c2019-07-05 03:10:52 -0700153 srcs = glob(
154 ["derived/**/*.java"],
155 allow_empty = True,
156 ),
Jakob Buchgraber6073f1d2017-06-06 11:58:26 -0400157 visibility = ["//:__subpackages__"],
158)
159
brandjon708e1ce2020-12-15 14:51:06 -0800160# Additional generated files that are not Java sources (which could otherwise
161# be included in //src:derived_java_sources).
162filegroup(
163 name = "generated_resources",
Tony Aiuto3b2d3102021-01-07 03:40:14 -0800164 srcs = [
165 "//src/main/java/com/google/devtools/build/lib/bazel/rules:builtins_bzl.zip",
aiutobbeb1da2021-01-15 06:50:56 -0800166 "//src/main/java/com/google/devtools/build/lib/bazel/rules:coverage.WORKSPACE",
Yun Peng75066902024-09-27 05:59:50 -0700167 "//src/main/java/com/google/devtools/build/lib/bazel/rules:rules_suffix.WORKSPACE",
Tony Aiuto3b2d3102021-01-07 03:40:14 -0800168 "//src/main/java/com/google/devtools/build/lib/bazel/rules/cpp:cc_configure.WORKSPACE",
169 ],
brandjon708e1ce2020-12-15 14:51:06 -0800170)
171
Damien Martin-Guillerezde54bca2016-02-29 10:49:43 +0000172pkg_tar(
173 name = "bazel-srcs",
brandjon708e1ce2020-12-15 14:51:06 -0800174 srcs = [
175 ":generated_resources",
176 ":srcs",
177 ],
Tony Aiuto99079b32021-04-06 06:41:17 -0700178 # TODO(aiuto): Replace with pkg_filegroup when that is available.
John Cater2f838922018-11-12 08:19:03 -0800179 remap_paths = {
Xdng Yngfb84c012024-02-13 13:39:23 -0800180 "MODULE.bazel.lock.dist": "MODULE.bazel.lock",
Yun Peng136dae12023-09-08 12:39:10 -0700181 "WORKSPACE.bzlmod.filtered": "WORKSPACE.bzlmod",
John Cater2f838922018-11-12 08:19:03 -0800182 },
Damien Martin-Guillerezde54bca2016-02-29 10:49:43 +0000183 strip_prefix = ".",
184 # Public but bazel-only visibility.
185 visibility = ["//:__subpackages__"],
186)
Klaus Aehlig4ca79d42016-10-22 07:59:41 +0000187
hlopkoaaf64572019-06-14 02:33:56 -0700188pkg_tar(
189 name = "platforms-srcs",
190 srcs = ["@platforms//:srcs"],
Googler164500d2024-05-03 01:41:31 -0700191 remap_paths = {
192 "external/": "",
193 "../": "",
194 },
195 strip_prefix = ".",
hlopkoaaf64572019-06-14 02:33:56 -0700196 visibility = ["//:__subpackages__"],
197)
198
Yun Peng136dae12023-09-08 12:39:10 -0700199write_file(
200 name = "gen_maven_repo_name",
201 out = "MAVEN_CANONICAL_REPO_NAME",
Fabian Meumertzheim2758f552024-06-12 03:33:27 -0700202 content = [get_canonical_repo_name("@maven")],
Yun Peng136dae12023-09-08 12:39:10 -0700203)
204
Yun Peng3d7937e2023-01-10 06:43:02 -0800205# The @maven repository is created by maven_install from rules_jvm_external.
206# `@maven//:srcs` contains all jar files downloaded and BUILD files created by maven_install.
207pkg_tar(
208 name = "maven-srcs",
Yun Peng136dae12023-09-08 12:39:10 -0700209 srcs = ["@maven//:srcs"] + ["MAVEN_CANONICAL_REPO_NAME"],
210 package_dir = "derived/maven",
Googler164500d2024-05-03 01:41:31 -0700211 remap_paths = {
Xdng Yng24fcc3e2024-08-29 00:45:43 -0700212 "external/" + get_canonical_repo_name("@maven") + "/": "",
213 "../" + get_canonical_repo_name("@maven") + "/": "",
Googler164500d2024-05-03 01:41:31 -0700214 },
215 strip_prefix = ".",
Yun Peng3d7937e2023-01-10 06:43:02 -0800216 visibility = ["//:__subpackages__"],
217)
218
Tony Aiuto05c70d92023-06-30 13:11:58 -0700219exports_files(
220 ["maven_install.json"],
221 visibility = ["//tools/compliance:__pkg__"],
222)
223
László Csomor0783b9e2017-08-11 10:28:36 +0200224py_binary(
225 name = "combine_distfiles",
226 srcs = ["combine_distfiles.py"],
227 visibility = ["//visibility:private"],
228 deps = ["//src:create_embedded_tools_lib"],
229)
230
Klaus Aehlig4ca79d42016-10-22 07:59:41 +0000231genrule(
232 name = "bazel-distfile",
233 srcs = [
234 ":bazel-srcs",
Yannic Bonenbergerd5d39442020-02-04 10:01:52 -0800235 ":bootstrap-jars",
Yun Peng3d7937e2023-01-10 06:43:02 -0800236 ":maven-srcs",
Klaus Aehlig4ca79d42016-10-22 07:59:41 +0000237 "//src:derived_java_srcs",
Yun Peng136dae12023-09-08 12:39:10 -0700238 "@bootstrap_repo_cache//:archives.tar",
Klaus Aehlig4ca79d42016-10-22 07:59:41 +0000239 ],
240 outs = ["bazel-distfile.zip"],
László Csomor0783b9e2017-08-11 10:28:36 +0200241 cmd = "$(location :combine_distfiles) $@ $(SRCS)",
242 tools = [":combine_distfiles"],
Klaus Aehlig279a0612016-11-11 09:51:44 +0000243 # Public but bazel-only visibility.
244 visibility = ["//:__subpackages__"],
Klaus Aehlig4ca79d42016-10-22 07:59:41 +0000245)
Klaus Aehlig52b03d12016-11-24 15:16:01 +0000246
247genrule(
248 name = "bazel-distfile-tar",
249 srcs = [
250 ":bazel-srcs",
Yannic Bonenbergerd5d39442020-02-04 10:01:52 -0800251 ":bootstrap-jars",
hlopkoaaf64572019-06-14 02:33:56 -0700252 ":platforms-srcs",
Yun Peng3d7937e2023-01-10 06:43:02 -0800253 ":maven-srcs",
Klaus Aehlig52b03d12016-11-24 15:16:01 +0000254 "//src:derived_java_srcs",
Yun Peng136dae12023-09-08 12:39:10 -0700255 "@bootstrap_repo_cache//:archives.tar",
Klaus Aehlig52b03d12016-11-24 15:16:01 +0000256 ],
257 outs = ["bazel-distfile.tar"],
László Csomor0783b9e2017-08-11 10:28:36 +0200258 cmd = "$(location :combine_distfiles_to_tar.sh) $@ $(SRCS)",
259 tools = ["combine_distfiles_to_tar.sh"],
Klaus Aehlig52b03d12016-11-24 15:16:01 +0000260 # Public but bazel-only visibility.
261 visibility = ["//:__subpackages__"],
262)
Googlercc858622017-07-25 21:03:05 +0200263
Jakob Buchgraber593c5302019-04-16 10:12:20 -0700264constraint_setting(name = "machine_size")
265
266# A machine with "high cpu count".
267constraint_value(
268 name = "highcpu_machine",
269 constraint_setting = ":machine_size",
270 visibility = ["//visibility:public"],
271)
272
philwo3a3a37a2019-02-05 07:33:47 -0800273platform(
Jakob Buchgraber593c5302019-04-16 10:12:20 -0700274 name = "default_host_platform",
275 constraint_values = [
276 ":highcpu_machine",
277 ],
Googler74c8ca42024-03-29 12:48:51 -0700278 parents = ["@platforms//host"],
Jakob Buchgraber593c5302019-04-16 10:12:20 -0700279)
280
Googler138f06f2023-08-10 01:53:06 -0700281platform(
282 name = "windows_arm64",
283 constraint_values = [
284 "@platforms//os:windows",
285 "@platforms//cpu:arm64",
286 ],
287)
288
Googler40824e12024-03-11 02:38:48 -0700289REMOTE_PLATFORMS = ("rbe_ubuntu2004",)
Jakob Buchgraber60df9052019-07-11 06:08:00 -0700290
291[
292 platform(
293 name = platform_name + "_platform",
Chi Wang26b94ff2021-09-28 23:42:26 -0700294 exec_properties = {
295 "dockerNetwork": "standard",
296 "dockerPrivileged": "true",
Tiago Quelhas0b914c62022-05-06 08:02:37 -0700297 "Pool": "default",
Chi Wang26b94ff2021-09-28 23:42:26 -0700298 },
Jakob Buchgraber60df9052019-07-11 06:08:00 -0700299 parents = ["@" + platform_name + "//config:platform"],
Jakob Buchgraber60df9052019-07-11 06:08:00 -0700300 )
301 for platform_name in REMOTE_PLATFORMS
302]
303
304[
305 # The highcpu RBE platform where heavy actions run on. In order to
306 # use this platform add the highcpu_machine constraint to your target.
307 platform(
308 name = platform_name + "_highcpu_platform",
309 constraint_values = [
310 "//:highcpu_machine",
311 ],
Chi Wang26b94ff2021-09-28 23:42:26 -0700312 exec_properties = {
Tiago Quelhas0b914c62022-05-06 08:02:37 -0700313 "Pool": "highcpu",
Chi Wang26b94ff2021-09-28 23:42:26 -0700314 },
Jakob Buchgraber60df9052019-07-11 06:08:00 -0700315 parents = ["//:" + platform_name + "_platform"],
Jakob Buchgraber60df9052019-07-11 06:08:00 -0700316 )
317 for platform_name in REMOTE_PLATFORMS
318]