Skip to content

Commit 9e4c1bf

Browse files
hvadehracopybara-github
authored andcommitted
Refactor remote jdks for easier updates and update zulu jdk versions
Work towards bazelbuild/bazel#22625 PiperOrigin-RevId: 641831185 Change-Id: Icef8b937f3427164528e9eb1e2bf1638fa4e8608
1 parent 3c72e84 commit 9e4c1bf

6 files changed

Lines changed: 556 additions & 442 deletions

File tree

.bazelci/presubmit.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ build_targets_bzlmod: &build_targets_bzlmod
1313
# Enable once the issue is fixed.
1414
- "-//distro/..."
1515

16+
test_targets: &test_targets
17+
- "//test/..."
18+
1619
buildifier: latest
1720

1821
tasks:
1922
ubuntu2004:
2023
build_targets: *build_targets
24+
test_targets: *test_targets
2125
macos:
2226
build_targets: *build_targets
2327
windows:

java/bazel/BUILD.bazel

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright 2024 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
load(":repositories_util.bzl", "FLAT_CONFIGS")
15+
16+
# run this to generate _REMOTE_JDK_CONFIGS_LIST in repositories.bzl
17+
# this downloads all the jdks and computes their sha256 sum, so can take a while
18+
# TODO(hvd): make this a sh_binary to update the configs in place
19+
genrule(
20+
name = "dump_remote_jdk_configs",
21+
outs = ["remote_jdks_config.out"],
22+
cmd = """
23+
echo > $@
24+
while read -r config; do
25+
TMP_FILE=$$(mktemp -q /tmp/remotejdk.XXXXXX)
26+
IFS=\\| read -r name version urls strip_prefix target_compatible_with primary_url <<< "$$config"
27+
echo "fetching: $$primary_url to $$TMP_FILE" > /dev/stderr
28+
curl --silent -o $$TMP_FILE -L "$$primary_url" > /dev/stderr
29+
sha256=`sha256sum $$TMP_FILE | cut -d' ' -f1`
30+
echo "struct("
31+
echo " name = \\"$$name\\","
32+
echo " target_compatible_with = $$target_compatible_with,"
33+
echo " sha256 = \\"$$sha256\\","
34+
echo " strip_prefix = \\"$$strip_prefix\\","
35+
echo " urls = $$urls,"
36+
echo " version = \\"$$version\\","
37+
echo "),"
38+
done <<< '{configs}' >> $@
39+
""".format(configs = "\n".join([
40+
"|".join([
41+
config.name,
42+
config.version,
43+
json.encode(config.urls),
44+
config.strip_prefix,
45+
json.encode(config.target_compatible_with),
46+
config.urls[0],
47+
])
48+
for config in FLAT_CONFIGS
49+
])),
50+
tags = [
51+
"local",
52+
"manual",
53+
],
54+
visibility = ["//visibility:private"],
55+
)

