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 16visibility(["//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.36.17-ca-jdk21.0.4", 76 "platforms": { 77 "linux": ["aarch64", "x86_64"], 78 "macos": ["aarch64", "x86_64"], 79 "windows": ["arm64", "x86_64"], 80 }, 81 }, 82 "adoptium": { 83 "release": "21.0.4+7", 84 "platforms": { 85 "linux": ["ppc", "s390x"], 86 }, 87 }, 88 }, 89} 90 91_STRIP_PREFIX_OVERRIDES = { 92 "remotejdk11_win_arm64": "jdk-11.0.13+8", 93} 94 95def _name_for_remote_jdk(version, os, cpu): 96 prefix = "remote_jdk" if version == "8" else "remotejdk" 97 os_part = "win" if (os == "windows" and version != "8") else os 98 if cpu == "x86_64": 99 suffix = "" 100 elif cpu == "ppc": 101 suffix = "_ppc64le" 102 else: 103 suffix = "_" + cpu 104 return prefix + version + "_" + os_part + suffix 105 106def _zulu_remote_jdk_repo(os, cpu, release): 107 arch = cpu 108 if cpu == "x86_64": 109 arch = "x64" 110 platform = os 111 ext = ".tar.gz" 112 if os == "macos": 113 platform = "macosx" 114 elif os == "windows": 115 ext = ".zip" 116 platform = "win" 117 arch = "aarch64" if arch == "arm64" else arch 118 archive_name = "zulu" + release + "-" + platform + "_" + arch 119 primary_url = "cdn.azul.com/zulu/bin/" + archive_name + ext 120 urls = [ 121 "https://" + primary_url, 122 "https://mirror.bazel.build/" + primary_url, 123 ] 124 return urls, archive_name 125 126def _adoptium_linux_remote_jdk_repo(version, cpu, release): 127 os = "linux" 128 arch = cpu 129 if cpu == "ppc": 130 arch = "ppc64le" 131 archive_name = "OpenJDK" + version + "U-jdk_" + arch + "_" + os + "_hotspot_" + release.replace("+", "_") + ".tar.gz" 132 primary_url = "github.com/adoptium/temurin" + version + "-binaries/releases/download/jdk-" + release + "/" + archive_name 133 urls = [ 134 "https://" + primary_url, 135 "https://mirror.bazel.build/" + primary_url, 136 ] 137 return urls, "jdk-" + release 138 139def _microsoft_windows_arm64_remote_jdk_repo(release): 140 primary_url = "aka.ms/download-jdk/microsoft-jdk-" + release + "-windows-aarch64.zip" 141 urls = [ 142 "https://" + primary_url, 143 "https://mirror.bazel.build/" + primary_url, 144 ] 145 return urls, "" 146 147def _adoptopenjdk_remote_jdk_repo(version, os, cpu, release): 148 archive = "OpenJDK" + version + "U-jdk_" + cpu + "_" + os + "_hotspot_" + release.replace("-", "") + ".tar.gz" 149 primary_url = "github.com/AdoptOpenJDK/openjdk" + version + "-binaries/releases/download/jdk" + release + "/" + archive 150 urls = [ 151 "https://" + primary_url, 152 "https://mirror.bazel.build/" + primary_url, 153 ] 154 return urls, "jdk" + release 155 156def _flatten_configs(): 157 result = [] 158 for version, all_for_version in _RELEASE_CONFIGS.items(): 159 for distrib, distrib_cfg in all_for_version.items(): 160 release = distrib_cfg["release"] 161 for os, cpus in distrib_cfg["platforms"].items(): 162 for cpu in cpus: 163 name = _name_for_remote_jdk(version, os, cpu) 164 if distrib == "zulu": 165 urls, strip_prefix = _zulu_remote_jdk_repo(os, cpu, release) 166 elif distrib == "adoptium": 167 if os != "linux": 168 fail("adoptium jdk configured but not linux") 169 urls, strip_prefix = _adoptium_linux_remote_jdk_repo(version, cpu, release) 170 elif distrib == "microsoft": 171 if os != "windows" or cpu != "arm64": 172 fail("only windows_arm64 config for microsoft is expected") 173 urls, strip_prefix = _microsoft_windows_arm64_remote_jdk_repo(release) 174 elif distrib == "adoptopenjdk": 175 urls, strip_prefix = _adoptopenjdk_remote_jdk_repo(version, os, cpu, release) 176 else: 177 fail("unexpected distribution:", distrib) 178 result.append(struct( 179 name = name, 180 version = version, 181 urls = urls, 182 strip_prefix = _STRIP_PREFIX_OVERRIDES.get(name, strip_prefix), 183 target_compatible_with = ["@platforms//os:" + os, "@platforms//cpu:" + cpu], 184 )) 185 return result 186 187FLAT_CONFIGS = _flatten_configs() 188