Skip to content

Commit

Permalink
finding the right version...
Browse files Browse the repository at this point in the history
  • Loading branch information
restingbull committed Jul 23, 2021
1 parent 4698602 commit 857458a
Show file tree
Hide file tree
Showing 26 changed files with 80 additions and 38 deletions.
2 changes: 1 addition & 1 deletion CompileAvoidance.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ If you encounter such bugs, ABI generation can be disabled on a per target basis
following tag

```python
load("//kotlin:kotlin.bzl", "kt_jvm_library")
load("//kotlin:jvm.bzl", "kt_jvm_library")

kt_jvm_library(
name = "framework",
Expand Down
35 changes: 22 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ http_archive(
sha256 = rules_kotlin_sha,
)

load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains")
load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories")
kotlin_repositories() # if you want the default. Otherwise see custom kotlinc distribution below

load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains")
kt_register_toolchains() # to use the default toolchain, otherwise see toolchains below
```

Expand All @@ -109,17 +111,19 @@ http_archive(
sha256 = rules_kotlin_sha,
)

load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains")
kotlin_repositories() # if you want the default. Otherwise see custom kotlinc distribution below
kt_register_toolchains() # to use the default toolchain, otherwise see toolchains below
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()
```

## `BUILD` files

In your project's `BUILD` files, load the Kotlin rules and use them like so:

```python
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library")
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library")

