Skip to content

Commit 89fd270

Browse files
authored
Add support for Kotlin 2.2+ (#1387)
* Add support for Kotlin 2.2+ with versioned artifact system Kotlin 2.2 removed trove4j and android-extensions jars from the distribution. This change introduces version-specific artifact definitions (artifacts_2.1.bzl and artifacts_2.2.bzl) to handle these differences, with automatic selection based on Kotlin version. Updates default Kotlin version to 2.2. Changes: - Created WriteKotlinArtifacts tool to generate artifact definitions - Added artifacts_2.1.bzl (includes trove4j) and artifacts_2.2.bzl - Updated compiler.bzl to use KOTLIN_STDLIBS from artifacts - Updated default Kotlin version to 2.2.21 - Added custom_compiler_version example to test backward compatibility - Updated jdeps plugin imports to use K2 FIR APIs Fixes #1373 * Fix * Remove artifacts.bzl generation * Fix docs * Fix * kotlinc_opts dictionary -> array * Fix RBE * Fix jetpack_compose * Downgrade rules_proto, upgrade kotlin-build-tools-impl
1 parent 12021bd commit 89fd270

File tree

28 files changed

+157
-95
lines changed

28 files changed

+157
-95
lines changed

docs/kotlin.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,8 +600,8 @@ Call this in the WORKSPACE file to setup the Kotlin rules.
600600
| <a id="kotlin_repositories-is_bzlmod"></a>is_bzlmod | <p align="center"> - </p> | `False` |
601601
| <a id="kotlin_repositories-compiler_repository_name"></a>compiler_repository_name | for the kotlinc compiler repository. | `"com_github_jetbrains_kotlin"` |
602602
| <a id="kotlin_repositories-ksp_repository_name"></a>ksp_repository_name | <p align="center"> - </p> | `"com_github_google_ksp"` |
603-
| <a id="kotlin_repositories-compiler_release"></a>compiler_release | version provider from versions.bzl. | `struct(sha256 = "1ba08a8b45da99339a0601134cc037b54cf85e9bc0edbe76dcbd27c2d684a977", url_templates = ["https://github.com/JetBrains/kotlin/releases/download/v{version}/kotlin-compiler-{version}.zip"], version = "2.1.21")` |
604-
| <a id="kotlin_repositories-ksp_compiler_release"></a>ksp_compiler_release | (internal) version provider from versions.bzl. | `struct(sha256 = "44e965bb067b2bb5cd9184dab2c3dea6e3eab747d341c07645bb4c88f09e49c8", url_templates = ["https://github.com/google/ksp/releases/download/{version}/artifacts.zip"], version = "2.1.21-2.0.1")` |
603+
| <a id="kotlin_repositories-compiler_release"></a>compiler_release | version provider from versions.bzl. | `struct(sha256 = "a623871f1cd9c938946948b70ef9170879f0758043885bbd30c32f024e511714", url_templates = ["https://github.com/JetBrains/kotlin/releases/download/v{version}/kotlin-compiler-{version}.zip"], version = "2.2.21")` |
604+
| <a id="kotlin_repositories-ksp_compiler_release"></a>ksp_compiler_release | (internal) version provider from versions.bzl. | `struct(sha256 = "6550f1117d7c9590cc9a5075b92682a218c8e1df4093d7e683d73cc481733dd1", url_templates = ["https://github.com/google/ksp/releases/download/{version}/artifacts.zip"], version = "2.2.21-2.0.4")` |
605605

606606

607607
<a id="versions.use_repository"></a>

examples/jetpack_compose/MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ maven.install(
3737
name = "maven_rules_kotlin_example",
3838
aar_import_bzl_label = "@rules_android//rules:rules.bzl",
3939
artifacts = [
40-
"org.jetbrains.kotlin:kotlin-compose-compiler-plugin-embeddable:2.1.20",
40+
"org.jetbrains.kotlin:kotlin-compose-compiler-plugin-embeddable:2.2.21",
4141
"androidx.core:core-ktx:1.15.0",
4242
"androidx.appcompat:appcompat:1.7.0",
4343
"androidx.activity:activity-compose:1.7.0",

examples/jetpack_compose/maven_install.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL",
3-
"__INPUT_ARTIFACTS_HASH": -84190194,
4-
"__RESOLVED_ARTIFACTS_HASH": 1828198228,
3+
"__INPUT_ARTIFACTS_HASH": 546178286,
4+
"__RESOLVED_ARTIFACTS_HASH": 981137442,
55
"artifacts": {
66
"androidx.activity:activity": {
77
"shasums": {
@@ -958,10 +958,10 @@
958958
},
959959
"org.jetbrains.kotlin:kotlin-compose-compiler-plugin-embeddable": {
960960
"shasums": {
961-
"jar": "cf87503abc96914f169c9ed61d30a097578c26b0da2666fdd172ec7cff2fac5d",
962-
"sources": "b1cc37d9883f388e1e5abfa6405c9d524baf0408262bc63e1d0592c2c876d747"
961+
"jar": "bd6b2db8bbf5ef1c12888ae885b72054e70cea7ef4d6e8bb5eca4faa0539393f",
962+
"sources": "0c1a7ad3991be34d03555140c304f15c67748f5be71a8e79dc393b745e442202"
963963
},
964-
"version": "2.1.20"
964+
"version": "2.2.21"
965965
},
966966
"org.jetbrains.kotlin:kotlin-stdlib": {
967967
"shasums": {

kotlin/compiler/compiler.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ load("//kotlin/internal:defs.bzl", _KT_COMPILER_REPO = "KT_COMPILER_REPO")
1818

1919
KOTLIN_STDLIBS = [
2020
"//kotlin/compiler:annotations",
21+
"//kotlin/compiler:kotlin-reflect",
2122
"//kotlin/compiler:kotlin-stdlib",
2223
"//kotlin/compiler:kotlin-stdlib-jdk7",
2324
"//kotlin/compiler:kotlin-stdlib-jdk8",
2425
"//kotlin/compiler:kotlinx-coroutines-core-jvm",
25-
"//kotlin/compiler:trove4j",
2626
]
2727

2828
def _import_artifacts(artifacts, rule_kind):

src/main/kotlin/BUILD.release.bazel

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
load("@com_github_jetbrains_kotlin//:artifacts.bzl", "KOTLIN_STDLIBS")
1516
load("@rules_java//java:defs.bzl", "java_binary", "java_import")
1617

1718
java_import(
@@ -78,14 +79,7 @@ java_binary(
7879

7980
java_binary(
8081
name = "jdeps_merger",
81-
data = [
82-
"@com_github_jetbrains_kotlin//:annotations",
83-
"@com_github_jetbrains_kotlin//:kotlin-stdlib",
84-
"@com_github_jetbrains_kotlin//:kotlin-stdlib-jdk7",
85-
"@com_github_jetbrains_kotlin//:kotlin-stdlib-jdk8",
86-
"@com_github_jetbrains_kotlin//:kotlinx-coroutines-core-jvm",
87-
"@com_github_jetbrains_kotlin//:trove4j",
88-
],
82+
data = KOTLIN_STDLIBS,
8983
jvm_flags = [
9084
"-XX:-MaxFDLimit",
9185
],

src/main/kotlin/bootstrap.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ load("//kotlin:lint.bzl", _ktlint_fix = "ktlint_fix", _ktlint_test = "ktlint_tes
1616
load("//src/main/starlark/core/compile:rules.bzl", "core_kt_jvm_library")
1717
load("//third_party:jarjar.bzl", "jar_jar")
1818

19-
def kt_bootstrap_library(name, deps = [], neverlink_deps = [], srcs = [], visibility = [], **kwargs):
19+
def kt_bootstrap_library(name, deps = [], neverlink_deps = [], srcs = [], visibility = [], kotlinc_opts = [], **kwargs):
2020
"""
2121
Simple compilation of a kotlin library using a non-persistent worker. The target is a JavaInfo provider.
2222
@@ -34,6 +34,7 @@ def kt_bootstrap_library(name, deps = [], neverlink_deps = [], srcs = [], visibi
3434
srcs = srcs,
3535
visibility = visibility,
3636
deps = deps + ["%s_neverlink" % name],
37+
kotlinc_opts = kotlinc_opts,
3738
**kwargs
3839
)
3940

@@ -43,6 +44,7 @@ def kt_bootstrap_library(name, deps = [], neverlink_deps = [], srcs = [], visibi
4344
visibility = ["//visibility:private"],
4445
config = "//:ktlint_editorconfig",
4546
tags = ["no-ide", "ktlint"],
47+
**kwargs
4648
)
4749

4850
_ktlint_fix(

src/main/kotlin/io/bazel/kotlin/builder/cmd/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ kt_bootstrap_binary(
1919
"//kotlin/compiler:jvm-abi-gen",
2020
"//kotlin/compiler:kotlin-annotation-processing",
2121
"//kotlin/compiler:kotlin-compiler",
22-
"//kotlin/compiler:kotlin-reflect",
2322
"//kotlin/compiler:symbol-processing-api",
2423
"//kotlin/compiler:symbol-processing-cmdline",
2524
"//src/main/kotlin:jdeps-gen",

src/main/kotlin/io/bazel/kotlin/builder/tasks/jvm/KotlinJvmTaskExecutor.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class KotlinJvmTaskExecutor
6363

6464
context.execute("compile classes") {
6565
preprocessedTask.apply {
66-
sequenceOf(
66+
listOf(
6767
runCatching {
6868
context.execute("kotlinc") {
6969
if (compileKotlin) {
@@ -80,6 +80,9 @@ class KotlinJvmTaskExecutor
8080
inputs.directDependenciesList.forEach {
8181
flag("direct_dependencies", it)
8282
}
83+
inputs.classpathList.forEach {
84+
flag("full_classpath", it)
85+
}
8386
flag("strict_kotlin_deps", info.strictKotlinDeps)
8487
}
8588
}.given(outputs.jar)

src/main/kotlin/io/bazel/kotlin/generate/BUILD.bazel

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
load("//kotlin:jvm.bzl", "kt_jvm_binary", "kt_jvm_import", "kt_jvm_library")
2+
load("//kotlin/compiler:compiler.bzl", _KOTLIN_STDLIBS = "KOTLIN_STDLIBS")
23

34
# Work around neverlink.
45
kt_jvm_import(
56
name = "kotlinc_jar",
67
jars = [
78
"@com_github_jetbrains_kotlin//:kotlin-compiler",
89
],
9-
deps = [
10-
"//kotlin/compiler:annotations",
11-
"//kotlin/compiler:kotlin-stdlib",
12-
"//kotlin/compiler:kotlin-stdlib-jdk7",
13-
"//kotlin/compiler:kotlin-stdlib-jdk8",
14-
"//kotlin/compiler:kotlinx-coroutines-core-jvm",
15-
"//kotlin/compiler:trove4j",
16-
],
10+
deps = _KOTLIN_STDLIBS,
1711
)
1812

1913
kt_jvm_library(

src/main/kotlin/io/bazel/kotlin/plugin/jdeps/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ kt_bootstrap_library(
2525
"k2/checker/declaration/*.kt",
2626
"k2/checker/expression/*.kt",
2727
]),
28+
kotlinc_opts = [
29+
"-Xcontext-parameters",
30+
],
2831
visibility = ["//src:__subpackages__"],
2932
deps = [
3033
"//kotlin/compiler:kotlin-compiler",

0 commit comments

Comments
 (0)