Skip to content

Commit

Permalink
Implement Jdeps using K2 APIs (#1166)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jbarr21 authored Aug 20, 2024
1 parent 61e1a3d commit f8e5c77
Show file tree
Hide file tree
Showing 26 changed files with 1,014 additions and 414 deletions.
2 changes: 2 additions & 0 deletions examples/anvil/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ load("@rules_kotlin//kotlin:core.bzl", "define_kt_toolchain")

define_kt_toolchain(
name = "kotlin_toolchain",
api_version = "1.9",
language_version = "1.9",
)

platform(
Expand Down
2 changes: 1 addition & 1 deletion examples/jetpack_compose/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ kt_compiler_plugin(
target_embedded_compiler = True,
visibility = ["//visibility:public"],
deps = [
"@maven//:androidx_compose_compiler_compiler",
"@maven//:org_jetbrains_kotlin_kotlin_compose_compiler_plugin_embeddable",
],
)

Expand Down
8 changes: 3 additions & 5 deletions examples/jetpack_compose/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

_COMPOSE_VERSION = "1.2.1"

_COMPOSE_COMPILER_VERSION = "1.5.9"
_KOTLIN_COMPILER_VERSION = "2.0.0"

_KOTLIN_COMPILER_VERSION = "1.9.22"

_KOTLIN_COMPILER_SHA = "88b39213506532c816ff56348c07bbeefe0c8d18943bffbad11063cf97cac3e6"
_KOTLIN_COMPILER_SHA = "ef578730976154fd2c5968d75af8c2703b3de84a78dffe913f670326e149da3b"

# Setup Kotlin

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

maven_install(
artifacts = [
"org.jetbrains.kotlin:kotlin-compose-compiler-plugin-embeddable:{}".format(_KOTLIN_COMPILER_VERSION),
"org.jetbrains.kotlin:kotlin-stdlib:{}".format(_KOTLIN_COMPILER_VERSION),
"androidx.core:core-ktx:1.7.0",
"androidx.appcompat:appcompat:1.4.1",
"androidx.activity:activity-compose:1.4.0",
"androidx.compose.material:material:{}".format(_COMPOSE_VERSION),
"androidx.compose.ui:ui:{}".format(_COMPOSE_VERSION),
"androidx.compose.ui:ui-tooling:{}".format(_COMPOSE_VERSION),
"androidx.compose.compiler:compiler:{}".format(_COMPOSE_COMPILER_VERSION),
"androidx.compose.runtime:runtime:{}".format(_COMPOSE_VERSION),
],
repositories = [
Expand Down
4 changes: 2 additions & 2 deletions kotlin/internal/toolchains.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ _kt_toolchain = rule(
),
"language_version": attr.string(
doc = "this is the -language_version flag [see](https://kotlinlang.org/docs/reference/compatibility.html)",
default = "1.9",
default = "2.0",
values = [
"1.1",
"1.2",
Expand All @@ -138,7 +138,7 @@ _kt_toolchain = rule(
),
"api_version": attr.string(
doc = "this is the -api_version flag [see](https://kotlinlang.org/docs/reference/compatibility.html).",
default = "1.9",
default = "2.0",
values = [
"1.1",
"1.2",
Expand Down
28 changes: 14 additions & 14 deletions src/main/kotlin/io/bazel/kotlin/builder/tasks/CompileKotlin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ import io.bazel.worker.WorkerContext
import javax.inject.Inject

class CompileKotlin
@Inject
constructor(
private val builder: KotlinBuilder,
) : Work {
override fun invoke(
ctx: WorkerContext.TaskContext,
args: Iterable<String>,
): Status =
if (builder.build(ctx, args.toList()) != 0) {
Status.ERROR
} else {
Status.SUCCESS
}
}
@Inject
constructor(
private val builder: KotlinBuilder,
) : Work {
override fun invoke(
ctx: WorkerContext.TaskContext,
args: Iterable<String>,
): Status =
if (builder.build(ctx, args.toList()) != 0) {
Status.ERROR
} else {
Status.SUCCESS
}
}
Loading

0 comments on commit f8e5c77

Please sign in to comment.