Skip to content

Commit 5fd9e37

Browse files
committed
Add support for JDK 14
Closes bazelbuild#11017. Test Plan: 1. Create java_tools from this commit: $ bazel build src:java_tools_java14.zip 2. Switch to using the java_tools from the above step in WORKSPACE file: load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "remote_java_tools_linux", urls = [ "file:///<path to the java_tools_java14.zip>", ], ) 3. Add Zulu OpenJDK14 to use as javabase in WORKSPACE file: http_archive( name = "openjdk14_linux_archive", build_file_content = """ java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public']) exports_files(["WORKSPACE"], visibility = ["//visibility:public"]) """, sha256 = "48bb8947034cd079ad1ef83335e7634db4b12a26743a0dc314b6b861480777aa", strip_prefix = "zulu14.28.21-ca-jdk14.0.1-linux_x64", urls = ["https://cdn.azul.com/zulu/bin/zulu14.28.21-ca-jdk14.0.1-linux_x64.tar.gz"], ) 4. Activate custom java toolchain and javabase in .bazelrc file: build --java_toolchain=@remote_java_tools_linux//:toolchain_jdk_14 build --host_java_toolchain=@remote_java_tools_linux//:toolchain_jdk_14 build --javabase=@openjdk14_linux_archive//:runtime build --host_javabase=@openjdk14_linux_archive//:runtime 5. Create Java 14 example class file: public class Javac14Example { record Point(int x, int y) {} public static void main(String[] args) { Point point = new Point(0, 1); System.out.println(point.x); } } 6. Add Bazel file to build Java 14 syntax class with activated preview features: java_binary( name = "Javac14Example", srcs = ["Javac14Example.java"], javacopts = ["--enable-preview"], jvm_flags = ["--enable-preview"], main_class = "Javac14Example", ) 7. Test that it works as expected: $ bazel run java:Javac14Example INFO: Analyzed target //java:Javac14Example (1 packages loaded, 2 targets configured). INFO: Found 1 target... INFO: From Building java/Javac14Example.jar (1 source file): Note: java/Javac14Example.java uses preview language features. Note: Recompile with -Xlint:preview for details. Target //java:Javac14Example up-to-date: bazel-bin/java/Javac14Example.jar bazel-bin/java/Javac14Example INFO: Elapsed time: 1.502s, Critical Path: 1.30s INFO: 1 process: 1 worker. INFO: Build completed successfully, 2 total actions INFO: Build completed successfully, 2 total actions 0
1 parent 3daedc3 commit 5fd9e37

File tree

12 files changed

+810
-77
lines changed

12 files changed

+810
-77
lines changed

WORKSPACE

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,7 @@ http_archive(
701701
],
702702
)
703703

