Skip to content

Commit

Permalink
Fix using rules_kotlin from head (#571)
Browse files Browse the repository at this point in the history
* Update local development instructions, add kotlinc_version helper for choosing compiler versions.

Signed-off-by: restingbull@cabaretmechanique.com <restingbull@cabaretmechanique.com>

* remove stray 1.5 references
  • Loading branch information
restingbull authored Aug 18, 2021
1 parent a73e838 commit fa0ff96
Show file tree
Hide file tree
Showing 21 changed files with 90 additions and 59 deletions.
44 changes: 22 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,14 @@ 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:repositories.bzl", "kotlin_repositories")

KOTLIN_VERSION = "1.3.31"
KOTLINC_RELEASE_SHA = "107325d56315af4f59ff28db6837d03c2660088e3efeb7d4e41f3e01bb848d6a"
load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories", "kotlinc_version")

KOTLINC_RELEASE = {
"urls": [
"https://github.com/JetBrains/kotlin/releases/download/v{v}/kotlin-compiler-{v}.zip".format(v = KOTLIN_VERSION),
],
"sha256": KOTLINC_RELEASE_SHA,
}

kotlin_repositories(compiler_release = KOTLINC_RELEASE)
kotlin_repositories(
compiler_release = kotlinc_version(
release = "1.3.31", # just the numeric version
sha256 = "107325d56315af4f59ff28db6837d03c2660088e3efeb7d4e41f3e01bb848d6a"
)
)
```

## Third party dependencies
Expand All @@ -183,24 +178,29 @@ _(e.g. Maven artifacts)_
Third party (external) artifacts can be brought in with systems such as [`rules_jvm_external`](https://github.com/bazelbuild/rules_jvm_external) or [`bazel_maven_repository`](https://github.com/square/bazel_maven_repository) or [`bazel-deps`](https://github.com/johnynek/bazel-deps), but make sure the version you use doesn't naively use `java_import`, as this will cause bazel to make an interface-only (`ijar`), or ABI jar, and the native `ijar` tool does not know about kotlin metadata with respect to inlined functions, and will remove method bodies inappropriately. Recent versions of `rules_jvm_external` and `bazel_maven_repository` are known to work with Kotlin.

# Development Setup Guide
As of 1.4.0, to use the rules directly from the rules_kotlin workspace (i.e. not the release artifact) additional dependency downloads are required.
As of 1.5.0, to use the rules directly from the rules_kotlin workspace (i.e. not the release artifact)
require the use of `release_archive` repository. This repository will build and configure the current
workspace to use `rules_kotlin` in the same manner as the released binary artifact.

In the project's `WORKSPACE`, change the setup:
```python

# 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/starklark/release_archive",
)

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

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

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

Expand All @@ -212,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:core.bzl", "kt_kotlinc_options", "kt_javac_options", "define_kt_toolchain")
load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_kotlinc_options", "kt_javac_options", "define_kt_toolchain")

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

