Skip to content

Commit

Permalink
Add support for Kotlin 2.0.10 (#1216)
Browse files Browse the repository at this point in the history
* Add support for Kotlin 2.0.10

* Support the release path

* Support the release module.bazel

* Pull things out into versions

* Docs
  • Loading branch information
Bencodes authored Sep 12, 2024
1 parent 7b2ba28 commit 2821bbb
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 15 deletions.
3 changes: 3 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

Expand Down
3 changes: 3 additions & 0 deletions MODULE.release.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions docs/kotlin.md
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,8 @@ Call this in the WORKSPACE file to setup the Kotlin rules.
| <a id="kotlin_repositories-is_bzlmod"></a>is_bzlmod | <p align="center"> - </p> | `False` |
| <a id="kotlin_repositories-compiler_repository_name"></a>compiler_repository_name | for the kotlinc compiler repository. | `"com_github_jetbrains_kotlin"` |
| <a id="kotlin_repositories-ksp_repository_name"></a>ksp_repository_name | <p align="center"> - </p> | `"com_github_google_ksp"` |
| <a id="kotlin_repositories-compiler_release"></a>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")` |
| <a id="kotlin_repositories-ksp_compiler_release"></a>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")` |
| <a id="kotlin_repositories-compiler_release"></a>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")` |
| <a id="kotlin_repositories-ksp_compiler_release"></a>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")` |


<a id="versions.use_repository"></a>
Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/BUILD.release.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/io/bazel/kotlin/builder/cmd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -142,6 +166,9 @@ class KotlinToolchain private constructor(
kaptFile: File,
kspSymbolProcessingApi: File,
kspSymbolProcessingCommandLine: File,
kotlinxSerializationCoreJvm: File,
kotlinxSerializationJson: File,
kotlinxSerializationJsonJvm: File,
): KotlinToolchain =
KotlinToolchain(
listOf(
Expand All @@ -155,6 +182,9 @@ class KotlinToolchain private constructor(
jdepsGenFile,
kspSymbolProcessingApi,
kspSymbolProcessingCommandLine,
kotlinxSerializationCoreJvm,
kotlinxSerializationJson,
kotlinxSerializationJsonJvm,
),
jvmAbiGen =
CompilerPlugin(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ class ClassUsageRecorder(
visited: MutableSet<Pair<ClassId, Boolean>> = 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) {
Expand Down
22 changes: 22 additions & 0 deletions src/main/starlark/core/repositories/initialize.release.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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

Expand Down
29 changes: 25 additions & 4 deletions src/main/starlark/core/repositories/versions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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())
);
}
}
3 changes: 3 additions & 0 deletions src/test/kotlin/io/bazel/kotlin/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2821bbb

Please sign in to comment.