704+
704705
# This must be kept in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/android/android_remote_tools.WORKSPACE
705706
http_archive(
706707
name = "android_tools_for_testing",
@@ -779,6 +780,39 @@ http_archive(
779780
urls = ["https://mirror.bazel.build/openjdk/azul-zulu11.37.17-ca-jdk11.0.6/zulu11.37.17-ca-jdk11.0.6-win_x64.zip"],
780781
)
781782

783+
# This must be kept in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.
784+
http_archive(
785+
name = "remotejdk14_linux_for_testing",
786+
build_file = "@local_jdk//:BUILD.bazel",
787+
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE,
788+
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN,
789+
sha256 = "48bb8947034cd079ad1ef83335e7634db4b12a26743a0dc314b6b861480777aa",
790+
strip_prefix = "zulu14.28.21-ca-jdk14.0.1-linux_x64",
791+
urls = ["https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu14.28.21-ca-jdk14.0.1-linux_x64.tar.gz"],
792+
)
793+
794+
# This must be kept in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.
795+
http_archive(
796+
name = "remotejdk14_macos_for_testing",
797+
build_file = "@local_jdk//:BUILD.bazel",
798+
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE,
799+
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN,
800+
sha256 = "088bd4d0890acc9f032b738283bf0f26b2a55c50b02d1c8a12c451d8ddf080dd",
801+
strip_prefix = "zulu14.28.21-ca-jdk14.0.1-macosx_x64",
802+
urls = ["https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu14.28.21-ca-jdk14.0.1-macosx_x64.tar.gz"],
803+
)
804+
805+
# This must be kept in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.
806+
http_archive(
807+
name = "remotejdk14_win_for_testing",
808+
build_file = "@local_jdk//:BUILD.bazel",
809+
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE,
810+
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN,
811+
sha256 = "9cb078b5026a900d61239c866161f0d9558ec759aa15c5b4c7e905370e868284",
812+
strip_prefix = "zulu14.28.21-ca-jdk14.0.1-win_x64",
813+
urls = ["https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu14.28.21-ca-jdk14.0.1-win_x64.zip"],
814+
)
815+
782816
# This must be kept in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.
783817
http_archive(
784818
name = "remote_java_tools_linux_for_testing",
@@ -884,6 +918,42 @@ exports_files(["WORKSPACE"], visibility = ["//visibility:public"])
884918
urls = ["https://mirror.bazel.build/openjdk/azul-zulu11.37.17-ca-jdk11.0.6/zulu11.37.17-ca-jdk11.0.6-win_x64.zip"],
885919
)
886920

921+
# This must be kept in sync with src/test/shell/bazel/testdata/jdk_http_archives.
922+
http_archive(
923+
name = "openjdk14_linux_archive",
924+
build_file_content = """
925+
java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public'])
926+
exports_files(["WORKSPACE"], visibility = ["//visibility:public"])
927+
""",
928+
sha256 = "48bb8947034cd079ad1ef83335e7634db4b12a26743a0dc314b6b861480777aa",
929+
strip_prefix = "zulu14.28.21-ca-jdk14.0.1-linux_x64",
930+
urls = ["https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu14.28.21-ca-jdk14.0.1-linux_x64.tar.gz"],
931+
)
932+
933+
# This must be kept in sync with src/test/shell/bazel/testdata/jdk_http_archives.
934+
http_archive(
935+
name = "openjdk14_darwin_archive",
936+
build_file_content = """
937+
java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public'])
938+
exports_files(["WORKSPACE"], visibility = ["//visibility:public"])
939+
""",
940+
sha256 = "088bd4d0890acc9f032b738283bf0f26b2a55c50b02d1c8a12c451d8ddf080dd",
941+
strip_prefix = "zulu14.28.21-ca-jdk14.0.1-macosx_x64",
942+
urls = ["https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu14.28.21-ca-jdk14.0.1-macosx_x64.tar.gz"],
943+
)
944+
945+
# This must be kept in sync with src/test/shell/bazel/testdata/jdk_http_archives.
946+
http_archive(
947+
name = "openjdk14_windows_archive",
948+
build_file_content = """
949+
java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public'])
950+
exports_files(["WORKSPACE"], visibility = ["//visibility:public"])
951+
""",
952+
sha256 = "9cb078b5026a900d61239c866161f0d9558ec759aa15c5b4c7e905370e868284",
953+
strip_prefix = "zulu14.28.21-ca-jdk14.0.1-win_x64",
954+
urls = ["https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu14.28.21-ca-jdk14.0.1-win_x64.zip"],
955+
)
956+
887957
load("@io_bazel_skydoc//:setup.bzl", "stardoc_repositories")
888958

889959
stardoc_repositories()

src/BUILD

Lines changed: 70 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -567,46 +567,68 @@ JAVA_TOOLS_DEPLOY_JARS = [
567567
"//conditions:default": [],
568568
})
569569

570-
JAVA_VERSIONS = ("11",)
570+
genrule(
571+
name = "jars_java_tools_java11_zip",
572+
srcs = JAVA_TOOLS_DEPLOY_JARS + [
573+
"@java_tools_langtools_javac11//:jdk_compiler_jar",
574+
"@java_tools_langtools_javac11//:java_compiler_jar",
575+
"@java_tools_langtools_javac11//:javac_jar",
576+
],
577+
outs = ["jars_java_tools_java11.zip"],
578+
cmd = "zip -qjX $@ $$(echo $(SRCS) | sort)",
579+
visibility = ["//visibility:private"],
580+
)
571581

