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 8aae20a
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 27 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
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/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_android_library")

kt_compiler_plugin(
name = "parcelize_plugin",
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
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 8aae20a

Please sign in to comment.