Skip to content

Commit 975866a

Browse files
meteorcloudycopybara-github
authored andcommitted
Respect rules_java as the source of truth for java toolchains
Context: #18373 Currently the definitions of java tools, remote JDKs, and Java toolchains are duplicated in both Bazel sources and rules_java, and they go out of sync quite often. By default, the default toolchains shipped with the Bazel binary uses the one in Bazel sources except when Bzlmod is enabled. bazelbuild/rules_java#110 syncs java toolchain related files from Bazel sources to rules_java and this PR removes most of the definitions in Bazel source and uses rules_java as the source of truth. Significant changes in this PR: - Removed all java tools definitions from distdir_deps.bzl - Removed all remote JDK definitions from distdir_deps.bzl except the ones for to be embedded within Bazel binary. - Changed `jdk.WORKSPACE.tmpl` to load java tools and JDKs from rules_java as WORKSPACE suffix. - Removed the `jdk_http_archives` hack for some shell tests. That dates back to #8361, I don't think it's needed since we have the WORKSPACE suffix by default. - When building Bazel with Bazel, we were using the java toolchains shipped in `@bazel_tools` of the Bazel binary, now we use the java toolchains from the `rules_java` defined in distdir_deps.bzl. This enables us to build Bazel itself with the latest java toolchain, therefore can detect issues earlier. - Removed `_for_testing` suffixes for the shared repo hack for Bazel CI since the java tools and remote JDKs versions we load to build Bazel are the same as the ones shipped in the Bazel binary we built (via `jdk.WORKSPACE.tmpl`) and used in the integration tests. They all come from the rules_java version in distdir_deps.bzl. - Removed the `test_WORKSPACE_files` hack for `workspace_resolved_test.sh`. - Mocked rules_java in some integration tests to avoid needing to download it or its transitive dependencies. Breaking changes: - Loading `.bzl` files under `@bazel_tools//tools/jdk` in WORKSPACE now requires you to define `rules_java` in advance, the `rules_java` definition in WORKSPACE suffix cannot guarantee `@rules_java` exist because it's appended after the content of the user WORKSPACE file. Closes #18423. RELNOTES[INC]: Loading `.bzl` files under `@bazel_tools//tools/jdk` in WORKSPACE now requires `rules_java` to be defined in advance. PiperOrigin-RevId: 536682532 Change-Id: Ia7475bfe134729ab1592b0ef0a31d28eb839b5ac
1 parent 3efaa32 commit 975866a

40 files changed

+312
-2655
lines changed

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ bazel_dep(name = "stardoc", version = "0.5.3", repo_name = "io_bazel_skydoc")
1616
bazel_dep(name = "zstd-jni", version = "1.5.2-3")
1717
bazel_dep(name = "zlib", version = "1.2.13")
1818
bazel_dep(name = "rules_cc", version = "0.0.6")
19-
bazel_dep(name = "rules_java", version = "5.5.0")
19+
bazel_dep(name = "rules_java", version = "6.0.0")
2020
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")
2121
bazel_dep(name = "rules_jvm_external", version = "4.5")
2222
bazel_dep(name = "rules_python", version = "0.19.0")

WORKSPACE

Lines changed: 4 additions & 225 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
workspace(name = "io_bazel")
22

33
load("//tools/build_defs/repo:http.bzl", "http_archive")
4-
load("//:distdir.bzl", "dist_http_archive", "dist_http_jar", "distdir_tar")
4+
load("//:distdir.bzl", "dist_http_archive", "distdir_tar", "dist_http_jar")
55
load("//:distdir_deps.bzl", "DIST_DEPS")
66
load("//:repositories.bzl", "embedded_jdk_repositories")
7-
load("//tools/jdk:jdk_build_file.bzl", "JDK_BUILD_TEMPLATE")
87

98
# These can be used as values for the patch_cmds and patch_cmds_win attributes
109
# of http_archive, in order to export the WORKSPACE file from the BUILD or
@@ -237,7 +236,6 @@ java_library(
237236
],
238237
)
239238

