Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin 1.5 support #577

Merged
merged 13 commits into from
Sep 3, 2021
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ load("@io_bazel_rules_kotlin//kotlin:core.bzl", "define_kt_toolchain")

define_kt_toolchain(
name = "kotlin_toolchain",
api_version = KOTLIN_LANGUAGE_LEVEL, # "1.1", "1.2", "1.3", or "1.4"
api_version = KOTLIN_LANGUAGE_LEVEL, # "1.1", "1.2", "1.3", "1.4", or "1.5"
jvm_target = JAVA_LANGUAGE_LEVEL, # "1.6", "1.8", "9", "10", "11", "12", or "13",
language_version = KOTLIN_LANGUAGE_LEVEL, # "1.1", "1.2", "1.3", or "1.4"
language_version = KOTLIN_LANGUAGE_LEVEL, # "1.1", "1.2", "1.3", "1.4", or "1.5"
)
```

Expand Down
4 changes: 2 additions & 2 deletions docs/kotlin.md
Original file line number Diff line number Diff line change
Expand Up @@ -398,15 +398,15 @@ kt_kotlinc_options(<a href="#kt_kotlinc_options-name">name</a>, <a href="#kt_kot
|<a id="kt_kotlinc_options-include_stdlibs"></a>include_stdlibs | Don't automatically include the Kotlin standard libraries into the classpath (stdlib and reflect). | String | optional | "all" |
|<a id="kt_kotlinc_options-java_parameters"></a>java_parameters | Generate metadata for Java 1.8+ reflection on method parameters. | Boolean | optional | False |
|<a id="kt_kotlinc_options-warn"></a>warn | Control warning behaviour. | String | optional | "report" |
|<a id="kt_kotlinc_options-x_allow_jvm_ir_dependencies"></a>x_allow_jvm_ir_dependencies | Suppress errors thrown when using dependencies not compiled by the IR backend. | Boolean | optional | False |
|<a id="kt_kotlinc_options-x_allow_jvm_ir_dependencies"></a>x_allow_jvm_ir_dependencies | Suppress errors thrown when using dependencies not compiled by the IR backend. Only available in 1.4. | Boolean | optional | False |
|<a id="kt_kotlinc_options-x_allow_result_return_type"></a>x_allow_result_return_type | Enable kotlin.Result as a return type | Boolean | optional | False |
|<a id="kt_kotlinc_options-x_inline_classes"></a>x_inline_classes | Enable experimental inline classes | Boolean | optional | False |
|<a id="kt_kotlinc_options-x_jvm_default"></a>x_jvm_default | Specifies that a JVM default method should be generated for non-abstract Kotlin interface member. | String | optional | "off" |
|<a id="kt_kotlinc_options-x_multi_platform"></a>x_multi_platform | Enable experimental language support for multi-platform projects | Boolean | optional | False |
|<a id="kt_kotlinc_options-x_no_optimized_callable_references"></a>x_no_optimized_callable_references | Do not use optimized callable reference superclasses. Available from 1.4. | Boolean | optional | False |
|<a id="kt_kotlinc_options-x_skip_prerelease_check"></a>x_skip_prerelease_check | Suppress errors thrown when using pre-release classes. | Boolean | optional | False |
|<a id="kt_kotlinc_options-x_use_experimental"></a>x_use_experimental | Allow the experimental language features. | Boolean | optional | True |
|<a id="kt_kotlinc_options-x_use_ir"></a>x_use_ir | Enable or disable the experimental IR backend. | Boolean | optional | False |
|<a id="kt_kotlinc_options-x_use_ir"></a>x_use_ir | Enable or disable the experimental IR backend. Only available in 1.4. | Boolean | optional | False |


<a name="#define_kt_toolchain"></a>
Expand Down
8 changes: 1 addition & 7 deletions examples/android/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories", "

kotlin_repositories()

load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains")

kt_register_toolchains()
register_toolchains("//bzl:experimental_toolchain")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

Expand Down Expand Up @@ -90,7 +88,3 @@ http_archive(
sha256 = "4ba8f4ab0ff85f2484287ab06c0d871dcb31cc54d439457d28fd4ae14b18450a",
url = "https://github.com/bazelbuild/rules_pkg/releases/download/0.2.4/rules_pkg-0.2.4.tar.gz",
)

kotlin_repositories()

register_toolchains("//bzl:experimental_toolchain")
4 changes: 2 additions & 2 deletions examples/android/bzl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ kt_javac_options(

define_kt_toolchain(
name = "experimental_toolchain",
api_version = "1.4",
api_version = "1.5",
experimental_reduce_classpath_mode = "KOTLINBUILDER_REDUCED",
experimental_report_unused_deps = "warn",
experimental_strict_kotlin_deps = "warn",
experimental_use_abi_jars = True,
javac_options = ":default_javac_options",
kotlinc_options = ":default_kotlinc_options",
language_version = "1.4",
language_version = "1.5",
)
8 changes: 4 additions & 4 deletions examples/anvil/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ maven_install(
"com.google.dagger:dagger:2.35.1",
"com.google.dagger:dagger-compiler:2.35.1",
"com.google.dagger:dagger-producers:2.35.1",
"com.squareup.anvil:compiler:2.0.10",
"com.squareup.anvil:annotations:2.0.10",
"com.squareup.anvil:compiler:2.2.2",
"com.squareup.anvil:annotations:2.2.2",
"androidx.activity:activity:1.0.0",
"androidx.annotation:annotation:1.1.0",
"androidx.appcompat:appcompat-resources:1.1.0",
Expand Down Expand Up @@ -104,10 +104,10 @@ maven_install(
"com.google.android.material:material:1.1.0",
"javax.inject:javax.inject:1",
"junit:junit:4.13",
"org.jetbrains.kotlin:kotlin-test:1.3.50",
"org.jetbrains.kotlin:kotlin-test:1.5.10",
"com.google.truth:truth:1.0.1",
"org.jetbrains:annotations:13.0",
"org.jetbrains.kotlin:kotlin-compiler-embeddable:1.3.72",
"org.jetbrains.kotlin:kotlin-compiler-embeddable:1.5.10",
],
excluded_artifacts = [
"org.jetbrains.kotlin:kotlin-stdlib",
Expand Down
6 changes: 2 additions & 4 deletions examples/jetpack_compose/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ default_java_toolchain(

kt_kotlinc_options(
name = "kt_kotlinc_options",
x_allow_jvm_ir_dependencies = True,
x_use_ir = True,
)

kt_javac_options(
Expand All @@ -23,12 +21,12 @@ kt_javac_options(

define_kt_toolchain(
name = "kotlin_toolchain",
api_version = "1.4",
api_version = "1.5",
experimental_use_abi_jars = False,
javac_options = "//:kt_javac_options",
jvm_target = "1.8",
kotlinc_options = "//:kt_kotlinc_options",
language_version = "1.4",
language_version = "1.5",
)

# Define the compose compiler plugin
Expand Down
10 changes: 6 additions & 4 deletions kotlin/internal/toolchains.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ load("@io_bazel_rules_kotlin//kotlin:toolchains.bzl", "define_kt_toolchain")

define_kt_toolchain(
name= "custom_toolchain",
api_version = "1.4",
language_version = "1.4",
api_version = "1.5",
language_version = "1.5",
)
```
and then register it in the `WORKSPACE`:
Expand Down Expand Up @@ -123,22 +123,24 @@ _kt_toolchain = rule(
),
"language_version": attr.string(
doc = "this is the -language_version flag [see](https://kotlinlang.org/docs/reference/compatibility.html)",
default = "1.4",
default = "1.5",
values = [
"1.1",
"1.2",
"1.3",
"1.4",
"1.5",
],
),
"api_version": attr.string(
doc = "this is the -api_version flag [see](https://kotlinlang.org/docs/reference/compatibility.html).",
default = "1.4",
default = "1.5",
values = [
"1.1",
"1.2",
"1.3",
"1.4",
"1.5",
],
),
"debug": attr.string_list(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ class KotlinBuilder @Inject internal constructor(
label = argMap.mandatorySingle(JavaBuilderFlags.TARGET_LABEL)
argMap.mandatorySingle(JavaBuilderFlags.RULE_KIND).split("_").also {
check(it.size == 3 && it[0] == "kt") { "invalid rule kind $it" }
platform = checkNotNull(Platform.valueOf(it[1].toUpperCase())) {
platform = checkNotNull(Platform.valueOf(it[1].uppercase())) {
"unrecognized platform ${it[1]}"
}
ruleKind = checkNotNull(RuleKind.valueOf(it[2].toUpperCase())) {
ruleKind = checkNotNull(RuleKind.valueOf(it[2].uppercase())) {
"unrecognized rule kind ${it[2]}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import java.util.Collections

/** Utility class for getting runfiles on windows and *nix. */
object BazelRunFiles {
private val isWindows = System.getProperty("os.name").toLowerCase().indexOf("win") >= 0
private val isWindows = System.getProperty("os.name").lowercase().indexOf("win") >= 0

/**
* Populated on windows. The RUNFILES_MANIFEST_FILE is set on platforms other then windows but it can be empty,]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import java.io.File

val JvmCompilationTask.Inputs.joinedClasspath: String get() = this.classpathList.joinToString(File.pathSeparator)

val CompilationTaskInfo.bazelRuleKind: String get() = "kt_${platform.name.toLowerCase()}_${ruleKind.name.toLowerCase()}"
val CompilationTaskInfo.bazelRuleKind: String get() = "kt_${platform.name.lowercase()}_${ruleKind.name.lowercase()}"

fun Iterator<String>.partitionJvmSources(kt: (String) -> Unit, java: (String) -> Unit) {
forEach {
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/io/bazel/worker/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ kt_bootstrap_library(
],
deps = [
":worker_proto",
"@kotlin_rules_maven//:org_jetbrains_kotlinx_kotlinx_coroutines_core",
"@kotlin_rules_maven//:org_jetbrains_kotlinx_kotlinx_coroutines_core_jvm",
],
)
3 changes: 0 additions & 3 deletions src/main/starlark/core/repositories/rules_stardoc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@ def _rules_stardoc_repository_impl(repository_ctx):
sha256 = attrs.sha256,
stripPrefix = attrs.strip_prefix,
)
print("%s prepping" % attrs.name)
for src in attrs.starlark_packages:
path = repository_ctx.path(src)
build = path.get_child("BUILD")
contents = ""
if build.exists:
contents = repository_ctx.read(build)
print("%s prepping %s" % (attrs.name, contents))
print("%s", path.readdir())
repository_ctx.file(
"%s/BUILD" % path,
content = LOAD + contents + RULE_TEMPLATE.format(
Expand Down
8 changes: 4 additions & 4 deletions src/main/starlark/core/repositories/setup.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ def kt_configure():
"javax.inject:javax.inject:1",
"org.pantsbuild:jarjar:1.7.2",
"org.jetbrains.kotlinx:atomicfu-js:0.15.2",
"org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2",
"org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.4.2",
"org.jetbrains.kotlinx:kotlinx-coroutines-test:1.4.2",
"org.jetbrains.kotlinx:kotlinx-coroutines-debug:1.4.2",
"org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0",
"org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.5.0",
"org.jetbrains.kotlinx:kotlinx-coroutines-test:1.5.0",
"org.jetbrains.kotlinx:kotlinx-coroutines-debug:1.5.0",
"org.jetbrains.kotlinx:kotlinx-serialization-runtime:1.0-M1-1.4.0-rc",
],
repositories = [
Expand Down
4 changes: 2 additions & 2 deletions src/main/starlark/core/repositories/versions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ versions = struct(
IO_BAZEL_STARDOC_SHA = "6d07d18c15abb0f6d393adbd6075cd661a2219faab56a9517741f0fc755f6f3c",
BAZEL_JAVA_LAUNCHER_VERSION = "5.0.0-pre.20210510.2",
KOTLIN_CURRENT_COMPILER_RELEASE = version(
version = "1.4.20",
version = "1.5.10",
url_templates = [
"https://github.com/JetBrains/kotlin/releases/download/v{version}/kotlin-compiler-{version}.zip",
],
sha256 = "11db93a4d6789e3406c7f60b9f267eba26d6483dcd771eff9f85bb7e9837011f",
sha256 = "2f8de1d73b816354055ff6a4b974b711c11ad55a68b948ed30b38155706b3c4e",
),
ANDROID = struct(
VERSION = "0.1.1",
Expand Down
6 changes: 6 additions & 0 deletions src/main/starlark/release_archive/repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ def archive_repository_implementation(repository_ctx):
archive = release_artifact,
)

# update release when the contents change.
return [
repository_ctx.path("../../%s" % release_archive.workspace_root),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well this seems important. I'm a little shocked it didn't have this before.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad. Didn't think that i'd need to tell it that the change happened.

]
return []

# not windows compatible.
def _find_workspace(attr, environ, path):
if attr.local_repository_path_env in environ:
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/io/bazel/kotlin/KotlinJvm13Test.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.junit.Test
class KotlinJvm13Test {
@Test
fun testFoo() {
when (val foo = "TryIng Mixed Case".toLowerCase()) {
when (val foo = "TryIng Mixed Case".lowercase()) {
"trying mixed case" -> {
println(foo)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ public final void resetForNext() {
KotlinToolchainInfo.newBuilder()
.setCommon(
KotlinToolchainInfo.Common.newBuilder()
.setApiVersion("1.4")
.setApiVersion("1.5")
.setCoroutines("enabled")
.setLanguageVersion("1.4"))
.setLanguageVersion("1.5"))
.setJvm(KotlinToolchainInfo.Jvm.newBuilder().setJvmTarget("1.8")));
try {
this.instanceRoot = Files.createTempDirectory(BAZEL_TEST_DIR, label);
Expand Down