Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ build_targets_bzlmod: &build_targets_bzlmod
# Enable once the issue is fixed.
- "-//distro/..."

test_targets: &test_targets
- "//test/..."

buildifier: latest

tasks:
ubuntu2004:
build_targets: *build_targets
test_targets: *test_targets
macos:
build_targets: *build_targets
windows:
Expand Down
55 changes: 55 additions & 0 deletions java/bazel/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright 2024 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
load(":repositories_util.bzl", "FLAT_CONFIGS")

# run this to generate _REMOTE_JDK_CONFIGS_LIST in repositories.bzl
# this downloads all the jdks and computes their sha256 sum, so can take a while
# TODO(hvd): make this a sh_binary to update the configs in place
genrule(
name = "dump_remote_jdk_configs",
outs = ["remote_jdks_config.out"],
cmd = """
echo > $@
while read -r config; do
TMP_FILE=$$(mktemp -q /tmp/remotejdk.XXXXXX)
IFS=\\| read -r name version urls strip_prefix target_compatible_with primary_url <<< "$$config"
echo "fetching: $$primary_url to $$TMP_FILE" > /dev/stderr
curl --silent -o $$TMP_FILE -L "$$primary_url" > /dev/stderr
sha256=`sha256sum $$TMP_FILE | cut -d' ' -f1`
echo "struct("
echo " name = \\"$$name\\","
echo " target_compatible_with = $$target_compatible_with,"
echo " sha256 = \\"$$sha256\\","
echo " strip_prefix = \\"$$strip_prefix\\","
echo " urls = $$urls,"
echo " version = \\"$$version\\","
echo "),"
done <<< '{configs}' >> $@
""".format(configs = "\n".join([
"|".join([
config.name,
config.version,
json.encode(config.urls),
config.strip_prefix,
json.encode(config.target_compatible_with),
config.urls[0],
])
for config in FLAT_CONFIGS
])),
tags = [
"local",
"manual",
],
visibility = ["//visibility:private"],
)
189 changes: 189 additions & 0 deletions java/bazel/repositories_util.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
# Copyright 2024 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Helper functions to register remote jdk repos"""

visibility(["//test"])

_RELEASE_CONFIGS = {
"8": {
"zulu": {
"release": "8.78.0.19-ca-jdk8.0.412",
"platforms": {
"linux": ["aarch64", "x86_64"],
"macos": ["aarch64", "x86_64"],
"windows": ["x86_64"],
},
},
"adoptopenjdk": {
"release": "8u292-b10",
"platforms": {
"linux": ["s390x"],
},
},
},
"11": {
"zulu": {
"release": "11.72.19-ca-jdk11.0.23",
"platforms": {
"linux": ["aarch64", "x86_64"],
"macos": ["aarch64", "x86_64"],
"windows": ["x86_64"],
},
},
"adoptium": {
"release": "11.0.15+10",
"platforms": {
"linux": ["ppc", "s390x"],
},
},
"microsoft": {
"release": "11.0.13.8.1",
"platforms": {
"windows": ["arm64"],
},
},
},
"17": {
"zulu": {
"release": "17.50.19-ca-jdk17.0.11",
"platforms": {
"linux": ["aarch64", "x86_64"],
"macos": ["aarch64", "x86_64"],
"windows": ["arm64", "x86_64"],
},
},
"adoptium": {
"release": "17.0.8.1+1",
"platforms": {
"linux": ["ppc", "s390x"],
},
},
},
"21": {
"zulu": {
"release": "21.34.19-ca-jdk21.0.3",
"platforms": {
"linux": ["aarch64", "x86_64"],
"macos": ["aarch64", "x86_64"],
"windows": ["x86_64"],
},
},
"adoptium": {
"release": "21.0.2+13",
"platforms": {
"linux": ["ppc", "s390x"],
},
},
"microsoft": {
"release": "21.0.0",
"platforms": {
"windows": ["arm64"],
},
},
},
}

