diff --git a/MODULE.bazel b/MODULE.bazel index 273d8bd9b..3828307fc 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -20,6 +20,9 @@ use_repo( "com_github_jetbrains_kotlin", "com_github_jetbrains_kotlin_git", "com_github_pinterest_ktlint", + "kotlinx_serialization_core_jvm", + "kotlinx_serialization_json", + "kotlinx_serialization_json_jvm", "released_rules_kotlin", ) diff --git a/MODULE.release.bazel b/MODULE.release.bazel index b2348946a..517e2d1f6 100644 --- a/MODULE.release.bazel +++ b/MODULE.release.bazel @@ -21,6 +21,9 @@ use_repo( "com_github_google_ksp", "com_github_jetbrains_kotlin", "com_github_pinterest_ktlint", + "kotlinx_serialization_core_jvm", + "kotlinx_serialization_json", + "kotlinx_serialization_json_jvm", ) register_toolchains("//kotlin/internal:default_toolchain") diff --git a/docs/kotlin.md b/docs/kotlin.md index e7ed27e35..1cd4d8525 100755 --- a/docs/kotlin.md +++ b/docs/kotlin.md @@ -575,8 +575,8 @@ Call this in the WORKSPACE file to setup the Kotlin rules. | is_bzlmod |

-

| `False` | | compiler_repository_name | for the kotlinc compiler repository. | `"com_github_jetbrains_kotlin"` | | ksp_repository_name |

-