572-
[
573-
genrule(
574-
name = "jars_java_tools_java" + java_version + "_zip",
575-
srcs = JAVA_TOOLS_DEPLOY_JARS + [
576-
"@java_tools_langtools_javac" + java_version + "//:jdk_compiler_jar",
577-
"@java_tools_langtools_javac" + java_version + "//:java_compiler_jar",
578-
"@java_tools_langtools_javac" + java_version + "//:javac_jar",
579-
],
580-
outs = ["jars_java_tools_java" + java_version + ".zip"],
581-
cmd = "zip -qjX $@ $$(echo $(SRCS) | sort)",
582-
visibility = ["//visibility:private"],
583-
)
584-
for java_version in JAVA_VERSIONS
585-
]
582+
genrule(
583+
name = "jars_java_tools_java14_zip",
584+
srcs = JAVA_TOOLS_DEPLOY_JARS,
585+
outs = ["jars_java_tools_java14.zip"],
586+
cmd = "zip -qjX $@ $$(echo $(SRCS) | sort)",
587+
visibility = ["//visibility:private"],
588+
)
586589

587-
[
588-
genrule(
589-
name = "java_tools_dist_java" + java_version,
590-
srcs = [
591-
"//src/java_tools/buildjar:srcs",
592-
"//src/java_tools/junitrunner:srcs",
593-
"//src/java_tools/singlejar:srcs",
594-
"//src/tools/singlejar:embedded_java_tools",
595-
"//third_party/checker_framework_dataflow:srcs",
596-
"//third_party/checker_framework_javacutil:srcs",
597-
"//third_party/jarjar:srcs",
598-
"//third_party/ijar:transitive_sources",
599-
"//third_party/java/jacoco:transitive_sources",
600-
"//third_party/java/proguard:srcs",
601-
"@java_tools_langtools_javac" + java_version + "//:srcs",
602-
],
603-
outs = ["java_tools_dist_javac" + java_version + ".zip"],
604-
cmd = "zip -qXr $@ $$(echo $(SRCS) | sort)",
605-
output_to_bindir = 1,
606-
visibility = ["//src/test/shell/bazel:__pkg__"],
607-
)
608-
for java_version in JAVA_VERSIONS
609-
]
590+
genrule(
591+
name = "java_tools_dist_java11",
592+
srcs = [
593+
"//src/java_tools/buildjar:srcs",
594+
"//src/java_tools/junitrunner:srcs",
595+
"//src/java_tools/singlejar:srcs",
596+
"//src/tools/singlejar:embedded_java_tools",
597+
"//third_party/checker_framework_dataflow:srcs",
598+
"//third_party/checker_framework_javacutil:srcs",
599+
"//third_party/jarjar:srcs",
600+
"//third_party/ijar:transitive_sources",
601+
"//third_party/java/jacoco:transitive_sources",
602+
"//third_party/java/proguard:srcs",
603+
"@java_tools_langtools_javac11//:srcs",
604+
],
605+
outs = ["java_tools_dist_javac11.zip"],
606+
cmd = "zip -qXr $@ $$(echo $(SRCS) | sort)",
607+
output_to_bindir = 1,
608+
visibility = ["//src/test/shell/bazel:__pkg__"],
609+
)
610+
611+
genrule(
612+
name = "java_tools_dist_java14",
613+
srcs = [
614+
"//src/java_tools/buildjar:srcs",
615+
"//src/java_tools/junitrunner:srcs",
616+
"//src/java_tools/singlejar:srcs",
617+
"//src/tools/singlejar:embedded_java_tools",
618+
"//third_party/checker_framework_dataflow:srcs",
619+
"//third_party/checker_framework_javacutil:srcs",
620+
"//third_party/jarjar:srcs",
621+
"//third_party/ijar:transitive_sources",
622+
"//third_party/java/jacoco:transitive_sources",
623+
"//third_party/java/proguard:srcs",
624+
],
625+
outs = ["java_tools_dist_javac14.zip"],
626+
cmd = "zip -qXr $@ $$(echo $(SRCS) | sort)",
627+
output_to_bindir = 1,
628+
visibility = ["//src/test/shell/bazel:__pkg__"],
629+
)
630+
631+
JAVA_VERSIONS = ("11", "14")
610632