_STRIP_PREFIX_OVERRIDES = {
"remotejdk11_win_arm64": "jdk-11.0.13+8",
"remotejdk21_win_arm64": "jdk-21+35",
}

def _name_for_remote_jdk(version, os, cpu):
prefix = "remote_jdk" if version == "8" else "remotejdk"
os_part = "win" if (os == "windows" and version != "8") else os
if cpu == "x86_64":
suffix = ""
elif cpu == "ppc":
suffix = "_ppc64le"
else:
suffix = "_" + cpu
return prefix + version + "_" + os_part + suffix

def _zulu_remote_jdk_repo(os, cpu, release):
arch = cpu
if cpu == "x86_64":
arch = "x64"
platform = os
ext = ".tar.gz"
if os == "macos":
platform = "macosx"
elif os == "windows":
ext = ".zip"
platform = "win"
arch = "aarch64" if arch == "arm64" else arch
archive_name = "zulu" + release + "-" + platform + "_" + arch
urls = [
"https://cdn.azul.com/zulu/bin/" + archive_name + ext,
"https://mirror.bazel.build/openjdk/azul-zulu-" + release + "/" + archive_name + ext,
]
return urls, archive_name

def _adoptium_linux_remote_jdk_repo(version, cpu, release):
os = "linux"
arch = cpu
if cpu == "ppc":
arch = "ppc64le"
archive_name = "OpenJDK" + version + "U-jdk_" + arch + "_" + os + "_hotspot_" + release.replace("+", "_") + ".tar.gz"
urls = [
"https://github.com/adoptium/temurin" + version + "-binaries/releases/download/jdk-" + release + "/" + archive_name,
"https://mirror.bazel.build/github.com/adoptium/temurin" + version + "-binaries/releases/download/jdk-" + release + "/" + archive_name,
]
return urls, "jdk-" + release

def _microsoft_windows_arm64_remote_jdk_repo(release):
urls = [
"https://aka.ms/download-jdk/microsoft-jdk-" + release + "-windows-aarch64.zip",
"https://mirror.bazel.build/aka.ms/download-jdk/microsoft-jdk-" + release + "-windows-aarch64.zip",
]
return urls, ""

def _adoptopenjdk_remote_jdk_repo(version, os, cpu, release):
archive = "OpenJDK" + version + "U-jdk_" + cpu + "_" + os + "_hotspot_" + release.replace("-", "") + ".tar.gz"
urls = [
"https://github.com/AdoptOpenJDK/openjdk" + version + "-binaries/releases/download/jdk" + release + "/" + archive,
]
return urls, "jdk" + release

def _flatten_configs():
result = []
for version, all_for_version in _RELEASE_CONFIGS.items():
for distrib, distrib_cfg in all_for_version.items():
release = distrib_cfg["release"]
for os, cpus in distrib_cfg["platforms"].items():
for cpu in cpus:
name = _name_for_remote_jdk(version, os, cpu)
if distrib == "zulu":
urls, strip_prefix = _zulu_remote_jdk_repo(os, cpu, release)
elif distrib == "adoptium":
if os != "linux":
fail("adoptium jdk configured but not linux")
urls, strip_prefix = _adoptium_linux_remote_jdk_repo(version, cpu, release)
elif distrib == "microsoft":
if os != "windows" or cpu != "arm64":
fail("only windows_arm64 config for microsoft is expected")
urls, strip_prefix = _microsoft_windows_arm64_remote_jdk_repo(release)
elif distrib == "adoptopenjdk":
urls, strip_prefix = _adoptopenjdk_remote_jdk_repo(version, os, cpu, release)
else:
fail("unexpected distribution:", distrib)
result.append(struct(
name = name,
version = version,
urls = urls,
strip_prefix = _STRIP_PREFIX_OVERRIDES.get(name, strip_prefix),
target_compatible_with = ["@platforms//os:" + os, "@platforms//cpu:" + cpu],
))
return result

FLAT_CONFIGS = _flatten_configs()
Loading