blob: 7fbc25b70c7491501d7c423fa652ddc0f68f62c0 [file] [log] [blame] [view]
Jakob Buchgrabere421f762018-02-23 11:44:10 +01001[![Build status](https://badge.buildkite.com/a8860e94a7378491ce8f50480e3605b49eb2558cfa851bbf9b.svg)](https://buildkite.com/bazel/kotlin-postsubmit)
2
hsyeda3a79e92018-01-31 18:32:26 +00003[Skydoc documentation](https://bazelbuild.github.io/rules_kotlin)
David Stanke3208b172018-01-31 12:45:04 -05004
hsyed14a04d02018-02-05 18:24:26 +00005# Announcements
Hassan Syed303eefb2018-08-14 12:50:36 +01006* <b>August 14, 2018.</b> Js support. No documentation yet but see the nested example workspace `examples/node`.
Hassan Syedafcaf552018-08-14 12:41:05 +01007* <b>August 14, 2018.</b> Android support. No documentation but it's a simple integration. see
8 `kotlin/internal/jvm/android.bzl`.
Hassan Syed0a60cad2018-07-07 18:02:00 +01009* <b>Jun 29, 2018.</b> The commits from this date forward are compatible with bazel `>=0.14`. JDK9 host issues were
10 fixed as well some other deprecations. I recommend skipping `0.15.0` if you are on a Mac.
Hassan Syed44a90a72018-05-25 15:55:20 +010011* <b>May 25, 2018.</b> Test "friend" support. A single friend dep can be provided to `kt_jvm_test` which allows the test
Hassan Syed2d517f92018-05-24 22:40:39 +010012 to access internal members of the module under test.
13* <b>February 15, 2018.</b> Toolchains for the JVM rules. Currently this allow tweaking:
hsyed36cf44f2018-02-15 23:55:14 +000014 * The JVM target (bytecode level).
15 * API and Language levels.
16 * Coroutines, enabled by default.
hsyed84a97212018-02-09 12:59:50 +000017* <b>February 9, 2018.</b> Annotation processing.
hsyed14a04d02018-02-05 18:24:26 +000018* <b>February 5, 2018. JVM rule name change:</b> the prefix has changed from `kotlin_` to `kt_jvm_`.
19
20# Overview
David Stanke3208b172018-01-31 12:45:04 -050021
Christian Edward Gruberac84ceb2018-03-04 14:06:00 -080022These rules were initially forked from [pubref/rules_kotlin](http://github.com/pubref/rules_kotlin).
23Key changes:
David Stanke3208b172018-01-31 12:45:04 -050024
Menny Even Danan9d7bcb52018-07-26 12:15:50 -040025* Replace the macros with three basic rules. `kt_jvm_binary`, `kt_jvm_library` and `kt_jvm_test`.
David Stanke3208b172018-01-31 12:45:04 -050026* Use a single dep attribute instead of `java_dep` and `dep`.
27* Add support for the following standard java rules attributes:
28 * `data`
29 * `resource_jars`
30 * `runtime_deps`
31 * `resources`
32 * `resources_strip_prefix`
33 * `exports`
34* Persistent worker support.
Jakob Buchgrabere421f762018-02-23 11:44:10 +010035* Mixed-Mode compilation (compile Java and Kotlin in one pass).
Christian Edward Gruberac84ceb2018-03-04 14:06:00 -080036
hsyed740b9622018-07-04 17:57:21 +010037# Quick Guide
hsyed9b1dece2018-08-10 16:49:15 +010038This section just contains a quick overview. Consult the generated
39[documentation](https://bazelbuild.github.io/rules_kotlin). Note: Skydoc documentation is no longer being generated.
40Comprehensive documentation will have to wait till the new documentation generation tool is ready. A contribution to
41port the documentation to the RST format like `rules_go` has would be very welcome !
hsyed740b9622018-07-04 17:57:21 +010042
Christian Edward Gruberac84ceb2018-03-04 14:06:00 -080043
44## WORKSPACE
45In the project's `WORKSPACE`, declare the external repository and initialize the toolchains, like
46this:
47
48```build
Xineacc5a22018-10-24 15:37:17 -040049load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
50
Christian Edward Gruber62243b12018-03-04 15:36:27 -080051rules_kotlin_version = "67f4a6050584730ebae7f8a40435a209f8e0b48e"
Christian Edward Gruberac84ceb2018-03-04 14:06:00 -080052
53http_archive(
54 name = "io_bazel_rules_kotlin",
55 urls = ["https://github.com/bazelbuild/rules_kotlin/archive/%s.zip" % rules_kotlin_version],
56 type = "zip",
57 strip_prefix = "rules_kotlin-%s" % rules_kotlin_version
58)
59
60load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains")
hsyedfe593c52018-09-03 21:10:59 +010061kotlin_repositories()
Christian Edward Gruberac84ceb2018-03-04 14:06:00 -080062kt_register_toolchains()
63```
64
Christian Edward Gruberac84ceb2018-03-04 14:06:00 -080065## BUILD files
66
67In your project's `BUILD` files, load the kotlin rules and use them like so:
68
69```
70load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library")
71
72kt_jvm_library(
73 name = "package_name",
74 srcs = glob(["*.kt"]),
75 deps = [
76 "//path/to/dependency",
77 ],
78)
79```
80
81# License
82
83This project is licensed under the [Apache 2.0 license](LICENSE), as are all contributions
84
85# Contributing
86
87See the [CONTRIBUTING](CONTRIBUTING.md) doc for information about how to contribute to
88this project.
89