initial toolchain implementation, enables coroutines and also reorganize doc wireup
diff --git a/Makefile b/Makefile
index aa1cc29..21b4d4b 100644
--- a/Makefile
+++ b/Makefile
@@ -7,10 +7,10 @@
buildifier -mode=fix -v kotlin/rules/*.bzl
docs.regen:
- bazel build //kotlin:docs
- unzip -o bazel-bin/kotlin/docs-skydoc.zip -d docs
+ bazel build //docs
+ unzip -o bazel-bin/docs/docs-skydoc.zip -d docs
docs.preview_local:
- bazel build //kotlin:docs --define local=1
- unzip -o bazel-bin/kotlin/docs-skydoc.zip -d /tmp/rules_kotlin
+ bazel build //docs --define local=1
+ unzip -o bazel-bin/docs/docs-skydoc.zip -d /tmp/rules_kotlin
open /tmp/rules_kotlin/kotlin/kotlin.html
diff --git a/README.md b/README.md
index 81b5cce..8b5acd4 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,10 @@
[Skydoc documentation](https://bazelbuild.github.io/rules_kotlin)
# Announcements
+* <b>February 15, 2018.</b>. Toolchains for the JVM rules. Currently this allow tweaking:
+ * The JVM target (bytecode level).
+ * API and Language levels.
+ * Coroutines, enabled by default.
* <b>February 9, 2018.</b> Annotation processing.
* <b>February 5, 2018. JVM rule name change:</b> the prefix has changed from `kotlin_` to `kt_jvm_`.
diff --git a/WORKSPACE b/WORKSPACE
index 085dcf6..72bbc2a 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -29,8 +29,9 @@
load("@io_bazel_skydoc//skylark:skylark.bzl", "skydoc_repositories")
skydoc_repositories()
-load("//kotlin:kotlin.bzl", "kotlin_repositories")
+load("//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains")
kotlin_repositories()
+kt_register_toolchains()
# test and example dependencies.
maven_jar(name = "junit_junit",artifact = "junit:junit:jar:4.12")
diff --git a/docs/BUILD b/docs/BUILD
new file mode 100644
index 0000000..0ce6af1
--- /dev/null
+++ b/docs/BUILD
@@ -0,0 +1,34 @@
+load("@io_bazel_skydoc//skylark:skylark.bzl", "skylark_doc", "skylark_library" )
+
+skylark_library(
+ name = "doc_public",
+ srcs = ["//kotlin:kotlin.bzl"],
+ visibility=["//visibility:private"]
+)
+
+skylark_library(
+ name = "doc_toolchains",
+ srcs = ["//kotlin:toolchains.bzl"],
+ visibility=["//visibility:private"]
+)
+
+skylark_doc(
+ name = "docs",
+ deps = [
+ ":doc_public",
+ ":doc_toolchains"
+ ],
+ format = "html",
+ site_root = select({
+ ":local": "/tmp/rules_kotlin",
+ "//conditions:default": "https://bazelbuild.github.io/rules_kotlin"
+ }),
+ visibility = ["//visibility:public"]
+)
+
+config_setting(
+ name = "local",
+ values = {
+ "define": "local=1",
+ }
+)
\ No newline at end of file
diff --git a/docs/index.html b/docs/index.html
index c0f2f8f..60c7bc9 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -58,6 +58,17 @@
</li>
</ul>
</li>
+<li>
+ <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html">Kotlin Toolchains</a>
+ <ul>
+ <li><a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html#overview">Overview</a></li>
+ <li>
+ <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html#kt_jvm_toolchain">
+ kt_jvm_toolchain
+ </a>
+ </li>
+ </ul>
+</li>
</ul>
</nav>
@@ -72,6 +83,7 @@
<h2>Rule sets</h2>
<ul>
<li><a href="#kotlin">Kotlin Rules</a></li>
+ <li><a href="#toolchains">Kotlin Toolchains</a></li>
</ul>
</nav>
@@ -149,6 +161,70 @@
</td>
</tr>
+ <tr>
+ <td>
+ <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/kotlin.html#kt_register_toolchains">
+ <code>kt_register_toolchains</code>
+ </a>
+ </td>
+ <td>
+ <p>register all default toolchains</p>
+
+ </td>
+ </tr>
+ </tbody>
+</table>
+<h2><a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html">Kotlin Toolchains</a></h2>
+
+<h3>Rules</h3>
+<table class="overview-table">
+ <colgroup>
+ <col class="col-name" />
+ <col class="col-description" />
+ </colgroup>
+ <tbody>
+ <tr>
+ <td>
+ <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html#kt_jvm_toolchain">
+ <code>kt_jvm_toolchain</code>
+ </a>
+ </td>
+ <td>
+ <p>The kotlin jvm toolchain</p>
+
+ </td>
+ </tr>
+ </tbody>
+</table>
+<h3>Macros</h3>
+<table class="overview-table">
+ <colgroup>
+ <col class="col-name" />
+ <col class="col-description" />
+ </colgroup>
+ <tbody>
+ <tr>
+ <td>
+ <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html#define_kt_jvm_toolchain">
+ <code>define_kt_jvm_toolchain</code>
+ </a>
+ </td>
+ <td>
+ <p>Define a Kotlin JVM Toolchain, the name is used in the <code>toolchain</code> rule so can be used to register the toolchain in the WORKSPACE file.</p>
+
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html#kt_register_jvm_toolchain">
+ <code>kt_register_jvm_toolchain</code>
+ </a>
+ </td>
+ <td>
+ <p>Register the default JVM toolchain.</p>
+
+ </td>
+ </tr>
</tbody>
</table>
diff --git a/docs/kotlin/kotlin.html b/docs/kotlin/kotlin.html
index b2a3fd5..38077ff 100644
--- a/docs/kotlin/kotlin.html
+++ b/docs/kotlin/kotlin.html
@@ -58,6 +58,17 @@
</li>
</ul>
</li>
+<li>
+ <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html">Kotlin Toolchains</a>
+ <ul>
+ <li><a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html#overview">Overview</a></li>
+ <li>
+ <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html#kt_jvm_toolchain">
+ kt_jvm_toolchain
+ </a>
+ </li>
+ </ul>
+</li>
</ul>
</nav>
@@ -79,6 +90,7 @@
<h2>Macros</h2>
<ul>
<li><a href="#kotlin_repositories">kotlin_repositories</a></li>
+ <li><a href="#kt_register_toolchains">kt_register_toolchains</a></li>
</ul>
</nav>
<hr>
@@ -90,8 +102,9 @@
remote = "https://github.com/bazelbuild/rules_kotlin.git",
commit = "<COMMIT_HASH>",
)
-load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories")
+load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains")
kotlin_repositories(kotlin_release_version = "1.2.21")
+kt_register_toolchains()
</code></pre>
<p>To enable persistent worker support, add the following to the appropriate <code>bazelrc</code> file:</p>
<pre><code>build --strategy=KotlinCompile=worker
@@ -149,6 +162,9 @@
<pre>kotlin_repositories(<a href="#kotlin_repositories.kotlin_release_version">kotlin_release_version</a>)</pre>
<p>Call this in the WORKSPACE file to setup the Kotlin rules.</p>
+<p>Args:a
+ kotlin_release_version: The kotlin compiler release version. If this is not set the latest release version is
+ chosen by default.</p>
<h3 id="kotlin_repositories_args">Attributes</h3>
@@ -163,14 +179,22 @@
<td><code>kotlin_release_version</code></td>
<td>
<p><code>Unknown; Optional</code></p>
- <p>The kotlin compiler release version. If this is not set the latest release version is
-chosen by default.</p>
+
</td>
</tr>
</tbody>
</table>
<hr>
+ <h2 id="kt_register_toolchains">kt_register_toolchains</h2>
+
+ <pre>kt_register_toolchains()</pre>
+
+ <p>register all default toolchains</p>
+
+
+ <hr>
+
<h2 id="kt_jvm_binary">kt_jvm_binary</h2>
<pre>kt_jvm_binary(<a href="#kt_jvm_binary.name">name</a>, <a href="#kt_jvm_binary.deps">deps</a>, <a href="#kt_jvm_binary.data">data</a>, <a href="#kt_jvm_binary.resources">resources</a>, <a href="#kt_jvm_binary.srcs">srcs</a>, <a href="#kt_jvm_binary.jvm_flags">jvm_flags</a>, <a href="#kt_jvm_binary.main_class">main_class</a>, <a href="#kt_jvm_binary.plugins">plugins</a>, <a href="#kt_jvm_binary.resource_jars">resource_jars</a>, <a href="#kt_jvm_binary.resource_strip_prefix">resource_strip_prefix</a>, <a href="#kt_jvm_binary.runtime_deps">runtime_deps</a>)</pre>
diff --git a/docs/kotlin/toolchains.html b/docs/kotlin/toolchains.html
new file mode 100644
index 0000000..8b7764f
--- /dev/null
+++ b/docs/kotlin/toolchains.html
@@ -0,0 +1,243 @@
+
+
+<!--
+Documentation generated by Skydoc
+-->
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width initial-scale=1" />
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
+
+ <title>Kotlin Toolchains</title>
+
+ <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,600,700" type="text/css">
+ <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
+ <link rel="stylesheet" href="https://code.getmdl.io/1.1.1/material.green-light_blue.min.css">
+ <script defer src="https://code.getmdl.io/1.1.1/material.min.js"></script>
+ <link rel="stylesheet" href="https://bazelbuild.github.io/rules_kotlin/main.css">
+ </head>
+ <body>
+ <div class="mdl-layout mdl-js-layout mdl-layout--fixed-drawer
+ mdl-layout--fixed-header">
+ <header class="mdl-layout__header">
+ <div class="mdl-layout__header-row">
+ <span class="mdl-layout-title">Kotlin Toolchains</span>
+ </div>
+ </header>
+ <div class="mdl-layout__drawer">
+ <span class="mdl-layout-title">Bazel</span>
+ <nav class="drawer-nav">
+ <ul class="drawer-nav">
+
+<li><a href="https://bazelbuild.github.io/rules_kotlin/index.html">Overview</a></li>
+<li>
+ <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/kotlin.html">Kotlin Rules</a>
+ <ul>
+ <li><a href="https://bazelbuild.github.io/rules_kotlin/kotlin/kotlin.html#overview">Overview</a></li>
+ <li>
+ <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/kotlin.html#kt_jvm_binary">
+ kt_jvm_binary
+ </a>
+ </li>
+ <li>
+ <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/kotlin.html#kt_jvm_import">
+ kt_jvm_import
+ </a>
+ </li>
+ <li>
+ <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/kotlin.html#kt_jvm_library">
+ kt_jvm_library
+ </a>
+ </li>
+ <li>
+ <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/kotlin.html#kt_jvm_test">
+ kt_jvm_test
+ </a>
+ </li>
+ </ul>
+</li>
+<li>
+ <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html">Kotlin Toolchains</a>
+ <ul>
+ <li><a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html#overview">Overview</a></li>
+ <li>
+ <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html#kt_jvm_toolchain">
+ kt_jvm_toolchain
+ </a>
+ </li>
+ </ul>
+</li>
+
+ </ul>
+ </nav>
+ </div>
+
+ <main class="mdl-layout__content">
+ <div class="page-content">
+ <h1>Kotlin Toolchains</h1>
+
+<nav class="toc">
+ <h2><a href="#overview">Overview</a></h2>
+ <h2>Rules</h2>
+ <ul>
+ <li><a href="#kt_jvm_toolchain">kt_jvm_toolchain</a></li>
+ </ul>
+ <h2>Macros</h2>
+ <ul>
+ <li><a href="#define_kt_jvm_toolchain">define_kt_jvm_toolchain</a></li>
+ <li><a href="#kt_register_jvm_toolchain">kt_register_jvm_toolchain</a></li>
+ </ul>
+</nav>
+ <hr>
+ <h2 id="overview">Overview</h2>
+ <p>This file contains macros for defining and registering specific toolchains.</p>
+<h3>Examples</h3>
+<p>To override a tool chain use the appropriate macro in a <code>BUILD</code> file to declare the toolchain:</p>
+<pre><code class="lang-bzl">load("@io_bazel_rules_kotlin//kotlin:toolchains.bzl", "define_kt_jvm_toolchain")
+
+define_kt_jvm_toolchain(
+ name= "custom_toolchain",
+ api_version = "1.1",
+ language_version = "1.1",
+)
+</code></pre>
+<p>and then register it in the <code>WORKSPACE</code>:</p>
+<pre><code class="lang-bzl">register_toolchains("//:custom_toolchain")
+</code></pre>
+
+ <hr>
+
+ <h2 id="define_kt_jvm_toolchain">define_kt_jvm_toolchain</h2>
+
+ <pre>define_kt_jvm_toolchain(<a href="#define_kt_jvm_toolchain.name">name</a>, <a href="#define_kt_jvm_toolchain.language_version">language_version</a>, <a href="#define_kt_jvm_toolchain.api_version">api_version</a>, <a href="#define_kt_jvm_toolchain.jvm_target">jvm_target</a>, <a href="#define_kt_jvm_toolchain.coroutines">coroutines</a>)</pre>
+
+ <p>Define a Kotlin JVM Toolchain, the name is used in the <code>toolchain</code> rule so can be used to register the toolchain in the WORKSPACE file.</p>
+
+
+ <h3 id="define_kt_jvm_toolchain_args">Attributes</h3>
+
+<table class="params-table">
+ <colgroup>
+ <col class="col-param" />
+ <col class="col-description" />
+ </colgroup>
+ <tbody>
+ <tr id="define_kt_jvm_toolchain.name">
+ <td><code>name</code></td>
+ <td>
+ <p><code><a href="https://bazel.build/docs/build-ref.html#name">Name</a>; Required</code></p>
+ <p>A unique name for this rule.</p>
+ </td>
+ </tr>
+ <tr id="define_kt_jvm_toolchain.language_version">
+ <td><code>language_version</code></td>
+ <td>
+ <p><code>Unknown; Optional</code></p>
+
+ </td>
+ </tr>
+ <tr id="define_kt_jvm_toolchain.api_version">
+ <td><code>api_version</code></td>
+ <td>
+ <p><code>Unknown; Optional</code></p>
+
+ </td>
+ </tr>
+ <tr id="define_kt_jvm_toolchain.jvm_target">
+ <td><code>jvm_target</code></td>
+ <td>
+ <p><code>Unknown; Optional</code></p>
+
+ </td>
+ </tr>
+ <tr id="define_kt_jvm_toolchain.coroutines">
+ <td><code>coroutines</code></td>
+ <td>
+ <p><code>Unknown; Optional</code></p>
+
+ </td>
+ </tr>
+ </tbody>
+</table>
+ <hr>
+
+ <h2 id="kt_register_jvm_toolchain">kt_register_jvm_toolchain</h2>
+
+ <pre>kt_register_jvm_toolchain()</pre>
+
+ <p>Register the default JVM toolchain.</p>
+
+
+ <hr>
+
+ <h2 id="kt_jvm_toolchain">kt_jvm_toolchain</h2>
+
+ <pre>kt_jvm_toolchain(<a href="#kt_jvm_toolchain.name">name</a>, <a href="#kt_jvm_toolchain.api_version">api_version</a>, <a href="#kt_jvm_toolchain.coroutines">coroutines</a>, <a href="#kt_jvm_toolchain.jvm_target">jvm_target</a>, <a href="#kt_jvm_toolchain.language_version">language_version</a>)</pre>
+
+ <p>The kotlin jvm toolchain</p>
+
+
+ <h3 id="kt_jvm_toolchain_args">Attributes</h3>
+
+<table class="params-table">
+ <colgroup>
+ <col class="col-param" />
+ <col class="col-description" />
+ </colgroup>
+ <tbody>
+ <tr id="kt_jvm_toolchain.name">
+ <td><code>name</code></td>
+ <td>
+ <p><code><a href="https://bazel.build/docs/build-ref.html#name">Name</a>; Required</code></p>
+ <p>A unique name for this rule.</p>
+ </td>
+ </tr>
+ <tr id="kt_jvm_toolchain.api_version">
+ <td><code>api_version</code></td>
+ <td>
+ <p><code>String; Optional; Default is '1.2'</code></p>
+ <p>the -api_version flag <a href="https://kotlinlang.org/docs/reference/compatibility.html">see</a>.</p>
+ </td>
+ </tr>
+ <tr id="kt_jvm_toolchain.coroutines">
+ <td><code>coroutines</code></td>
+ <td>
+ <p><code>String; Optional; Default is 'enable'</code></p>
+ <p>the -Xcoroutines flag, enabled by default as it's considered production ready 1.2.0 onward.</p>
+ </td>
+ </tr>
+ <tr id="kt_jvm_toolchain.jvm_target">
+ <td><code>jvm_target</code></td>
+ <td>
+ <p><code>String; Optional; Default is '1.8'</code></p>
+ <p>the -jvm_target flag.</p>
+ </td>
+ </tr>
+ <tr id="kt_jvm_toolchain.language_version">
+ <td><code>language_version</code></td>
+ <td>
+ <p><code>String; Optional; Default is '1.2'</code></p>
+ <p>the -languag_version flag <a href="https://kotlinlang.org/docs/reference/compatibility.html">see</a>.</p>
+ </td>
+ </tr>
+ </tbody>
+</table>
+
+
+ </div>
+
+ <footer class="mdl-mini-footer">
+ <div class="mdl-mini-footer__left-section">
+ <div class="mdl-logo">Bazel</div>
+ <ul class="mdl-mini-footer__link-list">
+ <li><a href="https://bazel.build">Home</a></li>
+ <li><a href="https://github.com/bazelbuild">GitHub</a></li>
+ </ul>
+ </div>
+ </footer>
+ </main>
+ </div>
+ </body>
+</html>
diff --git a/kotlin/BUILD b/kotlin/BUILD
index a8f1906..7411d64 100644
--- a/kotlin/BUILD
+++ b/kotlin/BUILD
@@ -11,33 +11,15 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-package(default_visibility = ["//visibility:private"])
-load("@io_bazel_skydoc//skylark:skylark.bzl", "skylark_doc", "skylark_library" )
+package(default_visibility = ["//visibility:public"])
-skylark_library(
- name = "doc_public",
- srcs = [
- "kotlin.bzl"
- ],
- visibility=["//visibility:private"]
-)
+load("//kotlin:toolchains.bzl", "define_kt_jvm_toolchain")
-skylark_doc(
- name = "docs",
- deps = [
- ":doc_public",
- ],
- format = "html",
- site_root = select({
- ":local": "/tmp/rules_kotlin",
- "//conditions:default": "https://bazelbuild.github.io/rules_kotlin"
- }),
+toolchain_type(
+ name = "kt_jvm_toolchain_type",
visibility = ["//visibility:public"]
)
-config_setting(
- name = "local",
- values = {
- "define": "local=1",
- }
-)
\ No newline at end of file
+define_kt_jvm_toolchain(name = "default_jvm_toolchain")
+
+exports_files(["toolchains.bzl", "kotlin.bzl"], visibility=["//docs:__subpackages__"])
\ No newline at end of file
diff --git a/kotlin/kotlin.bzl b/kotlin/kotlin.bzl
index f57965e..5d74015 100644
--- a/kotlin/kotlin.bzl
+++ b/kotlin/kotlin.bzl
@@ -23,8 +23,9 @@
remote = "https://github.com/bazelbuild/rules_kotlin.git",
commit = "<COMMIT_HASH>",
)
-load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories")
+load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains")
kotlin_repositories(kotlin_release_version = "1.2.21")
+kt_register_toolchains()
```
To enable persistent worker support, add the following to the appropriate `bazelrc` file:
@@ -220,7 +221,7 @@
}.items())
########################################################################################################################
-# Repositories
+# Repositories and Toolchains
########################################################################################################################
load(
"//kotlin:kotlin_compiler_repositories.bzl",
@@ -239,6 +240,12 @@
"""
_kotlin_compiler_repository(kotlin_release_version)
+load("//kotlin:toolchains.bzl", _kt_register_jvm_toolchain="kt_register_jvm_toolchain")
+
+def kt_register_toolchains():
+ """register all default toolchains"""
+ _kt_register_jvm_toolchain()
+
########################################################################################################################
# Simple Rules:
########################################################################################################################
@@ -256,6 +263,7 @@
}.items()),
outputs = _common_outputs,
implementation = _kotlin_library_impl,
+ toolchains = ["@io_bazel_rules_kotlin//kotlin:kt_jvm_toolchain_type"]
)
"""This rule compiles and links Kotlin and Java sources into a .jar file.
@@ -281,6 +289,7 @@
executable = True,
outputs = _binary_outputs,
implementation = _kotlin_binary_impl,
+ toolchains = ["@io_bazel_rules_kotlin//kotlin:kt_jvm_toolchain_type"]
)
"""Builds a Java archive ("jar file"), plus a wrapper shell script with the same name as the rule. The wrapper shell script uses a classpath that includes,
@@ -307,6 +316,7 @@
outputs = _binary_outputs,
test = True,
implementation = _kotlin_junit_test_impl,
+ toolchains = ["@io_bazel_rules_kotlin//kotlin:kt_jvm_toolchain_type"]
)
"""Setup a simple kotlin_test.
diff --git a/kotlin/rules/compile.bzl b/kotlin/rules/compile.bzl
index b702e20..59348bb 100644
--- a/kotlin/rules/compile.bzl
+++ b/kotlin/rules/compile.bzl
@@ -45,7 +45,7 @@
opts: struct containing Kotlin compilation options.
"""
compiler_output_base=ctx.actions.declare_directory(ctx.label.name + "." + "kotlinc")
-
+ tc=ctx.toolchains["@io_bazel_rules_kotlin//kotlin:kt_jvm_toolchain_type"]
args = [
"--target_label", ctx.label,
"--compiler_output_base", compiler_output_base.path,
@@ -53,7 +53,10 @@
"--output_jdeps", ctx.outputs.jdeps.path,
"--classpath", ":".join([f.path for f in compile_jars.to_list()]),
"--sources", ":".join([f.path for f in ctx.files.srcs]),
- "--kotlin_jvm_target", "1.8", "--kotlin_api_version", "1.2", "--kotlin_language_version", "1.2"
+ "--kotlin_jvm_target", tc.jvm_target,
+ "--kotlin_api_version", tc.api_version,
+ "--kotlin_language_version", tc.language_version,
+ "--kotlin_passthrough_flags", "-Xcoroutines=%s" % tc.coroutines
]
# Collect and prepare plugin descriptor for the worker.
plugin_info=_merge_plugin_infos(ctx.attr.plugins + ctx.attr.deps)
diff --git a/kotlin/toolchains.bzl b/kotlin/toolchains.bzl
new file mode 100644
index 0000000..e7ce1fb
--- /dev/null
+++ b/kotlin/toolchains.bzl
@@ -0,0 +1,88 @@
+# Copyright 2018 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""Kotlin Toolchains
+
+This file contains macros for defining and registering specific toolchains.
+
+### Examples
+
+To override a tool chain use the appropriate macro in a `BUILD` file to declare the toolchain:
+
+```bzl
+load("@io_bazel_rules_kotlin//kotlin:toolchains.bzl", "define_kt_jvm_toolchain")
+
+define_kt_jvm_toolchain(
+ name= "custom_toolchain",
+ api_version = "1.1",
+ language_version = "1.1",
+)
+```
+and then register it in the `WORKSPACE`:
+```bzl
+register_toolchains("//:custom_toolchain")
+```
+"""
+# The toolchain rules are not made private, at least the jvm ones so that they may be introspected in Intelij.
+_common_attrs = {
+ 'language_version': attr.string(default="1.2", values=["1.1", "1.2"]),
+ 'api_version': attr.string(default="1.2", values=["1.1", "1.2"]),
+ "coroutines": attr.string(default="enable", values=["enable", "warn", "error"]),
+}
+
+_kt_jvm_attrs = dict(_common_attrs.items() + {
+ 'jvm_target': attr.string(default="1.8", values=["1.6", "1.8"]),
+}.items())
+
+def _kotlin_jvm_toolchain_impl(ctx):
+ toolchain = platform_common.ToolchainInfo(
+ language_version = ctx.attr.language_version,
+ api_version = ctx.attr.api_version,
+ jvm_target = ctx.attr.jvm_target,
+ coroutines = ctx.attr.coroutines
+ )
+ return [toolchain]
+
+kt_jvm_toolchain = rule(
+ implementation = _kotlin_jvm_toolchain_impl,
+ attrs = _kt_jvm_attrs
+)
+"""The kotlin jvm toolchain
+Args:
+ language_version: the -languag_version flag [see](https://kotlinlang.org/docs/reference/compatibility.html).
+ api_version: the -api_version flag [see](https://kotlinlang.org/docs/reference/compatibility.html).
+ jvm_target: the -jvm_target flag.
+ coroutines: the -Xcoroutines flag, enabled by default as it's considered production ready 1.2.0 onward.
+"""
+
+def define_kt_jvm_toolchain(name, language_version=None, api_version=None, jvm_target=None, coroutines=None):
+ """Define a Kotlin JVM Toolchain, the name is used in the `toolchain` rule so can be used to register the toolchain in the WORKSPACE file."""
+ impl_name = name + "_impl"
+ kt_jvm_toolchain(
+ name = impl_name,
+ language_version = language_version,
+ api_version = api_version,
+ jvm_target = jvm_target,
+ coroutines = coroutines,
+ visibility = ["//visibility:public"]
+ )
+ native.toolchain(
+ name = name,
+ toolchain_type = "@io_bazel_rules_kotlin//kotlin:kt_jvm_toolchain_type",
+ toolchain = impl_name,
+ visibility = ["//visibility:public"]
+ )
+
+def kt_register_jvm_toolchain():
+ """Register the default JVM toolchain."""
+ native.register_toolchains("@io_bazel_rules_kotlin//kotlin:default_jvm_toolchain")
diff --git a/kotlin/workers/src/io/bazel/ruleskotlin/workers/compilers/jvm/actions/KotlinMainCompile.kt b/kotlin/workers/src/io/bazel/ruleskotlin/workers/compilers/jvm/actions/KotlinMainCompile.kt
index 21a677a..578a48c 100644
--- a/kotlin/workers/src/io/bazel/ruleskotlin/workers/compilers/jvm/actions/KotlinMainCompile.kt
+++ b/kotlin/workers/src/io/bazel/ruleskotlin/workers/compilers/jvm/actions/KotlinMainCompile.kt
@@ -61,6 +61,8 @@
.addAll("-module-name", Metas.TARGET[ctx])
.addAll("-d", compileDirectories.classes.toString())
+ Flags.KOTLIN_PASSTHROUGH_FLAGS[ctx]?.takeIf { it.isNotBlank() }?.also { args.addAll(it.split(" ")) }
+
return args
}
diff --git a/kotlin/workers/src/io/bazel/ruleskotlin/workers/model/Flags.kt b/kotlin/workers/src/io/bazel/ruleskotlin/workers/model/Flags.kt
index 4246b94..9e8deb5 100644
--- a/kotlin/workers/src/io/bazel/ruleskotlin/workers/model/Flags.kt
+++ b/kotlin/workers/src/io/bazel/ruleskotlin/workers/model/Flags.kt
@@ -34,4 +34,9 @@
val KOTLIN_API_VERSION = Flag.Optional("--kotlin_api_version", "-api-version")
val KOTLIN_LANGUAGE_VERSION = Flag.Optional("--kotlin_language_version", "-language-version")
val KOTLIN_JVM_TARGET = Flag.Optional("--kotlin_jvm_target", "-jvm-target")
+ /**
+ * These flags are passed through to the compiler verbatim, the rules ensure they are safe. These flags are to toggle features or they carry a single value
+ * so the string is tokenized by space.
+ */
+ val KOTLIN_PASSTHROUGH_FLAGS = Flag.Optional("--kotlin_passthrough_flags")
}
\ No newline at end of file