Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into nk-compilationAvo…
Browse files Browse the repository at this point in the history
…idanceKotlin_upstream

* upstream/master: (51 commits)
  Expose ksp_version (#989)
  Bump quick guide to use v1.8 (#987)
  Fail CI if the docs are outdated (#961)
  Rename dev_io_bazel_rules_kotlin -> io_bazel_rules_kotlin (#973)
  update stardoc to 0.5.6 (#986)
  fix readme about kotlinc_opts and javac_opts (#984)
  Update README with KSP support (#983)
  Regenerate the docs (#980)
  Update the README.md with the latest dev override config (#981)
  Remove opts.release.bzl which is no longer being used (#982)
  Remove print warning from kt_download_local_dev_dependencies (#974)
  Avoid creating duplicate android_sdk_repositories (#978)
  Normalize label (#968)
  Generate koltinc options (#962)
  Restore neverlink on compiler. (#977)
  Use the mnemonic for worker keys (#976)
  Update KtLint to 0.49.1 (#970)
  Add support for -Xuse-fir-lt (#972)
  Support -Xenable-incremental-compilation (#971)
  Update to Kotlin 1.8.21 (#969)
  ...
  • Loading branch information
nkoroste committed Jul 26, 2023
2 parents 9f14ecf + d584c43 commit 03ba94c
Show file tree
Hide file tree
Showing 148 changed files with 2,639 additions and 2,396 deletions.
12 changes: 10 additions & 2 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
validate_config: 1
bazel: 6.0.0
bazel: 6.1.1
buildifier:
version: 5.1.0
version: 6.1.0
# no lint warnings for the moment. They are basically a smoke alarm in hell.
# keep this argument in sync with .pre-commit-config.yaml
warnings: "-confusing-name,-constant-glob,-duplicated-name,-function-docstring,-function-docstring-args,-function-docstring-header,-module-docstring,-name-conventions,-no-effect,-constant-glob,-provider-params,-print,-rule-impl-return,-bzl-visibility,-unnamed-macro,-uninitialized,-unreachable"
Expand Down Expand Up @@ -33,6 +33,12 @@ tasks:
working_directory: examples/android
test_targets:
- //...
example-ksp:
name: "Example - Android KSP"
platform: ubuntu1804
working_directory: examples/ksp
test_targets:
- //...
example-associates:
name: "Example - Associates"
platform: ubuntu1804
Expand Down Expand Up @@ -105,6 +111,8 @@ tasks:
platform: ubuntu1804
build_targets:
- //kotlin:stardoc
test_targets:
- //docs:are_docs_up_to_date_test
ktlint:
name: KtLint
platform: ubuntu1804
Expand Down
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.0.0
6.1.1
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/keith/pre-commit-buildifier
rev: 4.0.1.1
rev: 6.1.0
hooks:
- id: buildifier
args: &args
Expand Down
12 changes: 0 additions & 12 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
load("//src/main/starlark/release:packager.bzl", "release_archive")
load("//src/main/starlark/core/repositories:versions.bzl", "versions")
load("//kotlin:lint.bzl", "ktlint_config")

exports_files([
Expand Down Expand Up @@ -52,20 +51,9 @@ test_suite(
],
)

[
release_archive(
name = version,
deps = [
"@%s//:pkg" % version,
],
)
for version in versions.CORE
]

# Release target.
release_archive(
name = "rules_kotlin_release",
srcs = ["%s.tgz" % v for v in versions.CORE],
src_map = {
"BUILD.release.bazel": "BUILD.bazel",
"WORKSPACE.release.bazel": "WORKSPACE",
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ sky.reflow:
deps.regen:
scripts/regen_deps

docs.regen:
bazel build //kotlin:stardoc
cp bazel-bin/kotlin/kotlin.md docs/kotlin.md

proto.regen:
scripts/gen_proto_jars

Expand Down
100 changes: 72 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

For more information about release and changelogs please see [Changelog](CHANGELOG.md) or refer to the [Github Releases](https://github.com/bazelbuild/rules_kotlin/releases) page.

# `rules_kotlin` Bazel Compatibility
- HEAD: `5`, `6`
- [Release 1.7](https://github.com/bazelbuild/rules_kotlin/releases/tag/v1.7.1): `4`, `5`, `6`

# Overview

**rules_kotlin** supports the basic paradigm of `*_binary`, `*_library`, `*_test` of other Bazel
Expand Down Expand Up @@ -52,8 +56,8 @@ this:
```python
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

rules_kotlin_version = "1.7.1"
rules_kotlin_sha = "fd92a98bd8a8f0e1cdcb490b93f5acef1f1727ed992571232d33de42395ca9b3"
rules_kotlin_version = "1.8"
rules_kotlin_sha = "01293740a16e474669aba5b5a1fe3d368de5832442f164e4fbfc566815a8bc3a"
http_archive(
name = "io_bazel_rules_kotlin",
urls = ["https://github.com/bazelbuild/rules_kotlin/releases/download/v%s/rules_kotlin_release.tgz" % rules_kotlin_version],
Expand Down Expand Up @@ -137,16 +141,13 @@ In the project's `WORKSPACE`, change the setup:

# Use local check-out of repo rules (or a commit-archive from github via http_archive or git_repository)
local_repository(
name = "release_archive",
path = "../path/to/rules_kotlin_clone/src/main/starlark/release_archive",
name = "io_bazel_rules_kotlin",
path = "../path/to/rules_kotlin_clone/",
)
load("@release_archive//:repository.bzl", "archive_repository")

load("@io_bazel_rules_kotlin//kotlin:dependencies.bzl", "kt_download_local_dev_dependencies")

archive_repository(
name = "io_bazel_rules_kotlin",
local_path = "../path/to/rules_kotlin_clone/"
)
kt_download_local_dev_dependencies()

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

Expand All @@ -163,18 +164,11 @@ rules to this:
```python
# Download master or specific revisions
http_archive(
name = "io_bazel_rules_kotlin_master",
name = "io_bazel_rules_kotlin",
strip_prefix = "rules_kotlin-master",
urls = ["https://github.com/bazelbuild/rules_kotlin/archive/refs/heads/master.zip"],
)

load("@io_bazel_rules_kotlin_master//src/main/starlark/release_archive:repository.bzl", "archive_repository")

archive_repository(
name = "io_bazel_rules_kotlin",
source_repository_name = "io_bazel_rules_kotlin_master",
)

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

kotlin_repositories()
Expand Down Expand Up @@ -209,13 +203,13 @@ load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_kotlinc_options", "kt_javac_

kt_kotlinc_options(
name = "kt_kotlinc_options",
warn = "report",
kotlinc_opts = ["-Xno-param-assertions"],
jvm_target = "1.8",
)

kt_javac_options(
name = "kt_javac_options",
warn = "report",
x_ep_disable_all_checks = False,
javac_opts = ["-nowarn"],
)

define_kt_toolchain(
Expand All @@ -231,26 +225,28 @@ Compiler flags that are passed to the rule definitions will be taken over the to

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

kt_kotlinc_options(
name = "kt_kotlinc_options_for_package_name",
warn = "error",
x_optin = ["kotlin.Experimental", "kotlin.ExperimentalStdlibApi"],
kotlinc_opts = [
"-Xno-param-assertions",
"-Xopt-in=kotlin.Experimental",
"-Xopt-in=kotlin.ExperimentalStdlibApi",
],
)

kt_javac_options(
name = "kt_javac_options_for_package_name",
warn = "error",
x_ep_disable_all_checks = True,
javac_opts = ["-nowarn"],
)

kt_jvm_library(
name = "package_name",
srcs = glob(["*.kt"]),
kotlinc_options = "//:kt_kotlinc_options_for_package_name",
javac_options = "//:kt_javac_options_for_package_name",
kotlinc_opts = "//:kt_kotlinc_options_for_package_name",
javac_opts = "//:kt_javac_options_for_package_name",
deps = ["//path/to/dependency"],
)
```
Expand All @@ -260,6 +256,54 @@ Additionally, you can add options for both tracing and timing of the bazel build
* `bazel build --define=kt_timings=1`

`kt_trace=1` will allow you to inspect the full kotlinc commandline invocation, while `kt_timings=1` will report the high level time taken for each step.

# KSP (Kotlin Symbol Processing)

KSP is officially supported as of `rules_kotlin` 1.8 and can be declared using the new
`kt_ksp_plugin` rule.

A few things to note:
- As of now `rules_kotlin` only supports KSP plugins that generate Kotlin code.
- KSP is [not yet thread safe](https://github.com/google/ksp/issues/1385) and will likely fail if you are using it in a build that has multiplex workers enabled. To work around this add the following flag to your Bazelrc:
```
build --experimental_worker_max_multiplex_instances=KotlinKsp=1
```

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

kt_ksp_plugin(
name = "moshi-kotlin-codegen",
processor_class = "com.squareup.moshi.kotlin.codegen.ksp.JsonClassSymbolProcessorProvider",
deps = [
"@maven//:com_squareup_moshi_moshi",
"@maven//:com_squareup_moshi_moshi_kotlin",
"@maven//:com_squareup_moshi_moshi_kotlin_codegen",
],
)

kt_jvm_library(
name = "lib",
srcs = glob(["*.kt"]),
plugins = ["//:moshi-kotlin-codegen"],
)
```

To choose a different `ksp_version` distribution,
do the following in your `WORKSPACE` file (or import from a `.bzl` file):

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

kotlin_repositories(
ksp_compiler_release = ksp_version(
release = "1.8.22-1.0.11",
sha256 = "2ce5a08fddd20ef07ac051615905453fe08c3ba3ce5afa5dc43a9b77aa64507d",
),
)
```

# Kotlin compiler plugins

The `kt_compiler_plugin` rule allows running Kotlin compiler plugins, such as no-arg, sam-with-receiver and allopen.
Expand Down
4 changes: 2 additions & 2 deletions WORKSPACE.dev.bazel
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.
workspace(name = "dev_io_bazel_rules_kotlin")
workspace(name = "io_bazel_rules_kotlin")

load("//src/main/starlark/core/repositories:download.bzl", "kt_download_local_dev_dependencies")

Expand All @@ -21,4 +21,4 @@ load("//kotlin:repositories.bzl", "kotlin_repositories")

kotlin_repositories()

register_toolchains("@dev_io_bazel_rules_kotlin//kotlin/internal:default_toolchain")
register_toolchains("@io_bazel_rules_kotlin//kotlin/internal:default_toolchain")
12 changes: 12 additions & 0 deletions docs/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sh_test(
name = "are_docs_up_to_date_test",
srcs = ["are_docs_up_to_date_test.sh"],
args = [
"$(location kotlin.md)",
"$(location //kotlin:stardoc)",
],
data = [
"kotlin.md",
"//kotlin:stardoc",
],
)
13 changes: 13 additions & 0 deletions docs/are_docs_up_to_date_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

function fail {
echo >&2 "##### $1 ######"
exit 1
}

current="$1"
new="$2"
[[ -f $new ]] || fail "missing new docs"
[[ -f $current ]] || fail "missing current docs"

diff -u "$1" "$2" || fail "kotlin docs are out of date"
Loading

0 comments on commit 03ba94c

Please sign in to comment.