blob: 033a1e44b73b74a7ea4a0ca43d207aaf47f66fe6 [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
Philipp Wollermann02401d92017-03-17 13:51:14 +000022exports_files(["LICENSE"])
23
Damien Martin-Guillerezd019eea2015-07-24 12:40:48 +000024filegroup(
Ulf Adams3e87c622017-06-13 10:53:13 +020025 name = "srcs",
26 srcs = glob(
27 ["*"],
28 exclude = [
Yun Peng136dae12023-09-08 12:39:10 -070029 "WORKSPACE.bzlmod", # Needs to be filtered.
Ulf Adams3e87c622017-06-13 10:53:13 +020030 "bazel-*", # convenience symlinks
31 "out", # IntelliJ with setup-intellij.sh
32 "output", # output of compile.sh
33 ".*", # mainly .git* files
34 ],
35 ) + [
Yun Peng136dae12023-09-08 12:39:10 -070036 "//:WORKSPACE.bzlmod.filtered",
Ulf Adams3e87c622017-06-13 10:53:13 +020037 "//examples:srcs",
38 "//scripts:srcs",
39 "//site:srcs",
40 "//src:srcs",
fweikert69895ba2022-07-13 04:56:04 -070041 "//src/main/java/com/google/devtools/build/docgen/release:srcs",
Yun Peng3029a7d2023-06-07 07:40:12 -070042 "//src/main/starlark/tests/builtins_bzl:srcs",
43 "//third_party:srcs",
44 "//tools:srcs",
45 ] + glob([".bazelci/*"]) + [
46 ".bazelrc",
47 ".bazelversion",
48 ],
Tony Aiuto881fc802022-05-25 06:30:17 -070049 applicable_licenses = ["@io_bazel//:license"],
Damien Martin-Guillerez0baff0f2017-08-22 17:40:37 +020050 visibility = ["//src/test/shell/bazel:__pkg__"],
Ulf Adams3e87c622017-06-13 10:53:13 +020051)
52
53filegroup(
Damien Martin-Guillerezd019eea2015-07-24 12:40:48 +000054 name = "git",
Andreas Bergmeier062da5c2017-12-01 07:30:35 -080055 srcs = glob(
56 [".git/**"],
Xavier Bonaventura6ad70542022-08-29 06:46:38 -070057 allow_empty = True,
Andreas Bergmeier062da5c2017-12-01 07:30:35 -080058 exclude = [".git/**/*[*"], # gitk creates temp files with []
59 ),
Damien Martin-Guillerezd019eea2015-07-24 12:40:48 +000060)
Lukacs Berki678ba232015-09-03 13:28:55 +000061
62filegroup(
63 name = "dummy",
64 visibility = ["//visibility:public"],
65)
Han-Wen Nienhuys47182322015-10-09 17:56:52 +000066
Damien Martin-Guillerezde54bca2016-02-29 10:49:43 +000067filegroup(
Damien Martin-Guillerez9b889202016-03-03 00:35:13 +000068 name = "workspace-file",
cushonb6646232018-09-07 01:44:10 -070069 srcs = [
70 ":WORKSPACE",
71 ":distdir.bzl",
Tony Aiuto337e7172020-12-09 10:20:14 -080072 ":distdir_deps.bzl",
cushonb6646232018-09-07 01:44:10 -070073 ],
Cal Peyser2152bc12016-04-22 17:08:59 +000074 visibility = [
John Cater214a7ae2017-08-09 17:24:53 +020075 "//src/test/shell/bazel:__subpackages__",
Cal Peyser2152bc12016-04-22 17:08:59 +000076 ],
Damien Martin-Guillerez9b889202016-03-03 00:35:13 +000077)
78
79filegroup(
Yun Penga50635d2016-07-26 13:29:03 +000080 name = "changelog-file",
81 srcs = [":CHANGELOG.md"],
82 visibility = [
John Caterb0308d42017-01-30 17:49:26 +000083 "//scripts/packages:__subpackages__",
Yun Penga50635d2016-07-26 13:29:03 +000084 ],
85)
86
John Cater1e005022020-07-20 07:50:49 -070087genrule(
88 name = "filtered_WORKSPACE",
Yun Peng136dae12023-09-08 12:39:10 -070089 srcs = ["WORKSPACE.bzlmod"],
90 outs = ["WORKSPACE.bzlmod.filtered"],
John Cater1e005022020-07-20 07:50:49 -070091 cmd = "\n".join([
92 "cp $< $@",
93 # Comment out the android repos if they exist.
94 "sed -i.bak -e 's/^android_sdk_repository/# android_sdk_repository/' -e 's/^android_ndk_repository/# android_ndk_repository/' $@",
95 ]),
96)
97
Yannic Bonenbergerd5d39442020-02-04 10:01:52 -080098pkg_tar(
99 name = "bootstrap-jars",
100 srcs = [
Tyler Williamscc49d682023-07-24 05:27:12 -0700101 "@blake3",
Yannic Bonenbergerd5d39442020-02-04 10:01:52 -0800102 "@com_google_protobuf//:protobuf_java",
103 "@com_google_protobuf//:protobuf_java_util",
Yannic Bonenbergerc656e652020-09-17 03:14:25 -0700104 "@com_google_protobuf//:protobuf_javalite",
Alessandro Patti6da80862021-11-11 22:49:37 -0800105 "@zstd-jni//:zstd-jni",
Yannic Bonenbergerd5d39442020-02-04 10:01:52 -0800106 ],
Tony Aiuto99079b32021-04-06 06:41:17 -0700107 package_dir = "derived/jars",
108 strip_prefix = "external",
Yannic Bonenbergerd5d39442020-02-04 10:01:52 -0800109 # Public but bazel-only visibility.
110 visibility = ["//:__subpackages__"],
111)
112
Yun Peng37b3a092020-05-25 06:54:48 -0700113distrib_jar_filegroup(
Yannic Bonenbergerd5d39442020-02-04 10:01:52 -0800114 name = "bootstrap-derived-java-jars",
115 srcs = glob(
116 ["derived/jars/**/*.jar"],
117 allow_empty = True,
118 ),
Yun Peng37b3a092020-05-25 06:54:48 -0700119 enable_distributions = ["debian"],
Yannic Bonenbergerd5d39442020-02-04 10:01:52 -0800120 visibility = ["//:__subpackages__"],
121)
122
Yun Penga50635d2016-07-26 13:29:03 +0000123filegroup(
Jakob Buchgraber6073f1d2017-06-06 11:58:26 -0400124 name = "bootstrap-derived-java-srcs",
Laurent Le Brun6fbfe5c2019-07-05 03:10:52 -0700125 srcs = glob(
126 ["derived/**/*.java"],
127 allow_empty = True,
128 ),
Jakob Buchgraber6073f1d2017-06-06 11:58:26 -0400129 visibility = ["//:__subpackages__"],
130)
131
brandjon708e1ce2020-12-15 14:51:06 -0800132# Additional generated files that are not Java sources (which could otherwise
133# be included in //src:derived_java_sources).
134filegroup(
135 name = "generated_resources",
Tony Aiuto3b2d3102021-01-07 03:40:14 -0800136 srcs = [
137 "//src/main/java/com/google/devtools/build/lib/bazel/rules:builtins_bzl.zip",
aiutobbeb1da2021-01-15 06:50:56 -0800138 "//src/main/java/com/google/devtools/build/lib/bazel/rules:coverage.WORKSPACE",
Googler4ce63be2022-09-08 03:38:54 -0700139 "//src/main/java/com/google/devtools/build/lib/bazel/rules:rules_license.WORKSPACE",
Tony Aiuto3b2d3102021-01-07 03:40:14 -0800140 "//src/main/java/com/google/devtools/build/lib/bazel/rules/cpp:cc_configure.WORKSPACE",
Tony Aiutob15a8b42021-01-08 07:42:57 -0800141 "//src/main/java/com/google/devtools/build/lib/bazel/rules/java:jdk.WORKSPACE",
Tony Aiuto3b2d3102021-01-07 03:40:14 -0800142 ],
brandjon708e1ce2020-12-15 14:51:06 -0800143)
144
Damien Martin-Guillerezde54bca2016-02-29 10:49:43 +0000145pkg_tar(
146 name = "bazel-srcs",
brandjon708e1ce2020-12-15 14:51:06 -0800147 srcs = [
148 ":generated_resources",
149 ":srcs",
150 ],
Tony Aiuto99079b32021-04-06 06:41:17 -0700151 # TODO(aiuto): Replace with pkg_filegroup when that is available.
John Cater2f838922018-11-12 08:19:03 -0800152 remap_paths = {
Yun Peng136dae12023-09-08 12:39:10 -0700153 "WORKSPACE.bzlmod.filtered": "WORKSPACE.bzlmod",
John Cater2f838922018-11-12 08:19:03 -0800154 # Rewrite paths coming from local repositories back into third_party.
Yun Peng136dae12023-09-08 12:39:10 -0700155 "external/googleapis~override": "third_party/googleapis",
156 "external/remoteapis~override": "third_party/remoteapis",
John Cater2f838922018-11-12 08:19:03 -0800157 },
Damien Martin-Guillerezde54bca2016-02-29 10:49:43 +0000158 strip_prefix = ".",
159 # Public but bazel-only visibility.
160 visibility = ["//:__subpackages__"],
161)
Klaus Aehlig4ca79d42016-10-22 07:59:41 +0000162
hlopkoaaf64572019-06-14 02:33:56 -0700163pkg_tar(
164 name = "platforms-srcs",
165 srcs = ["@platforms//:srcs"],
Tony Aiuto99079b32021-04-06 06:41:17 -0700166 strip_prefix = "external",
hlopkoaaf64572019-06-14 02:33:56 -0700167 visibility = ["//:__subpackages__"],
168)
169
Yun Peng30b21302023-06-19 03:28:53 -0700170pkg_tar(
171 name = "rules_java-srcs",
172 srcs = ["@rules_java//:distribution"],
173 strip_prefix = "external",
174 visibility = ["//:__subpackages__"],
175)
176
Yun Peng136dae12023-09-08 12:39:10 -0700177write_file(
178 name = "gen_maven_repo_name",
179 out = "MAVEN_CANONICAL_REPO_NAME",
180 content = [get_canonical_repo_name("@maven")],
181)
182
Yun Peng3d7937e2023-01-10 06:43:02 -0800183# The @maven repository is created by maven_install from rules_jvm_external.
184# `@maven//:srcs` contains all jar files downloaded and BUILD files created by maven_install.
185pkg_tar(
186 name = "maven-srcs",
Yun Peng136dae12023-09-08 12:39:10 -0700187 srcs = ["@maven//:srcs"] + ["MAVEN_CANONICAL_REPO_NAME"],
188 package_dir = "derived/maven",
189 strip_prefix = "external/" + get_canonical_repo_name("@maven"),
Yun Peng3d7937e2023-01-10 06:43:02 -0800190 visibility = ["//:__subpackages__"],
191)
192
Tony Aiuto05c70d92023-06-30 13:11:58 -0700193exports_files(
194 ["maven_install.json"],
195 visibility = ["//tools/compliance:__pkg__"],
196)
197
László Csomor0783b9e2017-08-11 10:28:36 +0200198py_binary(
199 name = "combine_distfiles",
200 srcs = ["combine_distfiles.py"],
201 visibility = ["//visibility:private"],
202 deps = ["//src:create_embedded_tools_lib"],
203)
204
Klaus Aehlig4ca79d42016-10-22 07:59:41 +0000205genrule(
206 name = "bazel-distfile",
207 srcs = [
208 ":bazel-srcs",
Yannic Bonenbergerd5d39442020-02-04 10:01:52 -0800209 ":bootstrap-jars",
Yun Peng3d7937e2023-01-10 06:43:02 -0800210 ":maven-srcs",
Klaus Aehlig4ca79d42016-10-22 07:59:41 +0000211 "//src:derived_java_srcs",
Shahan Yang1a4f7912017-12-19 14:50:53 -0800212 "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec:bootstrap_autocodec.tar",
Yun Peng136dae12023-09-08 12:39:10 -0700213 "@bootstrap_repo_cache//:archives.tar",
Klaus Aehlig4ca79d42016-10-22 07:59:41 +0000214 ],
215 outs = ["bazel-distfile.zip"],
László Csomor0783b9e2017-08-11 10:28:36 +0200216 cmd = "$(location :combine_distfiles) $@ $(SRCS)",
217 tools = [":combine_distfiles"],
Klaus Aehlig279a0612016-11-11 09:51:44 +0000218 # Public but bazel-only visibility.
219 visibility = ["//:__subpackages__"],
Klaus Aehlig4ca79d42016-10-22 07:59:41 +0000220)
Klaus Aehlig52b03d12016-11-24 15:16:01 +0000221
222genrule(
223 name = "bazel-distfile-tar",
224 srcs = [
225 ":bazel-srcs",
Yannic Bonenbergerd5d39442020-02-04 10:01:52 -0800226 ":bootstrap-jars",
hlopkoaaf64572019-06-14 02:33:56 -0700227 ":platforms-srcs",
Yun Peng30b21302023-06-19 03:28:53 -0700228 ":rules_java-srcs",
Yun Peng3d7937e2023-01-10 06:43:02 -0800229 ":maven-srcs",
Klaus Aehlig52b03d12016-11-24 15:16:01 +0000230 "//src:derived_java_srcs",
Shahan Yang1a4f7912017-12-19 14:50:53 -0800231 "//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec:bootstrap_autocodec.tar",
Yun Peng136dae12023-09-08 12:39:10 -0700232 "@bootstrap_repo_cache//:archives.tar",
Klaus Aehlig52b03d12016-11-24 15:16:01 +0000233 ],
234 outs = ["bazel-distfile.tar"],
László Csomor0783b9e2017-08-11 10:28:36 +0200235 cmd = "$(location :combine_distfiles_to_tar.sh) $@ $(SRCS)",
236 tools = ["combine_distfiles_to_tar.sh"],
Klaus Aehlig52b03d12016-11-24 15:16:01 +0000237 # Public but bazel-only visibility.
238 visibility = ["//:__subpackages__"],
239)
Googlercc858622017-07-25 21:03:05 +0200240
Jakob Buchgraber593c5302019-04-16 10:12:20 -0700241constraint_setting(name = "machine_size")
242
243# A machine with "high cpu count".
244constraint_value(
245 name = "highcpu_machine",
246 constraint_setting = ":machine_size",
247 visibility = ["//visibility:public"],
248)
249
philwo3a3a37a2019-02-05 07:33:47 -0800250platform(
Jakob Buchgraber593c5302019-04-16 10:12:20 -0700251 name = "default_host_platform",
252 constraint_values = [
253 ":highcpu_machine",
254 ],
John Cater1c0a9a32020-01-14 05:50:06 -0800255 parents = ["@local_config_platform//:host"],
Jakob Buchgraber593c5302019-04-16 10:12:20 -0700256)
257
Googler138f06f2023-08-10 01:53:06 -0700258platform(
259 name = "windows_arm64",
260 constraint_values = [
261 "@platforms//os:windows",
262 "@platforms//cpu:arm64",
263 ],
264)
265
philwoc406da02021-10-21 09:22:35 -0700266REMOTE_PLATFORMS = ("rbe_ubuntu1804_java11",)
Jakob Buchgraber60df9052019-07-11 06:08:00 -0700267
268[
269 platform(
270 name = platform_name + "_platform",
Chi Wang26b94ff2021-09-28 23:42:26 -0700271 exec_properties = {
272 "dockerNetwork": "standard",
273 "dockerPrivileged": "true",
Tiago Quelhas0b914c62022-05-06 08:02:37 -0700274 "Pool": "default",
Chi Wang26b94ff2021-09-28 23:42:26 -0700275 },
Jakob Buchgraber60df9052019-07-11 06:08:00 -0700276 parents = ["@" + platform_name + "//config:platform"],
Jakob Buchgraber60df9052019-07-11 06:08:00 -0700277 )
278 for platform_name in REMOTE_PLATFORMS
279]
280
281[
282 # The highcpu RBE platform where heavy actions run on. In order to
283 # use this platform add the highcpu_machine constraint to your target.
284 platform(
285 name = platform_name + "_highcpu_platform",
286 constraint_values = [
287 "//:highcpu_machine",
288 ],
Chi Wang26b94ff2021-09-28 23:42:26 -0700289 exec_properties = {
Tiago Quelhas0b914c62022-05-06 08:02:37 -0700290 "Pool": "highcpu",
Chi Wang26b94ff2021-09-28 23:42:26 -0700291 },
Jakob Buchgraber60df9052019-07-11 06:08:00 -0700292 parents = ["//:" + platform_name + "_platform"],
Jakob Buchgraber60df9052019-07-11 06:08:00 -0700293 )
294 for platform_name in REMOTE_PLATFORMS
295]