forked from bazelbuild/rules_java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBUILD
More file actions
430 lines (379 loc) · 14.9 KB
/
BUILD
File metadata and controls
430 lines (379 loc) · 14.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_setting")
load("@rules_cc//cc:cc_library.bzl", "cc_library")
load(
":bootclasspath.bzl",
"bootclasspath",
"language_version_bootstrap_runtime",
)
load(
":default_java_toolchain.bzl",
"DEFAULT_TOOLCHAIN_CONFIGURATION",
"PREBUILT_TOOLCHAIN_CONFIGURATION",
"default_java_toolchain",
"java_runtime_files",
)
load(
":java_toolchain_alias.bzl",
"java_host_runtime_alias",
"java_runtime_alias",
"java_runtime_version_alias",
"java_toolchain_alias",
)
load(":utf8_environment.bzl", "utf8_environment")
package(
default_applicable_licenses = ["@rules_java//:license"],
default_visibility = ["//visibility:public"],
)
licenses(["notice"])
filegroup(
name = "srcs",
srcs = glob(["**"]),
)
filegroup(
name = "bzl_srcs",
srcs = glob(["*.bzl"]),
)
# If enabled, the bootclasspath for Java compilation will be extracted from a Java runtime matching
# the version specified with `--java_language_version` rather than the runtime specified with
# `--java_runtime_version`.
bool_flag(
name = "incompatible_language_version_bootclasspath",
build_setting_default = False,
visibility = ["//visibility:private"],
)
# A single binary distribution of a JDK (e.g., OpenJDK 17 for Windows arm64) provides three
# different types of toolchains from the perspective of Bazel:
# The compilation toolchain, which provides the Java runtime used to execute the Java compiler, as
# well as various helper tools and settings.
#
# Toolchains of this type typically have constraints on the execution platform so that their Java
# runtime can run the compiler, but not on the target platform as Java compilation outputs are
# platform independent.
#
# Obtain the associated JavaToolchainInfo via:
# ctx.toolchains["@bazel_tools//tools/jdk:toolchain_type"].java
# TODO: migrate away from using @bazel_tools//tools/jdk:toolchain_type ?
# toolchain_type(name = "toolchain_type")
# The Java runtime that executable Java compilation outputs (e.g., java_binary with
# create_executable = True) will run on.
#
# Toolchains of this type typically have constraints on the target platform so that the runtime's
# native 'java' binary can be run there, but not on the execution platform as building an executable
# Java target only requires copying or symlinking the runtime, which can be done on any platform.
#
# Obtain the associated JavaRuntimeInfo via:
# ctx.toolchains["@bazel_tools//tools/jdk:runtime_toolchain_type"].java_runtime
# TODO: migrate away from using @bazel_tools//tools/jdk:runtime_toolchain_type ?
# toolchain_type(name = "runtime_toolchain_type")
# The Java runtime to extract the bootclasspath from that is then used to compile Java sources.
#
# As the bootclasspath is platform independent, toolchains of this type may have no constraints.
# Purely as an optimization to prevent unnecessary fetches of remote runtimes for other
# architectures, toolchains of this type may have constraints on the execution platform that match
# those on the corresponding compilation toolchain.
#
# Toolchains of this type are only consumed internally by the bootclasspath rule and should not be
# accessed from Starlark.
# TODO: migrate away from using @bazel_tools//tools/jdk:bootstrap_runtime_toolchain_type ?
# toolchain_type(name = "bootstrap_runtime_toolchain_type")
# Points to toolchain[":runtime_toolchain_type"] (was :legacy_current_java_runtime)
java_runtime_alias(name = "current_java_runtime")
# Host configuration of ":current_java_runtime"
java_host_runtime_alias(name = "current_host_java_runtime")
# Points to toolchain[":toolchain_type"] (was :legacy_current_java_toolchain)
java_toolchain_alias(name = "current_java_toolchain")
# These individual jni_* targets are exposed for legacy reasons.
# Most users should depend on :jni.
java_runtime_files(
name = "jni_header",
srcs = ["include/jni.h"],
)
java_runtime_files(
name = "jni_md_header-darwin",
srcs = ["include/darwin/jni_md.h"],
)
java_runtime_files(
name = "jni_md_header-linux",
srcs = ["include/linux/jni_md.h"],
)
java_runtime_files(
name = "jni_md_header-windows",
srcs = ["include/win32/jni_md.h"],
)
java_runtime_files(
name = "jni_md_header-freebsd",
srcs = ["include/freebsd/jni_md.h"],
)
java_runtime_files(
name = "jni_md_header-openbsd",
srcs = ["include/openbsd/jni_md.h"],
)
# The Java native interface. Depend on this package if you #include <jni.h>.
#
# See test_jni in third_party/bazel/src/test/shell/bazel/bazel_java_test.sh for
# an example of using Bazel to build a Java program that calls a C function.
#
# TODO(ilist): use //src:condition:linux when released in Bazel
cc_library(
name = "jni",
hdrs = [":jni_header"] + select({
"@bazel_tools//src/conditions:darwin": [":jni_md_header-darwin"],
"@bazel_tools//src/conditions:freebsd": [":jni_md_header-freebsd"],
"@bazel_tools//src/conditions:linux_aarch64": [":jni_md_header-linux"],
"@bazel_tools//src/conditions:linux_mips64": [":jni_md_header-linux"],
"@bazel_tools//src/conditions:linux_ppc64le": [":jni_md_header-linux"],
"@bazel_tools//src/conditions:linux_riscv64": [":jni_md_header-linux"],
"@bazel_tools//src/conditions:linux_s390x": [":jni_md_header-linux"],
"@bazel_tools//src/conditions:linux_x86_64": [":jni_md_header-linux"],
"@bazel_tools//src/conditions:openbsd": [":jni_md_header-openbsd"],
"@bazel_tools//src/conditions:windows": [":jni_md_header-windows"],
"//conditions:default": [],
}),
includes = ["include"] + select({
"@bazel_tools//src/conditions:darwin": ["include/darwin"],
"@bazel_tools//src/conditions:freebsd": ["include/freebsd"],
"@bazel_tools//src/conditions:linux_aarch64": ["include/linux"],
"@bazel_tools//src/conditions:linux_mips64": ["include/linux"],
"@bazel_tools//src/conditions:linux_ppc64le": ["include/linux"],
"@bazel_tools//src/conditions:linux_riscv64": ["include/linux"],
"@bazel_tools//src/conditions:linux_s390x": ["include/linux"],
"@bazel_tools//src/conditions:linux_x86_64": ["include/linux"],
"@bazel_tools//src/conditions:openbsd": ["include/openbsd"],
"@bazel_tools//src/conditions:windows": ["include/win32"],
"//conditions:default": [],
}),
tags = ["nobuilder"],
)
[
(
alias(
name = "ijar_prebuilt_binary_%s" % OS,
actual = "@remote_java_tools_%s//:ijar_prebuilt_binary" % OS,
visibility = ["//visibility:private"],
),
alias(
name = "prebuilt_singlejar_%s" % OS,
actual = "@remote_java_tools_%s//:prebuilt_singlejar" % OS,
visibility = ["//visibility:private"],
),
alias(
name = "prebuilt_one_version_%s" % OS,
actual = "@remote_java_tools_%s//:prebuilt_one_version" % OS,
visibility = ["//visibility:private"],
),
alias(
name = "turbine_direct_graal_%s" % OS,
actual = "@remote_java_tools_%s//:turbine_direct_graal" % OS,
),
)
for OS in [
"linux",
"linux_aarch64",
"darwin_x86_64",
"darwin_arm64",
"windows",
]
]
alias(
name = "ijar",
actual = ":ijar_prebuilt_binary_or_cc_binary",
)
alias(
name = "ijar_prebuilt_binary_or_cc_binary",
actual = select({
"@bazel_tools//src/conditions:darwin_arm64": ":ijar_prebuilt_binary_darwin_arm64",
"@bazel_tools//src/conditions:darwin_x86_64": ":ijar_prebuilt_binary_darwin_x86_64",
"@bazel_tools//src/conditions:linux_x86_64": ":ijar_prebuilt_binary_linux",
"@bazel_tools//src/conditions:linux_aarch64": ":ijar_prebuilt_binary_linux_aarch64",
"@bazel_tools//src/conditions:windows": ":ijar_prebuilt_binary_windows",
"//conditions:default": "@remote_java_tools//:ijar_cc_binary",
}),
)
alias(
name = "ijar_prebuilt_binary",
actual = select({
"@bazel_tools//src/conditions:darwin_arm64": ":ijar_prebuilt_binary_darwin_arm64",
"@bazel_tools//src/conditions:darwin_x86_64": ":ijar_prebuilt_binary_darwin_x86_64",
"@bazel_tools//src/conditions:linux_x86_64": ":ijar_prebuilt_binary_linux",
"@bazel_tools//src/conditions:linux_aarch64": "ijar_prebuilt_binary_linux_aarch64",
"@bazel_tools//src/conditions:windows": ":ijar_prebuilt_binary_windows",
}),
)
alias(
name = "singlejar",
actual = ":singlejar_prebuilt_or_cc_binary",
)
alias(
name = "singlejar_prebuilt_or_cc_binary",
actual = select({
"@bazel_tools//src/conditions:darwin_arm64": ":prebuilt_singlejar_darwin_arm64",
"@bazel_tools//src/conditions:darwin_x86_64": ":prebuilt_singlejar_darwin_x86_64",
"@bazel_tools//src/conditions:linux_x86_64": ":prebuilt_singlejar_linux",
"@bazel_tools//src/conditions:linux_aarch64": ":prebuilt_singlejar_linux_aarch64",
"@bazel_tools//src/conditions:windows": ":prebuilt_singlejar_windows",
"//conditions:default": "@remote_java_tools//:singlejar_cc_bin",
}),
)
alias(
name = "prebuilt_singlejar",
actual = select({
"@bazel_tools//src/conditions:darwin_arm64": ":prebuilt_singlejar_darwin_arm64",
"@bazel_tools//src/conditions:darwin_x86_64": ":prebuilt_singlejar_darwin_x86_64",
"@bazel_tools//src/conditions:linux_x86_64": ":prebuilt_singlejar_linux",
"@bazel_tools//src/conditions:linux_aarch64": ":prebuilt_singlejar_linux_aarch64",
"@bazel_tools//src/conditions:windows": ":prebuilt_singlejar_windows",
}),
)
alias(
name = "one_version",
actual = ":one_version_prebuilt_or_cc_binary",
)
alias(
name = "one_version_prebuilt_or_cc_binary",
actual = select({
"@bazel_tools//src/conditions:darwin_arm64": ":prebuilt_one_version_darwin_arm64",
"@bazel_tools//src/conditions:darwin_x86_64": ":prebuilt_one_version_darwin_x86_64",
"@bazel_tools//src/conditions:linux_x86_64": ":prebuilt_one_version_linux",
"@bazel_tools//src/conditions:linux_aarch64": ":prebuilt_one_version_linux_aarch64",
"@bazel_tools//src/conditions:windows": ":prebuilt_one_version_windows",
"//conditions:default": "@remote_java_tools//:one_version_cc_bin",
}),
)
alias(
name = "prebuilt_one_version",
actual = select({
"@bazel_tools//src/conditions:darwin_arm64": ":prebuilt_one_version_darwin_arm64",
"@bazel_tools//src/conditions:darwin_x86_64": ":prebuilt_one_version_darwin_x86_64",
"@bazel_tools//src/conditions:linux_x86_64": ":prebuilt_one_version_linux",
"@bazel_tools//src/conditions:linux_aarch64": ":prebuilt_one_version_linux_aarch64",
"@bazel_tools//src/conditions:windows": ":prebuilt_one_version_windows",
}),
)
alias(
name = "turbine_direct",
actual = ":turbine_direct_graal_or_java",
)
alias(
name = "turbine_direct_graal_or_java",
actual = select({
"@bazel_tools//src/conditions:darwin_arm64": ":turbine_direct_graal_darwin_arm64",
"@bazel_tools//src/conditions:darwin_x86_64": ":turbine_direct_graal_darwin_x86_64",
"@bazel_tools//src/conditions:linux_x86_64": ":turbine_direct_graal_linux",
"@bazel_tools//src/conditions:linux_aarch64": ":turbine_direct_graal_linux_aarch64",
"@bazel_tools//src/conditions:windows": ":turbine_direct_graal_windows",
"//conditions:default": "@remote_java_tools//:TurbineDirect",
}),
)
alias(
name = "turbine_direct_graal",
actual = select({
"@bazel_tools//src/conditions:darwin_arm64": ":turbine_direct_graal_darwin_arm64",
"@bazel_tools//src/conditions:darwin_x86_64": ":turbine_direct_graal_darwin_x86_64",
"@bazel_tools//src/conditions:linux_x86_64": ":turbine_direct_graal_linux",
"@bazel_tools//src/conditions:linux_aarch64": ":turbine_direct_graal_linux_aarch64",
"@bazel_tools//src/conditions:windows": ":turbine_direct_graal_windows",
}),
)
string_setting(
name = "java_language_version",
build_setting_default = "",
visibility = ["//visibility:private"],
)
string_setting(
name = "java_runtime_version",
build_setting_default = "",
visibility = ["//visibility:private"],
)
language_version_bootstrap_runtime(
name = "language_version_bootstrap_runtime",
java_language_version = ":java_language_version",
java_runtime_version = ":java_runtime_version",
visibility = ["//visibility:private"],
)
utf8_environment(
name = "utf8_environment",
visibility = ["//visibility:private"],
)
config_setting(
name = "incompatible_language_version_bootclasspath_enabled",
flag_values = {
":incompatible_language_version_bootclasspath": "True",
},
visibility = ["//visibility:private"],
)
bootclasspath(
name = "platformclasspath",
src = "DumpPlatformClassPath.java",
java_runtime_alias = ":current_java_runtime",
language_version_bootstrap_runtime = select({
":incompatible_language_version_bootclasspath_enabled": ":language_version_bootstrap_runtime",
"//conditions:default": None,
}),
)
bootclasspath(
name = "platformclasspath_nostrip",
src = "DumpPlatformClassPath.java",
java_runtime_alias = ":current_java_runtime",
language_version_bootstrap_runtime = select({
":incompatible_language_version_bootclasspath_enabled": ":language_version_bootstrap_runtime",
"//conditions:default": None,
}),
strip = False,
)
default_java_toolchain(
name = "toolchain",
configuration = DEFAULT_TOOLCHAIN_CONFIGURATION,
toolchain_definition = False,
)
alias(
name = "remote_toolchain",
actual = ":toolchain",
)
RELEASES = (8, 9, 10, 11, 17, 21, 25)
[
default_java_toolchain(
name = ("toolchain_java%d" if release <= 11 else "toolchain_jdk_%d") % release,
configuration = DEFAULT_TOOLCHAIN_CONFIGURATION | {"java_runtime": ":remotejdk_25"},
source_version = "%s" % release,
target_version = "%s" % release,
)
for release in RELEASES
]
default_java_toolchain(
name = "prebuilt_toolchain",
configuration = PREBUILT_TOOLCHAIN_CONFIGURATION,
toolchain_definition = False,
)
# A JDK 11 for use as a --host_javabase.
java_runtime_version_alias(
name = "remote_jdk11",
runtime_version = "remotejdk_11",
visibility = ["//visibility:public"],
)
java_runtime_version_alias(
name = "remotejdk_17",
runtime_version = "remotejdk_17",
visibility = ["//visibility:public"],
)
java_runtime_version_alias(
name = "remotejdk_21",
runtime_version = "remotejdk_21",
visibility = ["//visibility:public"],
)
java_runtime_version_alias(
name = "remotejdk_25",
runtime_version = "remotejdk_25",
visibility = ["//visibility:public"],
)
java_runtime_version_alias(
name = "jdk_8",
runtime_version = "8",
visibility = ["//visibility:public"],
)
bzl_library(
name = "toolchain_utils",
srcs = ["toolchain_utils.bzl"],
visibility = ["//visibility:public"],
deps = ["//java/common"],
)