blob: e333013714d43560bf09fc79bfc7a0663a711e97 [file] [log] [blame]
Ivo List504a5b72020-12-03 04:00:13 -08001load(
Ivo List37330652020-12-09 09:39:02 -08002 "@bazel_tools//tools/jdk:default_java_toolchain.bzl",
Ivo List504a5b72020-12-03 04:00:13 -08003 "DEFAULT_TOOLCHAIN_CONFIGURATION",
4 "JVM8_TOOLCHAIN_CONFIGURATION",
5 "PREBUILT_TOOLCHAIN_CONFIGURATION",
6 "VANILLA_TOOLCHAIN_CONFIGURATION",
7 "bootclasspath",
8 "default_java_toolchain",
9 "java_runtime_files",
10)
11load(
12 "//tools/jdk:java_toolchain_alias.bzl",
13 "java_host_runtime_alias",
14 "java_runtime_alias",
ilistd14fcf42020-12-14 05:15:06 -080015 "java_runtime_version_alias",
Ivo List504a5b72020-12-03 04:00:13 -080016 "java_toolchain_alias",
Ivo List504a5b72020-12-03 04:00:13 -080017)
Ivo List504a5b72020-12-03 04:00:13 -080018load("//tools/python:private/defs.bzl", "py_binary", "py_test")
19
20package(default_visibility = ["//visibility:public"])
21
22# Used to distinguish toolchains used for Java development, ie the JavaToolchainProvider.
23toolchain_type(name = "toolchain_type")
24
25# Used to distinguish toolchains used for Java execution, ie the JavaRuntimeInfo.
26toolchain_type(name = "runtime_toolchain_type")
27
Ivo List504a5b72020-12-03 04:00:13 -080028# Points to toolchain[":runtime_toolchain_type"] (was :legacy_current_java_runtime)
29java_runtime_alias(name = "current_java_runtime")
30
31# Host configuration of ":current_java_runtime"
32java_host_runtime_alias(name = "current_host_java_runtime")
33
34# Points to toolchain[":toolchain_type"] (was :legacy_current_java_toolchain)
35java_toolchain_alias(name = "current_java_toolchain")
36
ilist37bf4d22021-05-31 03:13:14 -070037# Aliases value of --plugins flag as a JavaPluginInfo
38java_plugins_flag_alias(
39 name = "java_plugins_flag_alias",
40)
41
Ivo List504a5b72020-12-03 04:00:13 -080042# This is necessary to get the *host* Java runtime. Depending on
43# //tools/jdk:current_java_runtime from an attribute with the host transition
44# does not work because the dependency is determined based on the configuration
45# *before* the transition.
46alias(
47 name = "java_runtime_alias",
48 actual = "//tools/jdk:current_java_runtime",
49)
50
51# These individual jni_* targets are exposed for legacy reasons.
52# Most users should depend on :jni.
53
54java_runtime_files(
55 name = "jni_header",
56 srcs = ["include/jni.h"],
57)
58
59java_runtime_files(
60 name = "jni_md_header-darwin",
61 srcs = ["include/darwin/jni_md.h"],
62)
63
64java_runtime_files(
65 name = "jni_md_header-linux",
66 srcs = ["include/linux/jni_md.h"],
67)
68
69java_runtime_files(
70 name = "jni_md_header-windows",
71 srcs = ["include/win32/jni_md.h"],
72)
73
74java_runtime_files(
75 name = "jni_md_header-freebsd",
76 srcs = ["include/freebsd/jni_md.h"],
77)
78
79java_runtime_files(
80 name = "jni_md_header-openbsd",
81 srcs = ["include/openbsd/jni_md.h"],
82)
83
84# The Java native interface. Depend on this package if you #include <jni.h>.
85#
86# See test_jni in third_party/bazel/src/test/shell/bazel/bazel_java_test.sh for
87# an example of using Bazel to build a Java program that calls a C function.
88#
89# TODO(ilist): use //src:condition:linux when released in Bazel
90cc_library(
91 name = "jni",
92 hdrs = [":jni_header"] + select({
93 "//src/conditions:linux_aarch64": [":jni_md_header-linux"],
94 "//src/conditions:linux_ppc64le": [":jni_md_header-linux"],
95 "//src/conditions:linux_s390x": [":jni_md_header-linux"],
Yun Peng1c29dff2021-03-01 01:28:01 -080096 "//src/conditions:linux_mips64": [":jni_md_header-linux"],
97 "//src/conditions:linux_riscv64": [":jni_md_header-linux"],
Ivo List504a5b72020-12-03 04:00:13 -080098 "//src/conditions:linux_x86_64": [":jni_md_header-linux"],
99 "//src/conditions:darwin": [":jni_md_header-darwin"],
100 "//src/conditions:freebsd": [":jni_md_header-freebsd"],
101 "//src/conditions:openbsd": [":jni_md_header-openbsd"],
102 "//src/conditions:windows": [":jni_md_header-windows"],
103 "//conditions:default": [],
104 }),
105 includes = ["include"] + select({
106 "//src/conditions:linux_aarch64": ["include/linux"],
107 "//src/conditions:linux_ppc64le": ["include/linux"],
108 "//src/conditions:linux_s390x": ["include/linux"],
Ast-x64b34be092022-02-15 02:37:10 -0800109 "//src/conditions:linux_mips64": ["include/linux"],
110 "//src/conditions:linux_riscv64": ["include/linux"],
Ivo List504a5b72020-12-03 04:00:13 -0800111 "//src/conditions:linux_x86_64": ["include/linux"],
112 "//src/conditions:darwin": ["include/darwin"],
113 "//src/conditions:freebsd": ["include/freebsd"],
114 "//src/conditions:openbsd": ["include/openbsd"],
115 "//src/conditions:windows": ["include/win32"],
116 "//conditions:default": [],
117 }),
118)
119
120alias(
121 name = "java",
122 actual = "@local_jdk//:java",
123)
124
125alias(
126 name = "jar",
127 actual = "@local_jdk//:jar",
128)
129
130alias(
Ivo List504a5b72020-12-03 04:00:13 -0800131 name = "javadoc",
132 actual = "@local_jdk//:javadoc",
133)
134
Ivo List903c2722021-01-20 03:26:15 -0800135[
136 (
137 alias(
138 name = "ijar_prebuilt_binary_%s" % OS,
139 actual = "@remote_java_tools_%s//:ijar_prebuilt_binary" % OS,
140 visibility = ["//visibility:private"],
141 ),
142 alias(
143 name = "prebuilt_singlejar_%s" % OS,
144 actual = "@remote_java_tools_%s//:prebuilt_singlejar" % OS,
145 visibility = ["//visibility:private"],
146 ),
147 )
148 for OS in [
149 "linux",
150 "darwin",
151 "windows",
152 ]
153]
154
Ivo List504a5b72020-12-03 04:00:13 -0800155# On Windows, executables end in ".exe", but the label we reach it through
156# must be platform-independent. Thus, we create a little filegroup that
157# contains the appropriate platform-dependent file.
158alias(
159 name = "ijar",
Ivo Listbba4b342021-01-19 08:31:40 -0800160 actual = ":ijar_prebuilt_binary_or_cc_binary",
Ivo List504a5b72020-12-03 04:00:13 -0800161)
162
163alias(
164 name = "ijar_prebuilt_binary_or_cc_binary",
165 actual = select({
Ivo List903c2722021-01-20 03:26:15 -0800166 "//src/conditions:linux_x86_64": ":ijar_prebuilt_binary_linux",
167 "//src/conditions:darwin": ":ijar_prebuilt_binary_darwin",
168 "//src/conditions:windows": ":ijar_prebuilt_binary_windows",
Ivo List504a5b72020-12-03 04:00:13 -0800169 "//conditions:default": "@remote_java_tools//:ijar_cc_binary",
170 }),
171)
172
173alias(
174 name = "ijar_prebuilt_binary",
175 actual = select({
Ivo List903c2722021-01-20 03:26:15 -0800176 "//src/conditions:linux_x86_64": ":ijar_prebuilt_binary_linux",
177 "//src/conditions:darwin": ":ijar_prebuilt_binary_darwin",
178 "//src/conditions:windows": ":ijar_prebuilt_binary_windows",
Ivo List504a5b72020-12-03 04:00:13 -0800179 }),
180)
181
182# On Windows, Java implementation of singlejar is used. We create a little
183# filegroup that contains the appropriate platform-dependent file.
184# Once https://github.com/bazelbuild/bazel/issues/2241 is fixed (that is,
185# the native singlejar is used on windows), this file group can be reused since
186# on Windows, executables end in ".exe", but the label we reach it through
187# must be platform-independent.
188alias(
189 name = "singlejar",
Ivo Listbba4b342021-01-19 08:31:40 -0800190 actual = ":singlejar_prebuilt_or_cc_binary",
Ivo List504a5b72020-12-03 04:00:13 -0800191)
192
193alias(
194 name = "singlejar_prebuilt_or_cc_binary",
195 actual = select({
Ivo List903c2722021-01-20 03:26:15 -0800196 "//src/conditions:linux_x86_64": ":prebuilt_singlejar_linux",
197 "//src/conditions:darwin": ":prebuilt_singlejar_darwin",
198 "//src/conditions:windows": ":prebuilt_singlejar_windows",
Ivo List504a5b72020-12-03 04:00:13 -0800199 "//conditions:default": "@remote_java_tools//:singlejar_cc_bin",
200 }),
201)
202
203alias(
204 name = "prebuilt_singlejar",
205 actual = select({
Ivo List903c2722021-01-20 03:26:15 -0800206 "//src/conditions:linux_x86_64": ":prebuilt_singlejar_linux",
207 "//src/conditions:darwin": ":prebuilt_singlejar_darwin",
208 "//src/conditions:windows": ":prebuilt_singlejar_windows",
Ivo List504a5b72020-12-03 04:00:13 -0800209 }),
210)
211
Zhongpeng Lindbb6e992022-03-31 10:38:15 -0700212exports_files([
213 "BUILD.java_tools",
214 "jdk.BUILD",
215])
Ivo List504a5b72020-12-03 04:00:13 -0800216
217alias(
218 name = "genclass",
219 actual = "@remote_java_tools//:GenClass",
220)
221
222alias(
223 name = "GenClass_deploy.jar",
224 actual = "@remote_java_tools//:GenClass",
225)
226
227alias(
Ivo List504a5b72020-12-03 04:00:13 -0800228 name = "turbine",
229 actual = "@remote_java_tools//:Turbine",
230)
231
232alias(
233 name = "turbine_deploy.jar",
234 actual = "@remote_java_tools//:Turbine",
235)
236
237alias(
238 name = "turbine_direct",
239 actual = "@remote_java_tools//:TurbineDirect",
240)
241
242alias(
243 name = "turbine_direct_binary_deploy.jar",
244 actual = "@remote_java_tools//:TurbineDirect",
245)
246
247alias(
248 name = "javabuilder",
249 actual = "@remote_java_tools//:JavaBuilder",
250)
251
252alias(
253 name = "JavaBuilder_deploy.jar",
254 actual = "@remote_java_tools//:JavaBuilder",
255)
256
257alias(
258 name = "vanillajavabuilder",
259 actual = "@remote_java_tools//:VanillaJavaBuilder",
260)
261
Ivo List504a5b72020-12-03 04:00:13 -0800262
263alias(
Ivo List504a5b72020-12-03 04:00:13 -0800264 name = "JacocoCoverageRunner",
265 actual = "@remote_java_tools//:jacoco_coverage_runner",
266)
267
268alias(
269 name = "JacocoCoverage",
270 actual = "@remote_java_tools//:jacoco_coverage_runner",
271)
272
273java_import(
274 name = "TestRunner",
275 jars = ["@remote_java_tools//:Runner"],
276)
277
278alias(
279 name = "TestRunner_deploy.jar",
280 actual = "@remote_java_tools//:Runner",
281)
282
283alias(
284 name = "proguard",
285 actual = "@remote_java_tools//:proguard",
286)
287
288BOOTCLASS_JARS = [
289 "rt.jar",
290 "resources.jar",
291 "jsse.jar",
292 "jce.jar",
293 "charsets.jar",
294]
295
296# TODO(cushon): this isn't compatible with JDK 9
297alias(
298 name = "bootclasspath",
299 actual = "@local_jdk//:bootclasspath",
300)
301
302alias(
303 name = "jre",
304 actual = "@local_jdk//:jre",
305)
306
307alias(
308 name = "jdk",
309 actual = "@local_jdk//:jdk",
310)
311
312alias(
313 name = "host_jdk",
314 actual = ":remote_jdk11",
315)
316
317bootclasspath(
318 name = "platformclasspath",
319 src = "DumpPlatformClassPath.java",
320 host_javabase = "current_java_runtime",
321 target_javabase = "current_java_runtime",
322)
323
324default_java_toolchain(
Ivo List504a5b72020-12-03 04:00:13 -0800325 name = "toolchain",
326 configuration = DEFAULT_TOOLCHAIN_CONFIGURATION,
Ivo Listf5b6abc2020-12-16 23:50:56 -0800327 toolchain_definition = False,
Ivo List504a5b72020-12-03 04:00:13 -0800328)
329
330alias(
331 name = "remote_toolchain",
332 actual = ":toolchain",
333)
334
Ivo List504a5b72020-12-03 04:00:13 -0800335RELEASES = (8, 9, 10, 11)
336
337[
338 default_java_toolchain(
339 name = "toolchain_java%d" % release,
340 configuration = DEFAULT_TOOLCHAIN_CONFIGURATION,
341 source_version = "%s" % release,
342 target_version = "%s" % release,
343 )
344 for release in RELEASES
345]
346
347# A toolchain that targets java 14.
348default_java_toolchain(
349 name = "toolchain_jdk_14",
350 configuration = dict(),
ilistd14fcf42020-12-14 05:15:06 -0800351 java_runtime = "@bazel_tools//tools/jdk:remotejdk_14",
Ivo List504a5b72020-12-03 04:00:13 -0800352 source_version = "14",
353 target_version = "14",
354)
355
356# A toolchain that targets java 15.
357default_java_toolchain(
358 name = "toolchain_jdk_15",
359 configuration = dict(),
ilistd14fcf42020-12-14 05:15:06 -0800360 java_runtime = "@bazel_tools//tools/jdk:remotejdk_15",
Ivo List504a5b72020-12-03 04:00:13 -0800361 source_version = "15",
362 target_version = "15",
363)
364
David Ostrovskye2ed2fd2021-04-15 01:17:40 -0700365# A toolchain that targets java 16.
366default_java_toolchain(
367 name = "toolchain_jdk_16",
368 configuration = dict(),
369 java_runtime = "@bazel_tools//tools/jdk:remotejdk_16",
370 source_version = "16",
371 target_version = "16",
372)
373
Liam Miller-Cushoneb7bf8c2021-09-30 07:53:06 -0700374# A toolchain that targets java 17.
375default_java_toolchain(
376 name = "toolchain_jdk_17",
377 configuration = dict(),
378 java_runtime = "@bazel_tools//tools/jdk:remotejdk_17",
379 source_version = "17",
380 target_version = "17",
381)
382
Liam Miller-Cushona7f1c712022-03-29 11:57:55 -0700383# A toolchain that targets java 18.
384default_java_toolchain(
385 name = "toolchain_jdk_18",
386 configuration = dict(),
387 java_runtime = "@bazel_tools//tools/jdk:remotejdk_18",
388 source_version = "18",
389 target_version = "18",
390)
391
Ivo Listec29e282020-12-16 12:30:12 -0800392# Deprecated, do not use.
393# It will be removed after migration to Java toolchain resolution.
394default_java_toolchain(
395 name = "toolchain_hostjdk8",
396 configuration = JVM8_TOOLCHAIN_CONFIGURATION,
397 java_runtime = ":current_host_java_runtime",
398 source_version = "8",
399 target_version = "8",
Ivo Listf5b6abc2020-12-16 23:50:56 -0800400 toolchain_definition = False,
Ivo Listec29e282020-12-16 12:30:12 -0800401)
402
Ivo List504a5b72020-12-03 04:00:13 -0800403default_java_toolchain(
404 name = "prebuilt_toolchain",
405 configuration = PREBUILT_TOOLCHAIN_CONFIGURATION,
Ivo Listf5b6abc2020-12-16 23:50:56 -0800406 toolchain_definition = False,
Ivo List504a5b72020-12-03 04:00:13 -0800407)
408
409filegroup(
410 name = "bzl_srcs",
411 srcs = glob(["*.bzl"]),
412 visibility = ["//tools:__pkg__"],
413)
414
415py_binary(
416 name = "proguard_whitelister",
417 srcs = [
418 "proguard_whitelister.py",
419 ],
420 deps = [
421 "//third_party/py/abseil",
422 ],
423)
424
425py_test(
426 name = "proguard_whitelister_test",
427 srcs = ["proguard_whitelister_test.py"],
428 data = ["proguard_whitelister_test_input.pgcfg"],
429 deps = [
430 ":proguard_whitelister",
431 ],
432)
433
Ivo List903c2722021-01-20 03:26:15 -0800434# Aliases for JDKs, so that they are only downloaded when needed.
435_JDKS = [
436 "remotejdk11_macos",
Yun Pengecddf602021-01-28 03:43:41 -0800437 "remotejdk11_macos_aarch64",
Ivo List903c2722021-01-20 03:26:15 -0800438 "remotejdk11_win",
Niyas Saitb6024252022-02-10 06:59:31 -0800439 "remotejdk11_win_arm64",
Ivo List903c2722021-01-20 03:26:15 -0800440 "remotejdk11_linux_aarch64",
441 "remotejdk11_linux",
442 "remotejdk11_linux_ppc64le",
443 "remotejdk11_linux_s390x",
Liam Miller-Cushone4461d32022-03-30 13:06:59 -0700444] + [
445 "remotejdk%s_%s" % (version, os)
446 for os in ("linux", "macos", "macos_aarch64", "win", "win_arm64")
447 for version in ("17", "18")
Ivo List903c2722021-01-20 03:26:15 -0800448]
449
450[
451 alias(
452 name = JDK,
453 actual = "@%s//:jdk" % JDK,
454 visibility = ["//visibility:private"],
455 )
456 for JDK in _JDKS
457]
458
Ivo List504a5b72020-12-03 04:00:13 -0800459# A JDK 11 for use as a --host_javabase.
ilistd14fcf42020-12-14 05:15:06 -0800460java_runtime_version_alias(
Ivo List504a5b72020-12-03 04:00:13 -0800461 name = "remote_jdk11",
ilistd14fcf42020-12-14 05:15:06 -0800462 runtime_version = "remotejdk_11",
Ivo List504a5b72020-12-03 04:00:13 -0800463 visibility = ["//visibility:public"],
464)
ilistd14fcf42020-12-14 05:15:06 -0800465
466java_runtime_version_alias(
ilistd14fcf42020-12-14 05:15:06 -0800467 name = "remotejdk_15",
468 runtime_version = "remotejdk_15",
ilistd14fcf42020-12-14 05:15:06 -0800469 visibility = ["//visibility:public"],
470)
iliste0f2e252021-01-11 04:54:19 -0800471
472java_runtime_version_alias(
David Ostrovskye2ed2fd2021-04-15 01:17:40 -0700473 name = "remotejdk_16",
474 runtime_version = "remotejdk_16",
David Ostrovskye2ed2fd2021-04-15 01:17:40 -0700475 visibility = ["//visibility:public"],
476)
477
478java_runtime_version_alias(
Liam Miller-Cushoneb7bf8c2021-09-30 07:53:06 -0700479 name = "remotejdk_17",
480 runtime_version = "remotejdk_17",
481 visibility = ["//visibility:public"],
482)
483
484java_runtime_version_alias(
Liam Miller-Cushona7f1c712022-03-29 11:57:55 -0700485 name = "remotejdk_18",
486 runtime_version = "remotejdk_18",
487 visibility = ["//visibility:public"],
488)
489
490java_runtime_version_alias(
iliste0f2e252021-01-11 04:54:19 -0800491 name = "jdk_8",
492 runtime_version = "8",
iliste0f2e252021-01-11 04:54:19 -0800493 visibility = ["//visibility:public"],
494)