java/bazel/repositories_util.bzl

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
# Copyright 2024 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""Helper functions to register remote jdk repos"""
15+
16+
visibility(["//test"])
17+
18+
_RELEASE_CONFIGS = {
19+
"8": {
20+
"zulu": {
21+
"release": "8.78.0.19-ca-jdk8.0.412",
22+
"platforms": {
23+
"linux": ["aarch64", "x86_64"],
24+
"macos": ["aarch64", "x86_64"],
25+
"windows": ["x86_64"],
26+
},
27+
},
28+
"adoptopenjdk": {
29+
"release": "8u292-b10",
30+
"platforms": {
31+
"linux": ["s390x"],
32+
},
33+
},
34+
},
35+
"11": {
36+
"zulu": {
37+
"release": "11.72.19-ca-jdk11.0.23",
38+
"platforms": {
39+
"linux": ["aarch64", "x86_64"],
40+
"macos": ["aarch64", "x86_64"],
41+
"windows": ["x86_64"],
42+
},
43+
},
44+
"adoptium": {
45+
"release": "11.0.15+10",
46+
"platforms": {
47+
"linux": ["ppc", "s390x"],
48+
},
49+
},
50+
"microsoft": {
51+
"release": "11.0.13.8.1",
52+
"platforms": {
53+
"windows": ["arm64"],
54+
},
55+
},
56+
},
57+
"17": {
58+
"zulu": {
59+
"release": "17.50.19-ca-jdk17.0.11",
60+
"platforms": {
61+
"linux": ["aarch64", "x86_64"],
62+
"macos": ["aarch64", "x86_64"],
63+
"windows": ["arm64", "x86_64"],
64+
},
65+
},
66+
"adoptium": {
67+
"release": "17.0.8.1+1",
68+
"platforms": {
69+
"linux": ["ppc", "s390x"],
70+
},
71+
},
72+
},
73+
"21": {
74+
"zulu": {
75+
"release": "21.34.19-ca-jdk21.0.3",
76+
"platforms": {
77+
"linux": ["aarch64", "x86_64"],
78+
"macos": ["aarch64", "x86_64"],
79+
"windows": ["x86_64"],
80+
},
81+
},
82+
"adoptium": {
83+
"release": "21.0.2+13",
84+
"platforms": {
85+
"linux": ["ppc", "s390x"],
86+
},
87+
},
88+
"microsoft": {
89+
"release": "21.0.0",
90+
"platforms": {
91+
"windows": ["arm64"],
92+
},
93+
},
94+
},
95+
}
96+
97+
_STRIP_PREFIX_OVERRIDES = {
98+
"remotejdk11_win_arm64": "jdk-11.0.13+8",
99+
"remotejdk21_win_arm64": "jdk-21+35",
100+
}
101+
102+
def _name_for_remote_jdk(version, os, cpu):
103+
prefix = "remote_jdk" if version == "8" else "remotejdk"
104+
os_part = "win" if (os == "windows" and version != "8") else os
105+
if cpu == "x86_64":
106+
suffix = ""
107+
elif cpu == "ppc":
108+
suffix = "_ppc64le"
109+
else:
110+
suffix = "_" + cpu
111+
return prefix + version + "_" + os_part + suffix
112+
113+
def _zulu_remote_jdk_repo(os, cpu, release):
114+
arch = cpu
115+
if cpu == "x86_64":
116+
arch = "x64"
117+
platform = os
118+
ext = ".tar.gz"
119+
if os == "macos":
120+
platform = "macosx"
121+
elif os == "windows":
122+
ext = ".zip"
123+
platform = "win"
124+
arch = "aarch64" if arch == "arm64" else arch
125+
archive_name = "zulu" + release + "-" + platform + "_" + arch
126+
urls = [
127+
"https://cdn.azul.com/zulu/bin/" + archive_name + ext,
128+
"https://mirror.bazel.build/openjdk/azul-zulu-" + release + "/" + archive_name + ext,
129+
]
130+
return urls, archive_name
131+
132+
def _adoptium_linux_remote_jdk_repo(version, cpu, release):
133+
os = "linux"
134+
arch = cpu
135+
if cpu == "ppc":
136+
arch = "ppc64le"
137+
archive_name = "OpenJDK" + version + "U-jdk_" + arch + "_" + os + "_hotspot_" + release.replace("+", "_") + ".tar.gz"
138+
urls = [
139+
"https://github.com/adoptium/temurin" + version + "-binaries/releases/download/jdk-" + release + "/" + archive_name,
140+
"https://mirror.bazel.build/github.com/adoptium/temurin" + version + "-binaries/releases/download/jdk-" + release + "/" + archive_name,
141+
]
142+
return urls, "jdk-" + release
143+
144+
def _microsoft_windows_arm64_remote_jdk_repo(release):
145+
urls = [
146+
"https://aka.ms/download-jdk/microsoft-jdk-" + release + "-windows-aarch64.zip",
147+
"https://mirror.bazel.build/aka.ms/download-jdk/microsoft-jdk-" + release + "-windows-aarch64.zip",
148+
]
149+
return urls, ""
150+
151+
def _adoptopenjdk_remote_jdk_repo(version, os, cpu, release):
152+
archive = "OpenJDK" + version + "U-jdk_" + cpu + "_" + os + "_hotspot_" + release.replace("-", "") + ".tar.gz"
153+
urls = [
154+
"https://github.com/AdoptOpenJDK/openjdk" + version + "-binaries/releases/download/jdk" + release + "/" + archive,
155+
]
156+
return urls, "jdk" + release
157+
158+
def _flatten_configs():
159+
result = []
160+
for version, all_for_version in _RELEASE_CONFIGS.items():
161+
for distrib, distrib_cfg in all_for_version.items():
162+
release = distrib_cfg["release"]
163+
for os, cpus in distrib_cfg["platforms"].items():
164+
for cpu in cpus:
165+
name = _name_for_remote_jdk(version, os, cpu)
166+
if distrib == "zulu":
167+
urls, strip_prefix = _zulu_remote_jdk_repo(os, cpu, release)
168+
elif distrib == "adoptium":
169+
if os != "linux":
170+
fail("adoptium jdk configured but not linux")
171+
urls, strip_prefix = _adoptium_linux_remote_jdk_repo(version, cpu, release)
172+
elif distrib == "microsoft":
173+
if os != "windows" or cpu != "arm64":
174+
fail("only windows_arm64 config for microsoft is expected")
175+
urls, strip_prefix = _microsoft_windows_arm64_remote_jdk_repo(release)
176+
elif distrib == "adoptopenjdk":
177+
urls, strip_prefix = _adoptopenjdk_remote_jdk_repo(version, os, cpu, release)
178+
else:
179+
fail("unexpected distribution:", distrib)
180+
result.append(struct(
181+
name = name,
182+
version = version,
183+
urls = urls,
184+
strip_prefix = _STRIP_PREFIX_OVERRIDES.get(name, strip_prefix),
185+
target_compatible_with = ["@platforms//os:" + os, "@platforms//cpu:" + cpu],
186+
))
187+
return result
188+
189+
FLAT_CONFIGS = _flatten_configs()

0 commit comments

Comments
 (0)