611633
[
612634
# Targets used by the java_tools_binaries Buildkite pipeline to build the
@@ -638,8 +660,10 @@ JAVA_VERSIONS = ("11",)
638660
[
639661
# The java_tools releases can have BUILD files that vary depending on the
640662
# javac version they embed. Currently the only difference is in the
641-
# java_toolchain source version which has to be 12 for javac 12 to be able
642-
# to build new Java 12 features.
663+
# java_toolchain source version which has to be 14 for javac 14 to be able
664+
# to build new Java 14 features. This is not used atm, as the toolchain for
665+
# javac 14 was duplicated, but it might be used in future Bazel releases to
666+
# support new javac release, so that we preserve this step for now.
643667
genrule(
644668
name = "create_java_tools_build_java" + java_version,
645669
srcs = ["//tools/jdk:BUILD.java_tools"],
@@ -744,6 +768,9 @@ filegroup(
744768
"@openjdk11_darwin_archive//:WORKSPACE",
745769
"@openjdk11_linux_archive//:WORKSPACE",
746770
"@openjdk11_windows_archive//:WORKSPACE",
771+
"@openjdk14_darwin_archive//:WORKSPACE",
772+
"@openjdk14_linux_archive//:WORKSPACE",
773+
"@openjdk14_windows_archive//:WORKSPACE",
747774
"@openjdk_linux_aarch64_minimal//file",
748775
"@openjdk_linux_minimal//file",
749776
"@openjdk_macos_minimal//file",
@@ -760,6 +787,9 @@ filegroup(
760787
"@remotejdk11_linux_ppc64le_for_testing//:WORKSPACE",
761788
"@remotejdk11_macos_for_testing//:WORKSPACE",
762789
"@remotejdk11_win_for_testing//:WORKSPACE",
790+
"@remotejdk14_linux_for_testing//:WORKSPACE",
791+
"@remotejdk14_macos_for_testing//:WORKSPACE",
792+
"@remotejdk14_win_for_testing//:WORKSPACE",
763793
"@rules_cc//:WORKSPACE",
764794
"@rules_java//:WORKSPACE",
765795
"@rules_pkg//:WORKSPACE",

src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,38 @@ maybe(
154154
],
155155
)
156156

157+
# This must be kept in sync with the top-level WORKSPACE file.
158+
maybe(
159+
http_archive,
160+
name = "remotejdk14_linux",
161+
build_file = "@local_jdk//:BUILD.bazel",
162+
sha256 = "48bb8947034cd079ad1ef83335e7634db4b12a26743a0dc314b6b861480777aa",
163+
strip_prefix = "zulu14.28.21-ca-jdk14.0.1-linux_x64",
164+
urls = [
165+
"https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu14.28.21-ca-jdk14.0.1-linux_x64.tar.gz",
166+
],
167+
)
168+
169+
# This must be kept in sync with the top-level WORKSPACE file.
170+
maybe(
171+
http_archive,
172+
name = "remotejdk14_macos",
173+
build_file = "@local_jdk//:BUILD.bazel",
174+
sha256 = "088bd4d0890acc9f032b738283bf0f26b2a55c50b02d1c8a12c451d8ddf080dd",
175+
strip_prefix = "zulu14.28.21-ca-jdk14.0.1-macosx_x64",
176+
urls = ["https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu14.28.21-ca-jdk14.0.1-macosx_x64.tar.gz"],
177+
)
178+
179+
# This must be kept in sync with the top-level WORKSPACE file.
180+
maybe(
181+
http_archive,
182+
name = "remotejdk14_win",
183+
build_file = "@local_jdk//:BUILD.bazel",
184+
sha256 = "9cb078b5026a900d61239c866161f0d9558ec759aa15c5b4c7e905370e868284",
185+
strip_prefix = "zulu14.28.21-ca-jdk14.0.1-win_x64",
186+
urls = ["https://mirror.bazel.build/cdn.azul.com/zulu/bin/zulu14.28.21-ca-jdk14.0.1-win_x64.zip"],
187+
)
188+
157189
# This must be kept in sync with the top-level WORKSPACE file.
158190
maybe(
159191
http_archive,

src/test/py/bazel/test_base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class TestBase(unittest.TestCase):
6161
'remotejdk11_linux_ppc64le_for_testing',
6262
'remotejdk11_macos_for_testing',
6363
'remotejdk11_win_for_testing',
64+
'remotejdk14_linux_for_testing',
65+
'remotejdk14_macos_for_testing',
66+
'remotejdk14_win_for_testing',
6467
'remote_java_tools_darwin_for_testing',
6568
'remote_java_tools_linux_for_testing',
6669
'remote_java_tools_windows_for_testing',

0 commit comments

Comments
 (0)