Example:
```python
load("//kotlin:core.bzl", "kt_kotlinc_options", "kt_javac_options", "kt_jvm_library")
load("//kotlin:jvm.bzl","kt_javac_options", "kt_jvm_library")
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")

kt_kotlinc_options(
name = "kt_kotlinc_options_for_package_name",
Expand Down Expand Up @@ -267,8 +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:core.bzl", "kt_compiler_plugin")
load("//kotlin:jvm.bzl", "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")

kt_compiler_plugin(
name = "open_for_testing_plugin",
Expand Down
28 changes: 2 additions & 26 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
# limitations under the License.
workspace(name = "dev_io_bazel_rules_kotlin")

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

kt_download_local_dev_dependencies()

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

kotlin_repositories()

Expand All @@ -30,27 +30,3 @@ load("@bazel_toolchains//rules:rbe_repo.bzl", "rbe_autoconfig")
rbe_autoconfig(
name = "buildkite_config",
)

load(
"@rules_android//android:rules.bzl",
"android_ndk_repository",
"android_sdk_repository",
)

android_sdk_repository(
name = "androidsdk",
build_tools_version = versions.ANDROID.BUILD_TOOLS,
)

android_ndk_repository(name = "androidndk")

[
local_repository(
name = version,
path = "src/main/starlark/%s" % version,
repo_mapping = {
"@dev_io_bazel_rules_kotlin": "@",
},
)
for version in versions.CORE
]
2 changes: 1 addition & 1 deletion examples/android/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ workspace(name = "android_example")

local_repository(
name = "release_archive",
path = "../release_archive",
path = "../../src/main/starlark/release_archive",
)

load("@release_archive//:repository.bzl", "archive_repository")
Expand Down
2 changes: 1 addition & 1 deletion examples/anvil/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local_repository(
name = "release_archive",
path = "../release_archive",
path = "../../src/main/starlark/release_archive",
)

load("@release_archive//:repository.bzl", "archive_repository")
Expand Down
2 changes: 1 addition & 1 deletion examples/associates/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local_repository(
name = "release_archive",
path = "../release_archive",
path = "../../src/main/starlark/release_archive",
)

load("@release_archive//:repository.bzl", "archive_repository")
Expand Down
2 changes: 1 addition & 1 deletion examples/dagger/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local_repository(
name = "release_archive",
path = "../release_archive",
path = "../../src/main/starlark/release_archive",
)

load("@release_archive//:repository.bzl", "archive_repository")
Expand Down
2 changes: 1 addition & 1 deletion examples/jetpack_compose/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local_repository(
name = "release_archive",
path = "../release_archive",
path = "../../src/main/starlark/release_archive",
)

load("@release_archive//:repository.bzl", "archive_repository")
Expand Down
2 changes: 1 addition & 1 deletion examples/multiplex/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ workspace(name = "multiplex")

local_repository(
name = "release_archive",
path = "../release_archive",
path = "../../src/main/starlark/release_archive",
)

load("@release_archive//:repository.bzl", "archive_repository")
Expand Down
2 changes: 1 addition & 1 deletion examples/node/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ workspace(name = "kotlin_node_examples")

local_repository(
name = "release_archive",
path = "../release_archive",
path = "../../src/main/starlark/release_archive",
)

load("@release_archive//:repository.bzl", "archive_repository")
Expand Down
2 changes: 1 addition & 1 deletion examples/plugin/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local_repository(
name = "release_archive",
path = "../release_archive",
path = "../../src/main/starlark/release_archive",
)

load("@release_archive//:repository.bzl", "archive_repository")
Expand Down
2 changes: 1 addition & 1 deletion examples/trivial/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

local_repository(
name = "release_archive",
path = "../release_archive",
path = "../../src/main/starlark/release_archive",
)

load("@release_archive//:repository.bzl", "archive_repository")
Expand Down
24 changes: 23 additions & 1 deletion kotlin/dependencies.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,26 @@ load(
_kt_download_local_dev_dependencies = "kt_download_local_dev_dependencies",
)

kt_download_local_dev_dependencies = _kt_download_local_dev_dependencies
def kt_download_local_dev_dependencies():
print("""kt_download_local_dev_dependencies is deprecated. To use rules_kotlin locally, change
the WORKSPACE loading from:
local_repository(
name = "io_bazel_rules_kotlin",
path = "<path/to/rules_kotlin>",
)
load("@io_bazel_rules_kotlin//kotlin:dependencies.bzl", "kt_download_local_dev_dependencies")
kt_download_local_dev_dependencies()
To:
local_repository(
name = "release_archive",
path = "<path/to/rules_kotlin>/src/main/starklark/release_archive",
)
archive_repository(
name = "io_bazel_rules_kotlin",
)""")
_kt_download_local_dev_dependencies()
2 changes: 2 additions & 0 deletions kotlin/repositories.bzl
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
load(
"//src/main/starlark/core/repositories:initialize.bzl",
_kotlin_repositories = "kotlin_repositories",
_kotlinc_version = "kotlinc_version",
_versions = "versions",
)

kotlin_repositories = _kotlin_repositories
versions = _versions
kotlinc_version = _kotlinc_version
2 changes: 2 additions & 0 deletions src/main/starlark/core/repositories/initialize.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
load(":setup.bzl", "kt_configure")
load(
":initialize.release.bzl",
_kotlinc_version = "kotlinc_version",
_release_kotlin_repositories = "kotlin_repositories",
)
load(":versions.bzl", _versions = "versions")

#exports
versions = _versions
kotlinc_version = _kotlinc_version

def kotlin_repositories(compiler_release = versions.KOTLIN_CURRENT_COMPILER_RELEASE):
"""Call this in the WORKSPACE file to setup the Kotlin rules.
Expand Down
11 changes: 10 additions & 1 deletion src/main/starlark/core/repositories/initialize.release.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ load(
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load(":compiler.bzl", "kotlin_compiler_repository")
load(":configured_rules.bzl", "rules_repository")
load(":versions.bzl", _versions = "versions")
load(":versions.bzl", "version", _versions = "versions")

versions = _versions

Expand Down Expand Up @@ -102,3 +102,12 @@ def kotlin_repositories(
"@": "@%s" % KOTLIN_RULES.workspace_name,
},
)

def kotlinc_version(release, sha256):
return version(
version = release,
url_templates = [
"https://github.com/JetBrains/kotlin/releases/download/v{version}/kotlin-compiler-{version}.zip",
],
sha256 = sha256,
)
20 changes: 20 additions & 0 deletions src/main/starlark/core/repositories/setup.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_
load("@rules_jvm_external//:defs.bzl", "maven_install")
load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories")
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
load("@rules_android//android:rules.bzl", "android_ndk_repository", "android_sdk_repository")
load("//src/main/starlark/core/repositories:versions.bzl", "versions")

def kt_configure():
"""Setup dependencies. Must be called AFTER kt_download_local_dev_dependencies() """
Expand Down Expand Up @@ -58,3 +60,21 @@ def kt_configure():
stardoc_repositories()

bazel_skylib_workspace()

android_sdk_repository(
name = "androidsdk",
build_tools_version = versions.ANDROID.BUILD_TOOLS,
)

android_ndk_repository(name = "androidndk")

[
native.local_repository(
name = version,
path = "src/main/starlark/%s" % version,
repo_mapping = {
"@dev_io_bazel_rules_kotlin": "@",
},
)
for version in versions.CORE
]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit fa0ff96

Please sign in to comment.