Skip to content

Commit

Permalink
Support Kotlin 1.8 (#910)
Browse files Browse the repository at this point in the history
* Support Kotlin 1.8
* Update Anvil to 2.4.3-1-8-0-RC
* Use the latest compose release
  • Loading branch information
Bencodes authored Jan 20, 2023
1 parent d7cf3fd commit 113e91b
Show file tree
Hide file tree
Showing 22 changed files with 467 additions and 17 deletions.
3 changes: 1 addition & 2 deletions examples/anvil/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ load("@io_bazel_rules_kotlin//kotlin:core.bzl", "define_kt_toolchain")

define_kt_toolchain(
name = "kotlin_toolchain",
api_version = "1.6",
language_version = "1.6",
jvm_target = "1.8",
)
5 changes: 2 additions & 3 deletions examples/anvil/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ maven_install(
"com.google.dagger:dagger:2.44.2",
"com.google.dagger:dagger-compiler:2.44.2",
"com.google.dagger:dagger-producers:2.44.2",
"com.squareup.anvil:compiler:2.4.3",
"com.squareup.anvil:annotations:2.4.3",
"com.squareup.anvil:compiler:2.4.4",
"com.squareup.anvil:annotations:2.4.4",
"androidx.activity:activity:1.0.0",
"androidx.annotation:annotation:1.1.0",
"androidx.appcompat:appcompat-resources:1.1.0",
Expand All @@ -76,7 +76,6 @@ maven_install(
"androidx.cursoradapter:cursoradapter:1.0.0",
"androidx.customview:customview:1.0.0",
"androidx.drawerlayout:drawerlayout:1.0.0",
"androidx.fragment:fragment:1.0.0",
"androidx.fragment:fragment:1.1.0",
"androidx.interpolator:interpolator:1.0.0",
"androidx.lifecycle:lifecycle-common:2.1.0",
Expand Down
2 changes: 0 additions & 2 deletions examples/jetpack_compose/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ default_java_toolchain(

define_kt_toolchain(
name = "kotlin_toolchain",
api_version = "1.6",
jvm_target = "1.8",
language_version = "1.6",
)

# Define the compose compiler plugin
Expand Down
6 changes: 3 additions & 3 deletions examples/jetpack_compose/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

_COMPOSE_VERSION = "1.2.1"

_COMPOSE_COMPILER_VERSION = "1.3.2"
_COMPOSE_COMPILER_VERSION = "1.4.0"

_KOTLIN_COMPILER_VERSION = "1.7.20"
_KOTLIN_COMPILER_VERSION = "1.8.0"

_KOTLIN_COMPILER_SHA = "5e3c8d0f965410ff12e90d6f8dc5df2fc09fd595a684d514616851ce7e94ae7d"
_KOTLIN_COMPILER_SHA = "0bb9419fac9832a56a3a19cad282f8f2d6f1237d2d467dc8dfe9bd4a2a43c42e"

# Setup Kotlin

Expand Down
4 changes: 2 additions & 2 deletions kotlin/internal/opts.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
# limitations under the License.

load(
"@rkt_1_7//starlark/kotlin:opts.bzl",
"@rkt_1_8//starlark/kotlin:opts.bzl",
_KotlincOptions = "KotlincOptions",
_kotlinc_options_to_flags = "kotlinc_options_to_flags",
_kt_kotlinc_options = "kt_kotlinc_options",
)
load(
"@rkt_1_7//starlark/jvm:opts.bzl",
"@rkt_1_8//starlark/jvm:opts.bzl",
_JavacOptions = "JavacOptions",
_javac_options_to_flags = "javac_options_to_flags",
_kt_javac_options = "kt_javac_options",
Expand Down
5 changes: 3 additions & 2 deletions kotlin/internal/toolchains.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,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.7",
default = "1.8",
values = [
"1.1",
"1.2",
Expand All @@ -132,7 +132,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.7",
default = "1.8",
values = [
"1.1",
"1.2",
Expand All @@ -141,6 +141,7 @@ _kt_toolchain = rule(
"1.5",
"1.6",
"1.7",
"1.8",
],
),
"debug": attr.string_list(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Kotlin2JsTaskExecutor @Inject constructor(
it.addAll(passThroughFlagsList)
it.addAll("-libraries", inputs.librariesList.joinToString(":"))
it.addAll("-output", outputs.js)
it.addAll("-Xuse-deprecated-legacy-compiler")
it.addAll(inputs.kotlinSourcesList)
}
context.whenTracing { printLines("js compile args", args) }
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/io/bazel/kotlin/plugin/SkipCodeGen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisHandlerExtension
/**
* SkipCodeGen registers an extension to skip code generation. Must be the last compiler plugin.
*/
@OptIn(org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi::class)
class SkipCodeGen : ComponentRegistrar {

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.CompilerConfigurationKey

@OptIn(org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi::class)
class JdepsGenCommandLineProcessor : CommandLineProcessor {
companion object {
val COMPILER_PLUGIN_ID = "io.bazel.kotlin.plugin.jdeps.JDepsGen"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor
import org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisHandlerExtension

@OptIn(org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi::class)
class JdepsGenComponentRegistrar : ComponentRegistrar {

override fun registerProjectComponents(
Expand Down
7 changes: 5 additions & 2 deletions src/main/starlark/core/repositories/versions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,21 @@ versions = struct(
sha256 = "5f6412986b351cc569baa6cfde2e8ff8bc527a7bc15af4fe5a49cfd76b73b569",
),
KOTLIN_CURRENT_COMPILER_RELEASE = version(
version = "1.7.22",
version = "1.8.0",
url_templates = [
"https://github.com/JetBrains/kotlin/releases/download/v{version}/kotlin-compiler-{version}.zip",
],
sha256 = "9db4b467743c1aea8a21c08e1c286bc2aeb93f14c7ba2037dbd8f48adc357d83",
sha256 = "0bb9419fac9832a56a3a19cad282f8f2d6f1237d2d467dc8dfe9bd4a2a43c42e",
),
ANDROID = struct(
VERSION = "0.1.1",
SHA = "cd06d15dd8bb59926e4d65f9003bfc20f9da4b2519985c27e190cddc8b7a7806",
URLS = ["https://github.com/bazelbuild/rules_android/archive/v%s.zip" % "0.1.1"],
),
CORE = {
"rkt_1_8": struct(
prefix = "1.8",
),
"rkt_1_7": struct(
prefix = "1.7",
),
Expand Down
13 changes: 13 additions & 0 deletions src/rkt_1_8/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load("@dev_io_bazel_rules_kotlin//src/main/starlark/release:packager.bzl", "release_archive")

release_archive(
name = "pkg",
srcs = ["WORKSPACE"],
src_map = {
"BUILD.release.bazel": "BUILD.bazel",
},
deps = [
"//starlark/jvm:pkg",
"//starlark/kotlin:pkg",
],
)
Empty file added src/rkt_1_8/BUILD.release.bazel
Empty file.
1 change: 1 addition & 0 deletions src/rkt_1_8/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workspace(name = "rkt_1_8")
10 changes: 10 additions & 0 deletions src/rkt_1_8/starlark/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

bzl_library(
name = "starlark",
visibility = ["//visibility:public"],
deps = [
"//starlark/jvm",
"//starlark/kotlin",
],
)
24 changes: 24 additions & 0 deletions src/rkt_1_8/starlark/jvm/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
load("@dev_io_bazel_rules_kotlin//src/main/starlark/release:packager.bzl", "release_archive")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

exports_files(
["opts.bzl"],
visibility = ["//visibility:public"],
)

release_archive(
name = "pkg",
srcs = glob(["*.bzl"]),
src_map = {
"BUILD.release.bazel": "BUILD.bazel",
},
)

bzl_library(
name = "jvm",
srcs = glob(["*.bzl"]),
visibility = ["//visibility:public"],
deps = [
"@dev_io_bazel_rules_kotlin//src/main/starlark",
],
)
Empty file.
92 changes: 92 additions & 0 deletions src/rkt_1_8/starlark/jvm/opts.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
load("@dev_io_bazel_rules_kotlin//src/main/starlark/core/options:derive.bzl", "derive")
load("@dev_io_bazel_rules_kotlin//src/main/starlark/core/options:convert.bzl", "convert")

_JOPTS = {
"warn": struct(
args = dict(
default = "report",
doc = "Control warning behaviour.",
values = ["off", "report", "error"],
),
type = attr.string,
value_to_flag = {
"off": ["-nowarn"],
"error": ["-Werror"],
"report": None,
},
),
"x_ep_disable_all_checks": struct(
args = dict(
default = False,
doc = "See javac -XepDisableAllChecks documentation",
),
type = attr.bool,
value_to_flag = {
True: ["-XepDisableAllChecks"],
},
),
"x_lint": struct(
args = dict(
default = [],
doc = "See javac -Xlint: documentation",
),
type = attr.string_list,
value_to_flag = {
derive.info: derive.repeated_values_for("-Xlint:"),
},
),
"xd_suppress_notes": struct(
args = dict(
default = False,
doc = "See javac -XDsuppressNotes documentation",
),
type = attr.bool,
value_to_flag = {
True: ["-XDsuppressNotes"],
},
),
"x_explicit_api_mode": struct(
args = dict(
default = "off",
doc = "Enable explicit API mode for Kotlin libraries.",
values = ["off", "warning", "strict"],
),
type = attr.string,
value_to_flag = {
"off": None,
"warning": ["-Xexplicit-api=warning"],
"strict": ["-Xexplicit-api=strict"],
},
),
}

def _javac_options_impl(ctx):
return struct(
providers = [
JavacOptions(**{n: getattr(ctx.attr, n, None) for n in _JOPTS}),
],
)

JavacOptions = provider(
fields = {
name: o.args["doc"]
for name, o in _JOPTS.items()
},
)

kt_javac_options = rule(
implementation = _javac_options_impl,
doc = "Define java compiler options for `kt_jvm_*` rules with java sources.",
provides = [JavacOptions],
attrs = {n: o.type(**o.args) for n, o in _JOPTS.items()},
)

def javac_options_to_flags(javac_options):
"""Translate JavacOptions to worker flags
Args:
javac_options of type JavacOptions or None
Returns:
list of flags to add to the command line.
"""
return convert.javac_options_to_flags(_JOPTS, javac_options)
21 changes: 21 additions & 0 deletions src/rkt_1_8/starlark/kotlin/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
load("@dev_io_bazel_rules_kotlin//src/main/starlark/release:packager.bzl", "release_archive")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

exports_files(
["opts.bzl"],
visibility = ["//visibility:public"],
)

release_archive(
name = "pkg",
srcs = glob(["*.bzl"]),
src_map = {
"BUILD.release.bazel": "BUILD.bazel",
},
)

bzl_library(
name = "kotlin",
srcs = glob(["*.bzl"]),
visibility = ["//visibility:public"],
)
Empty file.
Loading

0 comments on commit 113e91b

Please sign in to comment.