Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Kotlin language version to 1.8. #216

Merged
merged 7 commits into from
Sep 26, 2023
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Purpose

Implementation of comnmon JVM dependencies for the wfa repositories.
Implementation of common JVM dependencies for the wfa repositories.

### Technologies

Expand Down
1 change: 0 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ load(
"COMMON_JVM_MAVEN_OVERRIDE_TARGETS",
"common_jvm_maven_artifacts",
)

load("@rules_jvm_external//:defs.bzl", "maven_install")

maven_install(
Expand Down
3 changes: 1 addition & 2 deletions build/common_jvm_maven.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Adds external repos necessary for common-jvm.

load(
"//build/rules_kotlin:repo.bzl",
"RULES_KOTLIN_OVERRIDE_TARGETS",
"rules_kotlin_maven_artifacts_dict",
)
load(
Expand Down Expand Up @@ -122,7 +121,7 @@ def common_jvm_maven_artifacts_dict():

return maven_artifacts

COMMON_JVM_MAVEN_OVERRIDE_TARGETS = dict(RULES_KOTLIN_OVERRIDE_TARGETS.items() + GRPC_KOTLIN_OVERRIDE_TARGETS.items())
COMMON_JVM_MAVEN_OVERRIDE_TARGETS = GRPC_KOTLIN_OVERRIDE_TARGETS

COMMON_JVM_EXCLUDED_ARTIFACTS = [
# Until the log2shell has been more widely mitigated, prohibit log4j totally.
Expand Down
2 changes: 1 addition & 1 deletion build/grpc_kotlin/repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Repository rules/macros for Github GPRC Kotlin.

load("//build:versions.bzl", "GRPC_KOTLIN", "versioned_http_archive")

# kt_jvm_grpc_library directly depends on the stub library target below.
# kt_jvm_grpc_library directly depends on these library targets.
GRPC_KOTLIN_OVERRIDE_TARGETS = {
"io.grpc:grpc-kotlin-stub": "@com_github_grpc_grpc_kotlin//stub/src/main/java/io/grpc/kotlin:stub",
}
Expand Down
11 changes: 7 additions & 4 deletions build/kt_jvm_proto/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Provides kt_jvm_proto_library to generate Kotlin protos.

load("//build:defs.bzl", "get_real_short_path")
load("@rules_proto//proto:defs.bzl", "ProtoInfo")
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library")
load("//build/rules_kotlin:defs.bzl", "kt_jvm_library")

KtProtoLibInfo = provider(
"Information for a Kotlin JVM proto library.",
Expand Down Expand Up @@ -153,6 +153,10 @@ _kt_jvm_proto_library_helper = rule(
implementation = _kt_jvm_proto_library_helper_impl,
)

_KT_JVM_PROTO_DEPS = [
"@com_google_protobuf_protobuf_kotlin",
]

def kt_jvm_proto_library(name, srcs = None, deps = None, **kwargs):
"""Generates Kotlin code for a protocol buffer library.

Expand Down Expand Up @@ -186,9 +190,8 @@ def kt_jvm_proto_library(name, srcs = None, deps = None, **kwargs):
kt_jvm_library(
name = name,
srcs = [generated_srcjar],
# TODO: add Bazel rule in protobuf instead of relying on Maven
deps = deps + ["@maven//:com_google_protobuf_protobuf_kotlin"],
exports = deps,
deps = deps + _KT_JVM_PROTO_DEPS,
exports = deps + _KT_JVM_PROTO_DEPS,
kotlinc_opts = "@wfa_common_jvm//build/kt_jvm_proto:proto_gen_kt_options",
**kwargs
)
83 changes: 0 additions & 83 deletions build/rules_kotlin/BUILD.com_github_jetbrains_kotlin

This file was deleted.

36 changes: 36 additions & 0 deletions build/rules_kotlin/defs.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2023 The Cross-Media Measurement Authors
#
# 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.

"""Macros for kt_jvm_library to include Maven kotlin stdlib."""

load(
"@io_bazel_rules_kotlin//kotlin:jvm.bzl",
_kt_jvm_library = "kt_jvm_library",
)

_STDLIBS = [
"@wfa_common_jvm//imports/kotlin/kotlin:stdlib",
"@wfa_common_jvm//imports/kotlin/kotlin/reflect",
]

def kt_jvm_library(name, deps = None, exports = None, **kwargs):
deps = deps or []
exports = exports or []

_kt_jvm_library(
name = name,
deps = deps + _STDLIBS,
exports = exports + _STDLIBS,
**kwargs
)
49 changes: 2 additions & 47 deletions build/rules_kotlin/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,60 +25,15 @@ load("//build:versions.bzl", "KOTLIN_RELEASE_VERSION")
# KOTLIN_RELEASE_VERSION.
JETBRAINS_ANNOTATIONS_VERSION = "13.0"

# buildifier: disable=unnamed-macro
def rules_kotlin_deps():
compiler_release = kotlinc_version(
release = KOTLIN_RELEASE_VERSION,
sha256 = "632166fed89f3f430482f5aa07f2e20b923b72ef688c8f5a7df3aa1502c6d8ba",
sha256 = "6e43c5569ad067492d04d92c28cdf8095673699d81ce460bd7270443297e8fd7",
)
kotlin_repositories(
compiler_release = compiler_release,
)

# Override the Kotlin compiler repo with one that has Maven coordinate tags.
#
# TODO(bazelbuild/rules_kotlin#752): Drop once compiler repo deps are
# tagged with Maven coordinates.
_kotlin_compiler_repo(
name = "com_github_jetbrains_kotlin",
urls = [
url.format(version = compiler_release.version)
for url in compiler_release.url_templates
],
sha256 = compiler_release.sha256,
)

native.register_toolchains(
"@wfa_common_jvm//build/rules_kotlin/toolchain:toolchain",
)

def _kotlin_compiler_repo_impl(repository_ctx):
attr = repository_ctx.attr
repository_ctx.download_and_extract(
attr.urls,
sha256 = attr.sha256,
stripPrefix = "kotlinc",
)
repository_ctx.file(
"WORKSPACE",
content = "workspace(name = {name})".format(name = attr.name),
)
repository_ctx.template(
"BUILD.bazel",
attr._build_template,
substitutions = {
"{{kotlin_release_version}}": KOTLIN_RELEASE_VERSION,
"{{jetbrains_annotations_version}}": JETBRAINS_ANNOTATIONS_VERSION,
},
executable = False,
)

_kotlin_compiler_repo = repository_rule(
implementation = _kotlin_compiler_repo_impl,
attrs = {
"urls": attr.string_list(mandatory = True),
"sha256": attr.string(),
"_build_template": attr.label(
default = ":BUILD.com_github_jetbrains_kotlin",
),
},
)
51 changes: 15 additions & 36 deletions build/rules_kotlin/repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,26 @@
See https://github.com/bazelbuild/rules_kotlin
"""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("//build:versions.bzl", "KOTLIN_RELEASE_VERSION")

_JETBRAINS_KOTLIN_OVERRIDE_TARGETS = {
"org.jetbrains.kotlin:kotlin-stdlib": "@com_github_jetbrains_kotlin//:kotlin-stdlib",
"org.jetbrains.kotlin:kotlin-stdlib-common": "@com_github_jetbrains_kotlin//:kotlin-stdlib",
"org.jetbrains.kotlin:kotlin-stdlib-jdk7": "@com_github_jetbrains_kotlin//:kotlin-stdlib-jdk7",
"org.jetbrains.kotlin:kotlin-stdlib-jdk8": "@com_github_jetbrains_kotlin//:kotlin-stdlib-jdk8",
"org.jetbrains.kotlin:kotlin-reflect": "@com_github_jetbrains_kotlin//:kotlin-reflect",
"org.jetbrains.kotlin:kotlin-test": "@com_github_jetbrains_kotlin//:kotlin-test",
}

_JETBRAINS_OVERRIDE_TARGETS = {
"org.jetbrains:annotations": "@com_github_jetbrains_kotlin//:annotations",
} # @unused

# Override targets for rules_kotlin.
#
# Despite the fact that the Kotlin compiler release bundles JetBrains,
# annotations, we intentionally do not include it as an override target since
# as of the 1.6 compiler release it is quite an old version (13).
RULES_KOTLIN_OVERRIDE_TARGETS = _JETBRAINS_KOTLIN_OVERRIDE_TARGETS

def _rules_kotlin_repo(version, sha256):
maybe(
http_archive,
name = "io_bazel_rules_kotlin",
urls = ["https://github.com/bazelbuild/rules_kotlin/releases/download/%s/rules_kotlin_release.tgz" % version],
sha256 = sha256,
)
load(
"//build:versions.bzl",
"KOTLIN_RELEASE_VERSION",
"RULES_KOTLIN",
"versioned_http_archive",
)

_JETBRAINS_KOTLIN_LIBRARIES = [
"org.jetbrains.kotlin:kotlin-stdlib",
"org.jetbrains.kotlin:kotlin-stdlib-common",
"org.jetbrains.kotlin:kotlin-reflect",
"org.jetbrains.kotlin:kotlin-test",
]

def io_bazel_rules_kotlin():
_rules_kotlin_repo(
version = "v1.6.0-RC-2",
sha256 = "88d19c92a1fb63fb64ddb278cd867349c3b0d648b6fe9ef9a200b9abcacd489d",
)
versioned_http_archive(RULES_KOTLIN, "io_bazel_rules_kotlin")

def rules_kotlin_maven_artifacts_dict():
artifacts_dict = {
coordinates: KOTLIN_RELEASE_VERSION
for coordinates in _JETBRAINS_KOTLIN_OVERRIDE_TARGETS.keys()
for coordinates in _JETBRAINS_KOTLIN_LIBRARIES
}
return artifacts_dict
1 change: 1 addition & 0 deletions build/rules_kotlin/toolchain/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ load("//build:versions.bzl", "KOTLIN_LANGUAGE_LEVEL")

kt_kotlinc_options(
name = "default_opts",
include_stdlibs = "none",
x_optin = ["kotlin.RequiresOptIn"],
)

Expand Down
14 changes: 11 additions & 3 deletions build/versions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,23 @@ RULES_DOCKER = VersionedArchiveInfo(
],
)

KOTLIN_LANGUAGE_LEVEL = "1.5"
RULES_KOTLIN = VersionedArchiveInfo(
version = "1.8.1",
sha256 = "a630cda9fdb4f56cf2dc20a4bf873765c41cf00e9379e8d59cd07b24730f4fde",
url_templates = [
"https://github.com/bazelbuild/rules_kotlin/releases/download/v{version}/rules_kotlin_release.tgz",
],
)

KOTLIN_LANGUAGE_LEVEL = "1.8"

# Kotlin release version.
#
# See https://kotlinlang.org/docs/releases.html#release-details.
KOTLIN_RELEASE_VERSION = "1.6.21"
KOTLIN_RELEASE_VERSION = "1.8.21"

# kotlinx.coroutines version.
KOTLINX_COROUTINES_VERSION = "1.6.2"
KOTLINX_COROUTINES_VERSION = "1.7.3"

# Tink commit that is newer than v1.6.1.
#
Expand Down
9 changes: 2 additions & 7 deletions imports/kotlin/kotlin/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package(default_visibility = ["//visibility:public"])

alias(
name = "stdlib_jdk7",
actual = "@maven//:org_jetbrains_kotlin_kotlin_stdlib_jdk7",
)

alias(
name = "stdlib_jdk8",
actual = "@maven//:org_jetbrains_kotlin_kotlin_stdlib_jdk8",
name = "stdlib",
actual = "@maven//:org_jetbrains_kotlin_kotlin_stdlib",
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package(default_visibility = ["//visibility:public"])

alias(
name = "jvm",
name = "reflect",
actual = "@maven//:org_jetbrains_kotlin_kotlin_reflect",
)
9 changes: 7 additions & 2 deletions imports/kotlin/kotlinx/coroutines/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
load("@rules_java//java:defs.bzl", "java_library")

package(default_visibility = ["//visibility:public"])

alias(
java_library(
name = "core",
actual = "@maven//:org_jetbrains_kotlinx_kotlinx_coroutines_core",
exports = [
"@maven//:org_jetbrains_kotlinx_kotlinx_coroutines_core",
"@maven//:org_jetbrains_kotlinx_kotlinx_coroutines_core_jvm",
],
)

alias(
Expand Down
Loading