| `"com_github_google_ksp"` | -| compiler_release | version provider from versions.bzl. | `struct(sha256 = "ef578730976154fd2c5968d75af8c2703b3de84a78dffe913f670326e149da3b", url_templates = ["https://github.com/JetBrains/kotlin/releases/download/v{version}/kotlin-compiler-{version}.zip"], version = "2.0.0")` | -| ksp_compiler_release | (internal) version provider from versions.bzl. | `struct(sha256 = "84100aed5b63effa992ce6574b3ba47d2dbb78529752daa4c181e203117ba7de", url_templates = ["https://github.com/google/ksp/releases/download/{version}/artifacts.zip"], version = "2.0.0-1.0.21")` | +| compiler_release | version provider from versions.bzl. | `struct(sha256 = "88d7d8bad362ae4e114a8b9668c6887b8c85f48e340883db0e317e47c8dc2f4f", url_templates = ["https://github.com/JetBrains/kotlin/releases/download/v{version}/kotlin-compiler-{version}.zip"], version = "2.0.10")` | +| ksp_compiler_release | (internal) version provider from versions.bzl. | `struct(sha256 = "e6a79e649ee383b372fa982be89686c10ee42b25e60147b3271a70fd75a9eb19", url_templates = ["https://github.com/google/ksp/releases/download/{version}/artifacts.zip"], version = "2.0.10-1.0.24")` | diff --git a/src/main/kotlin/BUILD.release.bazel b/src/main/kotlin/BUILD.release.bazel index 5f04f0e85..91ad31c96 100644 --- a/src/main/kotlin/BUILD.release.bazel +++ b/src/main/kotlin/BUILD.release.bazel @@ -47,8 +47,14 @@ java_binary( "//kotlin/compiler:symbol-processing-cmdline", "//src/main/kotlin/io/bazel/kotlin/compiler", "@com_github_jetbrains_kotlin//:home", + "@kotlinx_serialization_core_jvm//jar", + "@kotlinx_serialization_json//jar", + "@kotlinx_serialization_json_jvm//jar", ], jvm_flags = [ + "-D@com_github_jetbrains_kotlinx...serialization-core-jvm=$(rlocationpath @kotlinx_serialization_core_jvm//jar)", + "-D@com_github_jetbrains_kotlinx...serialization-json=$(rlocationpath @kotlinx_serialization_json//jar)", + "-D@com_github_jetbrains_kotlinx...serialization-json-jvm=$(rlocationpath @kotlinx_serialization_json_jvm//jar)", "-D@com_github_jetbrains_kotlin...jvm-abi-gen=$(rlocationpath //kotlin/compiler:jvm-abi-gen)", "-D@com_github_jetbrains_kotlin...kotlin-compiler=$(rlocationpath //kotlin/compiler:kotlin-compiler)", "-D@com_github_jetbrains_kotlin...kapt=$(rlocationpath //kotlin/compiler:kotlin-annotation-processing)", diff --git a/src/main/kotlin/io/bazel/kotlin/builder/cmd/BUILD.bazel b/src/main/kotlin/io/bazel/kotlin/builder/cmd/BUILD.bazel index 06363c3b8..b5195827f 100644 --- a/src/main/kotlin/io/bazel/kotlin/builder/cmd/BUILD.bazel +++ b/src/main/kotlin/io/bazel/kotlin/builder/cmd/BUILD.bazel @@ -25,8 +25,14 @@ kt_bootstrap_binary( "//src/main/kotlin:skip-code-gen", "//src/main/kotlin/io/bazel/kotlin/compiler:compiler.jar", "@com_github_jetbrains_kotlin//:home", + "@kotlinx_serialization_core_jvm//jar", + "@kotlinx_serialization_json//jar", + "@kotlinx_serialization_json_jvm//jar", ], jvm_flags = [ + "-D@com_github_jetbrains_kotlinx...serialization-core-jvm=$(rlocationpath @kotlinx_serialization_core_jvm//jar)", + "-D@com_github_jetbrains_kotlinx...serialization-json=$(rlocationpath @kotlinx_serialization_json//jar)", + "-D@com_github_jetbrains_kotlinx...serialization-json-jvm=$(rlocationpath @kotlinx_serialization_json_jvm//jar)", "-D@com_github_jetbrains_kotlin...jvm-abi-gen=$(rlocationpath //kotlin/compiler:jvm-abi-gen)", "-D@com_github_jetbrains_kotlin...kotlin-compiler=$(rlocationpath //kotlin/compiler:kotlin-compiler)", "-D@com_github_jetbrains_kotlin...kapt=$(rlocationpath //kotlin/compiler:kotlin-annotation-processing)", diff --git a/src/main/kotlin/io/bazel/kotlin/builder/toolchain/KotlinToolchain.kt b/src/main/kotlin/io/bazel/kotlin/builder/toolchain/KotlinToolchain.kt index 5f0d0f1af..776770584 100644 --- a/src/main/kotlin/io/bazel/kotlin/builder/toolchain/KotlinToolchain.kt +++ b/src/main/kotlin/io/bazel/kotlin/builder/toolchain/KotlinToolchain.kt @@ -104,6 +104,27 @@ class KotlinToolchain private constructor( ).toPath() } + private val KOTLINX_SERIALIZATION_CORE_JVM by lazy { + BazelRunFiles + .resolveVerifiedFromProperty( + "@com_github_jetbrains_kotlinx...serialization-core-jvm", + ).toPath() + } + + private val KOTLINX_SERIALIZATION_JSON by lazy { + BazelRunFiles + .resolveVerifiedFromProperty( + "@com_github_jetbrains_kotlinx...serialization-json", + ).toPath() + } + + private val KOTLINX_SERIALIZATION_JSON_JVM by lazy { + BazelRunFiles + .resolveVerifiedFromProperty( + "@com_github_jetbrains_kotlinx...serialization-json-jvm", + ).toPath() + } + private val JAVA_HOME by lazy { FileSystems .getDefault() @@ -129,6 +150,9 @@ class KotlinToolchain private constructor( KAPT_PLUGIN.verified().absoluteFile, KSP_SYMBOL_PROCESSING_API.toFile(), KSP_SYMBOL_PROCESSING_CMDLINE.toFile(), + KOTLINX_SERIALIZATION_CORE_JVM.toFile(), + KOTLINX_SERIALIZATION_JSON.toFile(), + KOTLINX_SERIALIZATION_JSON_JVM.toFile(), ) @JvmStatic @@ -142,6 +166,9 @@ class KotlinToolchain private constructor( kaptFile: File, kspSymbolProcessingApi: File, kspSymbolProcessingCommandLine: File, + kotlinxSerializationCoreJvm: File, + kotlinxSerializationJson: File, + kotlinxSerializationJsonJvm: File, ): KotlinToolchain = KotlinToolchain( listOf( @@ -155,6 +182,9 @@ class KotlinToolchain private constructor( jdepsGenFile, kspSymbolProcessingApi, kspSymbolProcessingCommandLine, + kotlinxSerializationCoreJvm, + kotlinxSerializationJson, + kotlinxSerializationJsonJvm, ), jvmAbiGen = CompilerPlugin( diff --git a/src/main/kotlin/io/bazel/kotlin/plugin/jdeps/k2/ClassUsageRecorder.kt b/src/main/kotlin/io/bazel/kotlin/plugin/jdeps/k2/ClassUsageRecorder.kt index bd2cf5083..ac26e1039 100644 --- a/src/main/kotlin/io/bazel/kotlin/plugin/jdeps/k2/ClassUsageRecorder.kt +++ b/src/main/kotlin/io/bazel/kotlin/plugin/jdeps/k2/ClassUsageRecorder.kt @@ -44,13 +44,15 @@ class ClassUsageRecorder( visited: MutableSet> = mutableSetOf(), ) { if (collectTypeArguments) { - coneKotlinType.forEachType { coneType -> - val classId = coneType.classId ?: return@forEachType - if (ANONYMOUS in classId.toString()) return@forEachType - context.session.symbolProvider - .getClassLikeSymbolByClassId(classId) - ?.let { recordClass(it, context, isExplicit, collectTypeArguments, visited) } - } + coneKotlinType.forEachType( + action = { coneType -> + val classId = coneType.classId ?: return@forEachType + if (ANONYMOUS in classId.toString()) return@forEachType + context.session.symbolProvider + .getClassLikeSymbolByClassId(classId) + ?.let { recordClass(it, context, isExplicit, collectTypeArguments, visited) } + }, + ) } else { coneKotlinType.classId?.let { classId -> if (!classId.isLocal) { diff --git a/src/main/starlark/core/repositories/initialize.release.bzl b/src/main/starlark/core/repositories/initialize.release.bzl index 1e97424c1..1ca9dfdd9 100644 --- a/src/main/starlark/core/repositories/initialize.release.bzl +++ b/src/main/starlark/core/repositories/initialize.release.bzl @@ -18,6 +18,7 @@ load( "@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file", + "http_jar", ) load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") load( @@ -71,6 +72,27 @@ def kotlin_repositories( executable = True, ) + maybe( + http_jar, + name = "kotlinx_serialization_core_jvm", + sha256 = versions.KOTLINX_SERIALIZATION_CORE_JVM.sha256, + urls = [url.format(version = versions.KOTLINX_SERIALIZATION_CORE_JVM.version) for url in versions.KOTLINX_SERIALIZATION_CORE_JVM.url_templates], + ) + + maybe( + http_jar, + name = "kotlinx_serialization_json", + sha256 = versions.KOTLINX_SERIALIZATION_JSON.sha256, + urls = [url.format(version = versions.KOTLINX_SERIALIZATION_JSON.version) for url in versions.KOTLINX_SERIALIZATION_JSON.url_templates], + ) + + maybe( + http_jar, + name = "kotlinx_serialization_json_jvm", + sha256 = versions.KOTLINX_SERIALIZATION_JSON_JVM.sha256, + urls = [url.format(version = versions.KOTLINX_SERIALIZATION_JSON_JVM.version) for url in versions.KOTLINX_SERIALIZATION_JSON_JVM.url_templates], + ) + if is_bzlmod: return diff --git a/src/main/starlark/core/repositories/versions.bzl b/src/main/starlark/core/repositories/versions.bzl index 18e055c3a..049285eee 100644 --- a/src/main/starlark/core/repositories/versions.bzl +++ b/src/main/starlark/core/repositories/versions.bzl @@ -61,18 +61,18 @@ versions = struct( sha256 = "a9f923be58fbd32670a17f0b729b1df804af882fa57402165741cb26e5440ca1", ), KOTLIN_CURRENT_COMPILER_RELEASE = version( - version = "2.0.0", + version = "2.0.10", url_templates = [ "https://github.com/JetBrains/kotlin/releases/download/v{version}/kotlin-compiler-{version}.zip", ], - sha256 = "ef578730976154fd2c5968d75af8c2703b3de84a78dffe913f670326e149da3b", + sha256 = "88d7d8bad362ae4e114a8b9668c6887b8c85f48e340883db0e317e47c8dc2f4f", ), KSP_CURRENT_COMPILER_PLUGIN_RELEASE = version( - version = "2.0.0-1.0.21", + version = "2.0.10-1.0.24", url_templates = [ "https://github.com/google/ksp/releases/download/{version}/artifacts.zip", ], - sha256 = "84100aed5b63effa992ce6574b3ba47d2dbb78529752daa4c181e203117ba7de", + sha256 = "e6a79e649ee383b372fa982be89686c10ee42b25e60147b3271a70fd75a9eb19", ), ANDROID = struct( VERSION = "0.1.1", @@ -132,5 +132,26 @@ versions = struct( ], sha256 = "b84ed8546f1969d700ead4546de9f7637e0f058d835e47e865dcbb13c4210aed", ), + KOTLINX_SERIALIZATION_CORE_JVM = version( + version = "1.6.3", + url_templates = [ + "https://repo1.maven.org/maven2/org/jetbrains/kotlinx/kotlinx-serialization-core-jvm/{version}/kotlinx-serialization-core-jvm-{version}.jar", + ], + sha256 = "29c821a8d4e25cbfe4f2ce96cdd4526f61f8f4e69a135f9612a34a81d93b65f1", + ), + KOTLINX_SERIALIZATION_JSON = version( + version = "1.6.3", + url_templates = [ + "https://repo1.maven.org/maven2/org/jetbrains/kotlinx/kotlinx-serialization-json/{version}/kotlinx-serialization-json-{version}.jar", + ], + sha256 = "8c0016890a79ab5980dd520a5ab1a6738023c29aa3b6437c482e0e5fdc06dab1", + ), + KOTLINX_SERIALIZATION_JSON_JVM = version( + version = "1.6.3", + url_templates = [ + "https://repo1.maven.org/maven2/org/jetbrains/kotlinx/kotlinx-serialization-json-jvm/{version}/kotlinx-serialization-json-jvm-{version}.jar", + ], + sha256 = "d3234179bcff1886d53d67c11eca47f7f3cf7b63c349d16965f6db51b7f3dd9a", + ), use_repository = _use_repository, ) diff --git a/src/test/kotlin/io/bazel/kotlin/builder/KotlinAbstractTestBuilder.java b/src/test/kotlin/io/bazel/kotlin/builder/KotlinAbstractTestBuilder.java index 224191238..0327ef58e 100644 --- a/src/test/kotlin/io/bazel/kotlin/builder/KotlinAbstractTestBuilder.java +++ b/src/test/kotlin/io/bazel/kotlin/builder/KotlinAbstractTestBuilder.java @@ -143,7 +143,6 @@ final Path writeFile(DirectoryType dirType, String filename, String[] lines) { } - public final Path writeSourceFile(String filename, String[] lines) { return writeFile(DirectoryType.SOURCES, filename, lines); } @@ -242,7 +241,10 @@ static KotlinToolchain toolchainForTest() { new File(Deps.Dep.fromLabel("//src/main/kotlin:jdeps-gen").singleCompileJar()), new File(Deps.Dep.fromLabel("//kotlin/compiler:kotlin-annotation-processing").singleCompileJar()), new File(Deps.Dep.fromLabel("//kotlin/compiler:symbol-processing-api").singleCompileJar()), - new File(Deps.Dep.fromLabel("//kotlin/compiler:symbol-processing-cmdline").singleCompileJar()) + new File(Deps.Dep.fromLabel("//kotlin/compiler:symbol-processing-cmdline").singleCompileJar()), + new File(Deps.Dep.fromLabel("@kotlinx_serialization_core_jvm//jar").singleCompileJar()), + new File(Deps.Dep.fromLabel("@kotlinx_serialization_json//jar").singleCompileJar()), + new File(Deps.Dep.fromLabel("@kotlinx_serialization_json_jvm//jar").singleCompileJar()) ); } } diff --git a/src/test/kotlin/io/bazel/kotlin/defs.bzl b/src/test/kotlin/io/bazel/kotlin/defs.bzl index a94783daf..7f914191e 100644 --- a/src/test/kotlin/io/bazel/kotlin/defs.bzl +++ b/src/test/kotlin/io/bazel/kotlin/defs.bzl @@ -44,6 +44,9 @@ def kt_rules_test(name, **kwargs): "//kotlin/compiler:kotlin-stdlib-jdk8", "//kotlin/compiler:kotlin-annotation-processing", "@rules_kotlin//kotlin/compiler:kotlin-reflect", + "@kotlinx_serialization_core_jvm//jar", + "@kotlinx_serialization_json//jar", + "@kotlinx_serialization_json_jvm//jar", ] + args["data"]: if dep not in args["data"]: args["data"].append(dep)