kt_jvm_library(
name = "package_name",
Expand All @@ -136,7 +140,7 @@ To enable a custom toolchain (to configure language level, etc.)
do the following. In a `<workspace>/BUILD.bazel` file define the following:

```python
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "define_kt_toolchain")
load("@io_bazel_rules_kotlin//kotlin:core.bzl", "define_kt_toolchain")

define_kt_toolchain(
name = "kotlin_toolchain",
Expand All @@ -158,7 +162,7 @@ To choose a different `kotlinc` distribution (1.3 and 1.4 variants supported), d
in your `WORKSPACE` file (or import from a `.bzl` file:

```python
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories")
load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories")

KOTLIN_VERSION = "1.3.31"
KOTLINC_RELEASE_SHA = "107325d56315af4f59ff28db6837d03c2660088e3efeb7d4e41f3e01bb848d6a"
Expand Down Expand Up @@ -192,9 +196,12 @@ local_repository(

load("@io_bazel_rules_kotlin//kotlin:dependencies.bzl", "kt_download_local_dev_dependencies")
kt_download_local_dev_dependencies()
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains")
kotlin_repositories() # if you want the default. Otherwise see custom kotlinc distribution below
kt_register_toolchains() # to use the default toolchain, otherwise see toolchains below

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()
```

# Kotlin and Java compiler flags
Expand All @@ -205,7 +212,7 @@ Note: Not all compiler flags are supported in all language versions. When this h

For example you can define global compiler flags by doing:
```python
load("//kotlin:kotlin.bzl", "kt_kotlinc_options", "kt_javac_options", "define_kt_toolchain")
load("//kotlin:core.bzl", "kt_kotlinc_options", "kt_javac_options", "define_kt_toolchain")

kt_kotlinc_options(
name = "kt_kotlinc_options",
Expand All @@ -231,7 +238,8 @@ Compiler flags that are passed to the rule definitions will be taken over the to

Example:
```python
load("//kotlin:kotlin.bzl", "kt_kotlinc_options", "kt_javac_options", "kt_jvm_library")
load("//kotlin:core.bzl", "kt_kotlinc_options", "kt_javac_options", "kt_jvm_library")
load("//kotlin:jvm.bzl","kt_javac_options", "kt_jvm_library")

kt_kotlinc_options(
name = "kt_kotlinc_options_for_package_name",
Expand Down Expand Up @@ -259,7 +267,8 @@ The `kt_compiler_plugin` rule allows running Kotlin compiler plugins, such as no

For example, you can add allopen to your project like this:
```python
load("//kotlin:kotlin.bzl", "kt_compiler_plugin", "kt_jvm_library")
load("//kotlin:core.bzl", "kt_compiler_plugin")
load("//kotlin:jvm.bzl", "kt_jvm_library")

kt_compiler_plugin(
name = "open_for_testing_plugin",
Expand Down
22 changes: 22 additions & 0 deletions docs/kotlin.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ kt_js_library(<a href="#kt_js_library-name">name</a>, <a href="#kt_js_library-kw

<!-- Generated with Stardoc: http://skydoc.bazel.build -->

<a id="#kt_javac_options"></a>

## kt_javac_options

kt_javac_options(<a href="#kt_javac_options-name">name</a>, <a href="#kt_javac_options-warn">warn</a>, <a href="#kt_javac_options-x_ep_disable_all_checks">x_ep_disable_all_checks</a>, <a href="#kt_javac_options-x_lint">x_lint</a>, <a href="#kt_javac_options-xd_suppress_notes">xd_suppress_notes</a>)

Define java compiler options for `kt_jvm_*` rules with java sources.


**ATTRIBUTES**


| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
|<a id="kt_javac_options-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
|<a id="kt_javac_options-warn"></a>warn | Control warning behaviour. | String | optional | "report" |
|<a id="kt_javac_options-x_ep_disable_all_checks"></a>x_ep_disable_all_checks | See javac -XepDisableAllChecks documentation | Boolean | optional | False |
|<a id="kt_javac_options-x_lint"></a>x_lint | See javac -Xlint: documentation | List of strings | optional | [] |
|<a id="kt_javac_options-xd_suppress_notes"></a>xd_suppress_notes | See javac -XDsuppressNotes documentation | Boolean | optional | False |


<a id="#kt_jvm_binary"></a>

## kt_jvm_binary
Expand Down
4 changes: 2 additions & 2 deletions examples/android/bzl/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "define_kt_toolchain")
load("@io_bazel_rules_kotlin//kotlin/internal:opts.bzl", "kt_javac_options", "kt_kotlinc_options")
load("@io_bazel_rules_kotlin//kotlin:core.bzl", "define_kt_toolchain", "kt_kotlinc_options")
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_javac_options")

kt_kotlinc_options(
name = "default_kotlinc_options",
Expand Down
2 changes: 1 addition & 1 deletion examples/android/libAndroid/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library")
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library")
load("@build_bazel_rules_android//android:rules.bzl", "android_library")

android_library(
Expand Down
3 changes: 2 additions & 1 deletion examples/android/libKtAndroid/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library", "kt_compiler_plugin")
load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_compiler_plugin")
load("@io_bazel_rules_kotlin//kotlin:android.bzl", "kt_android_library")
load("@rules_java//java:defs.bzl", "java_plugin")

kt_compiler_plugin(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")
load("@io_bazel_rules_kotlin//kotlin:android.bzl", "kt_android_library")

kt_android_library(
name = "sample",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_test")
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_test")

kt_jvm_test(
name = "LoggedInComponentTest",
Expand Down
2 changes: 1 addition & 1 deletion examples/anvil/library/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library")
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library")

kt_jvm_library(
name = "library",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library")
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library")

kt_jvm_library(
name = "god",
Expand Down
2 changes: 1 addition & 1 deletion examples/anvil/scopes/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library")
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library")

kt_jvm_library(
name = "scopes",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library")
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library")

kt_jvm_library(
name = "scopes",
Expand Down
3 changes: 2 additions & 1 deletion examples/anvil/third_party/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@rules_java//java:defs.bzl", "java_library", "java_plugin")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_compiler_plugin", "kt_jvm_library")
load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_compiler_plugin")
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library")

java_plugin(
name = "dagger_component_plugin",
Expand Down
3 changes: 2 additions & 1 deletion examples/jetpack_compose/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "define_kt_toolchain", "kt_compiler_plugin", "kt_javac_options", "kt_kotlinc_options")
load("@io_bazel_rules_kotlin//kotlin:core.bzl", "define_kt_toolchain", "kt_compiler_plugin", "kt_kotlinc_options")
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_javac_options")
load("@bazel_tools//tools/jdk:default_java_toolchain.bzl", "default_java_toolchain")

# Java Toolchain
Expand Down
2 changes: 1 addition & 1 deletion examples/jetpack_compose/compose-ui/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")
load("@io_bazel_rules_kotlin//kotlin:android.bzl", "kt_android_library")

kt_android_library(
name = "lib",
Expand Down
2 changes: 1 addition & 1 deletion examples/node/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_js_import")
load("@io_bazel_rules_kotlin//kotlin:js.bzl", "kt_js_import")

# Create kt_js_imports for KotlinX's Coroutines and Atomicfu libraries.
#
Expand Down
3 changes: 2 additions & 1 deletion examples/node/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ load("@io_bazel_rules_kotlin//kotlin:dependencies.bzl", "kt_download_local_dev_d

kt_download_local_dev_dependencies()

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

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()

load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "versions")
Expand Down
2 changes: 1 addition & 1 deletion examples/node/coroutines-helloworld/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_js_library")
load("@io_bazel_rules_kotlin//kotlin:js.bzl", "kt_js_library")
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")

kt_js_library(
Expand Down
2 changes: 1 addition & 1 deletion examples/node/express/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_js_library")
load("@io_bazel_rules_kotlin//kotlin:js.bzl", "kt_js_library")
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")

# routes and auth have acme prepended to the rule name as these are the names of the resulting jars. The name of the
Expand Down
2 changes: 1 addition & 1 deletion examples/node/express/auth/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_js_library")
load("@io_bazel_rules_kotlin//kotlin:js.bzl", "kt_js_library")

kt_js_library(
name = "acme-auth",
Expand Down
3 changes: 2 additions & 1 deletion examples/plugin/src/parcelize/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_compiler_plugin")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library", "kt_jvm_library")
load("@io_bazel_rules_kotlin//kotlin:android.bzl", "kt_android_library")
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library")

kt_compiler_plugin(
name = "parcelize_plugin",
Expand Down
4 changes: 2 additions & 2 deletions examples/trivial/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ load("@io_bazel_rules_kotlin//kotlin:dependencies.bzl", "kt_download_local_dev_d

kt_download_local_dev_dependencies()

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

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()

RULES_JVM_EXTERNAL_TAG = "2.7"
Expand Down
3 changes: 2 additions & 1 deletion examples/trivial/app/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@rules_java//java:defs.bzl", "java_binary")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library", "ktlint_fix", "ktlint_test")
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library",)
load("@io_bazel_rules_kotlin//kotlin:lint.bzl", "ktlint_fix", "ktlint_test")

kt_jvm_library(
name = "app_lib",
Expand Down
2 changes: 1 addition & 1 deletion kotlin/internal/repositories/release_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def _kotlin_compiler_impl(repository_ctx):
"""Creates the kotlinc repository."""
attr = repository_ctx.attr

repository_ctx.execute("ls $ANDROID_HOME/build-tools", quiet = false)
repository_ctx.execute(["sh", "-c", "ls $ANDROID_HOME/build-tools"], quiet = False)

repository_ctx.download_and_extract(
attr.urls,
Expand Down
2 changes: 1 addition & 1 deletion kotlin/internal/repositories/versions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ versions = struct(
VERSION = "0.1.1",
SHA = "cd06d15dd8bb59926e4d65f9003bfc20f9da4b2519985c27e190cddc8b7a7806",
URLS = ["https://github.com/bazelbuild/rules_android/archive/v%s.zip" % "0.1.1"],
BUILD_TOOLS = "30.0.0",
BUILD_TOOLS = "30.0.3",
),
PYTHON = struct(
VERSION = "0.2.0",
Expand Down
5 changes: 5 additions & 0 deletions kotlin/jvm.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ load(
_kt_jvm_library = "kt_jvm_library",
_kt_jvm_test = "kt_jvm_test",
)
load(
"//kotlin/internal:opts.bzl",
_kt_javac_options = "kt_javac_options",
)

kt_javac_options = _kt_javac_options
kt_jvm_binary = _kt_jvm_binary
kt_jvm_import = _kt_jvm_import
kt_jvm_library = _kt_jvm_library
Expand Down

0 comments on commit 857458a

Please sign in to comment.