Skip to content

Commit f8e5c77

Browse files
authored
Implement Jdeps using K2 APIs (#1166)
* Enable K2 jdeps tests * Update to Kotlin & KSP 2.0.0 * Implement jdeps using K2 APIs * Convert ClassUsageRecorder & checker objects to classes * Allow for overriding of the KSP Kotlin toolchain versions for K2 * Update examples for Kotlin 2.0 * Run ktlint to update formatting
1 parent 61e1a3d commit f8e5c77

26 files changed

+1014
-414
lines changed

examples/anvil/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ load("@rules_kotlin//kotlin:core.bzl", "define_kt_toolchain")
22

33
define_kt_toolchain(
44
name = "kotlin_toolchain",
5+
api_version = "1.9",
6+
language_version = "1.9",
57
)
68

79
platform(

examples/jetpack_compose/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ kt_compiler_plugin(
2222
target_embedded_compiler = True,
2323
visibility = ["//visibility:public"],
2424
deps = [
25-
"@maven//:androidx_compose_compiler_compiler",
25+
"@maven//:org_jetbrains_kotlin_kotlin_compose_compiler_plugin_embeddable",
2626
],
2727
)
2828

examples/jetpack_compose/WORKSPACE

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
22

33
_COMPOSE_VERSION = "1.2.1"
44

5-
_COMPOSE_COMPILER_VERSION = "1.5.9"
5+
_KOTLIN_COMPILER_VERSION = "2.0.0"
66

7-
_KOTLIN_COMPILER_VERSION = "1.9.22"
8-
9-
_KOTLIN_COMPILER_SHA = "88b39213506532c816ff56348c07bbeefe0c8d18943bffbad11063cf97cac3e6"
7+
_KOTLIN_COMPILER_SHA = "ef578730976154fd2c5968d75af8c2703b3de84a78dffe913f670326e149da3b"
108

119
# Setup Kotlin
1210

@@ -48,14 +46,14 @@ load("@rules_jvm_external//:defs.bzl", "maven_install")
4846

4947
maven_install(
5048
artifacts = [
49+
"org.jetbrains.kotlin:kotlin-compose-compiler-plugin-embeddable:{}".format(_KOTLIN_COMPILER_VERSION),
5150
"org.jetbrains.kotlin:kotlin-stdlib:{}".format(_KOTLIN_COMPILER_VERSION),
5251
"androidx.core:core-ktx:1.7.0",
5352
"androidx.appcompat:appcompat:1.4.1",
5453
"androidx.activity:activity-compose:1.4.0",
5554
"androidx.compose.material:material:{}".format(_COMPOSE_VERSION),
5655
"androidx.compose.ui:ui:{}".format(_COMPOSE_VERSION),
5756
"androidx.compose.ui:ui-tooling:{}".format(_COMPOSE_VERSION),
58-
"androidx.compose.compiler:compiler:{}".format(_COMPOSE_COMPILER_VERSION),
5957
"androidx.compose.runtime:runtime:{}".format(_COMPOSE_VERSION),
6058
],
6159
repositories = [

kotlin/internal/toolchains.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ _kt_toolchain = rule(
122122
),
123123
"language_version": attr.string(
124124
doc = "this is the -language_version flag [see](https://kotlinlang.org/docs/reference/compatibility.html)",
125-
default = "1.9",
125+
default = "2.0",
126126
values = [
127127
"1.1",
128128
"1.2",
@@ -138,7 +138,7 @@ _kt_toolchain = rule(
138138
),
139139
"api_version": attr.string(
140140
doc = "this is the -api_version flag [see](https://kotlinlang.org/docs/reference/compatibility.html).",
141-
default = "1.9",
141+
default = "2.0",
142142
values = [
143143
"1.1",
144144
"1.2",

src/main/kotlin/io/bazel/kotlin/builder/tasks/CompileKotlin.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ import io.bazel.worker.WorkerContext
2323
import javax.inject.Inject
2424

2525
class CompileKotlin
26-
@Inject
27-
constructor(
28-
private val builder: KotlinBuilder,
29-
) : Work {
30-
override fun invoke(
31-
ctx: WorkerContext.TaskContext,
32-
args: Iterable<String>,
33-
): Status =
34-
if (builder.build(ctx, args.toList()) != 0) {
35-
Status.ERROR
36-
} else {
37-
Status.SUCCESS
38-
}
39-
}
26+
@Inject
27+
constructor(
28+
private val builder: KotlinBuilder,
29+
) : Work {
30+
override fun invoke(
31+
ctx: WorkerContext.TaskContext,
32+
args: Iterable<String>,
33+
): Status =
34+
if (builder.build(ctx, args.toList()) != 0) {
35+
Status.ERROR
36+
} else {
37+
Status.SUCCESS
38+
}
39+
}

0 commit comments

Comments
 (0)