240-
# Used in src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.
241239
dist_http_archive(
242240
name = "rules_cc",
243241
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_FILE,
@@ -256,26 +254,6 @@ dist_http_archive(
256254
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN,
257255
)
258256

259-
# For testing, have an distdir_tar with all the archives implicit in every
260-
# WORKSPACE, to that they don't have to be refetched for every test
261-
# calling `bazel sync`.
262-
distdir_tar(
263-
name = "test_WORKSPACE_files",
264-
archives = [
265-
"android_tools_pkg-0.28.0.tar",
266-
],
267-
dirname = "test_WORKSPACE/distdir",
268-
dist_deps = {dep: attrs for dep, attrs in DIST_DEPS.items() if "test_WORKSPACE_files" in attrs["used_in"]},
269-
sha256 = {
270-
"android_tools_pkg-0.28.0.tar": "db3b02421ae974e0b33573f3e4f658d5f89cc9a0b42baae0ba2ac08e25c0720a",
271-
},
272-
urls = {
273-
"android_tools_pkg-0.28.0.tar": [
274-
"https://mirror.bazel.build/bazel_android_tools/android_tools_pkg-0.28.0.tar",
275-
],
276-
},
277-
)
278-
279257
dist_http_archive(
280258
name = "io_bazel_skydoc",
281259
)
@@ -309,208 +287,9 @@ dist_http_archive(
309287
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_FILE_WIN,
310288
)
311289

312-
dist_http_archive(
313-
name = "remotejdk11_linux_for_testing",
314-
build_file_content = JDK_BUILD_TEMPLATE.format(RUNTIME_VERSION = 11),
315-
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE,
316-
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN,
317-
)
318-
319-
dist_http_archive(
320-
name = "remotejdk11_linux_aarch64_for_testing",
321-
build_file_content = JDK_BUILD_TEMPLATE.format(RUNTIME_VERSION = 11),
322-
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE,
323-
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN,
324-
)
325-
326-
dist_http_archive(
327-
name = "remotejdk11_linux_ppc64le_for_testing",
328-
build_file_content = JDK_BUILD_TEMPLATE.format(RUNTIME_VERSION = 11),
329-
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE,
330-
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN,
331-
)
332-
333-
dist_http_archive(
334-
name = "remotejdk11_linux_s390x_for_testing",
335-
build_file_content = JDK_BUILD_TEMPLATE.format(RUNTIME_VERSION = 11),
336-
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE,
337-
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN,
338-
)
339-
340-
dist_http_archive(
341-
name = "remotejdk11_macos_for_testing",
342-
build_file_content = JDK_BUILD_TEMPLATE.format(RUNTIME_VERSION = 11),
343-
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE,
344-
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN,
345-
)
346-
347-
dist_http_archive(
348-
name = "remotejdk11_macos_aarch64_for_testing",
349-
build_file_content = JDK_BUILD_TEMPLATE.format(RUNTIME_VERSION = 11),
350-
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE,
351-
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN,
352-
)
353-
354-
dist_http_archive(
355-
name = "remotejdk11_win_for_testing",
356-
build_file_content = JDK_BUILD_TEMPLATE.format(RUNTIME_VERSION = 11),
357-
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE,
358-
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN,
359-
)
360-
361-
dist_http_archive(
362-
name = "remotejdk11_win_arm64_for_testing",
363-
build_file_content = JDK_BUILD_TEMPLATE.format(RUNTIME_VERSION = 11),
364-
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE,
365-
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN,
366-
)
367-
368-
[
369-
dist_http_archive(
370-
name = "remotejdk%s_%s_for_testing" % (version, os),
371-
build_file_content = JDK_BUILD_TEMPLATE.format(RUNTIME_VERSION = version),
372-
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE,
373-
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN,
374-
)
375-
for version in ("17", "20")
376-
for os in ("linux", "macos", "macos_aarch64", "win") + (("linux_s390x", "win_arm64") if version != "20" else ())
377-
]
378-
379-
# Used in src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.
380-
dist_http_archive(
381-
name = "remote_java_tools_for_testing",
382-
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_FILE,
383-
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_FILE_WIN,
384-
)
385-
386-
# Used in src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.
387-
dist_http_archive(
388-
name = "remote_java_tools_linux_for_testing",
389-
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_FILE,
390-
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_FILE_WIN,
391-
)
392-
393-
# Used in src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.
394-
dist_http_archive(
395-
name = "remote_java_tools_windows_for_testing",
396-
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_FILE,
397-
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_FILE_WIN,
398-
)
399-
400-
# Used in src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.
401-
dist_http_archive(
402-
name = "remote_java_tools_darwin_x86_64_for_testing",
403-
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_FILE,
404-
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_FILE_WIN,
405-
)
406-
407-
# Used in src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.
408-
dist_http_archive(
409-
name = "remote_java_tools_darwin_arm64_for_testing",
410-
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_FILE,
411-
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_FILE_WIN,
412-
)
413-
414-
# Used in src/test/shell/bazel/testdata/jdk_http_archives.
415-
dist_http_archive(
416-
name = "remote_java_tools_test",
417-
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_FILE,
418-
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_FILE_WIN,
419-
)
420-
421-
# Used in src/test/shell/bazel/testdata/jdk_http_archives.
422-
dist_http_archive(
423-
name = "remote_java_tools_test_linux",
424-
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_FILE,
425-
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_FILE_WIN,
426-
)
427-
428-
# Used in src/test/shell/bazel/testdata/jdk_http_archives.
429-
dist_http_archive(
430-
name = "remote_java_tools_test_windows",
431-
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_FILE,
432-
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_FILE_WIN,
433-
)
434-
435-
# Used in src/test/shell/bazel/testdata/jdk_http_archives.
436-
dist_http_archive(
437-
name = "remote_java_tools_test_darwin_x86_64",
438-
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_FILE,
439-
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_FILE_WIN,
440-
)
441-
442-
# Used in src/test/shell/bazel/testdata/jdk_http_archives.
443-
dist_http_archive(
444-
name = "remote_java_tools_test_darwin_arm64",
445-
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_FILE,
446-
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_FILE_WIN,
447-
)
448-
449-
dist_http_archive(
450-
name = "openjdk11_linux_archive",
451-
build_file_content = """
452-
java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public'])
453-
exports_files(["WORKSPACE"], visibility = ["//visibility:public"])
454-
""",
455-
)
456-
457-
# This must be kept in sync with src/test/shell/bazel/testdata/jdk_http_archives.
458-
dist_http_archive(
459-
name = "openjdk11_linux_s390x_archive",
460-
build_file_content = """
461-
java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public'])
462-
exports_files(["WORKSPACE"], visibility = ["//visibility:public"])
463-
""",
464-
)
465-
466-
# This must be kept in sync with src/test/shell/bazel/testdata/jdk_http_archives.
467-
dist_http_archive(
468-
name = "openjdk11_darwin_archive",
469-
build_file_content = """
470-
java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public'])
471-
exports_files(["WORKSPACE"], visibility = ["//visibility:public"])
472-
""",
473-
)
474-
475-
# This must be kept in sync with src/test/shell/bazel/testdata/jdk_http_archives.
476-
dist_http_archive(
477-
name = "openjdk11_darwin_aarch64_archive",
478-
build_file_content = """
479-
java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public'])
480-
exports_files(["WORKSPACE"], visibility = ["//visibility:public"])
481-
""",
482-
)
483-
484-
# This must be kept in sync with src/test/shell/bazel/testdata/jdk_http_archives.
485-
dist_http_archive(
486-
name = "openjdk11_windows_archive",
487-
build_file_content = """
488-
java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public'])
489-
exports_files(["WORKSPACE"], visibility = ["//visibility:public"])
490-
""",
491-
)
492-
493-
# This must be kept in sync with src/test/shell/bazel/testdata/jdk_http_archives.
494-
dist_http_archive(
495-
name = "openjdk11_windows_arm64_archive",
496-
build_file_content = """
497-
java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public'])
498-
exports_files(["WORKSPACE"], visibility = ["//visibility:public"])
499-
""",
500-
)
501-
502-
# This must be kept in sync with src/test/shell/bazel/testdata/jdk_http_archives.
503-
[
504-
dist_http_archive(
505-
name = "openjdk%s_%s_archive" % (version, os),
506-
build_file_content = """
507-
java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public'])
508-
exports_files(["WORKSPACE"], visibility = ["//visibility:public"])
509-
""",
510-
)
511-
for version in ("17", "20")
512-
for os in ("linux", "darwin", "darwin_aarch64", "windows") + (("linux_s390x", "windows_arm64") if version != "20" else ())
513-
]
290+
load("@rules_java//java:repositories.bzl", "rules_java_dependencies", "rules_java_toolchains")
291+
rules_java_dependencies()
292+
rules_java_toolchains()
514293

515294
load("@io_bazel_skydoc//:setup.bzl", "stardoc_repositories")
516295

0 commit comments

Comments
 (0)