diff --git a/README.md b/README.md index 18b785af3..8353bb437 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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() ``` @@ -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", @@ -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", @@ -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", diff --git a/WORKSPACE b/WORKSPACE index 07299bdc9..aa7128eb6 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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() @@ -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 -] diff --git a/examples/android/WORKSPACE b/examples/android/WORKSPACE index 6fed611d0..21ffd270e 100644 --- a/examples/android/WORKSPACE +++ b/examples/android/WORKSPACE @@ -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") diff --git a/examples/anvil/WORKSPACE b/examples/anvil/WORKSPACE index e47187dc1..944dac1a6 100644 --- a/examples/anvil/WORKSPACE +++ b/examples/anvil/WORKSPACE @@ -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") diff --git a/examples/associates/WORKSPACE b/examples/associates/WORKSPACE index 7382dbf6b..8605a1646 100644 --- a/examples/associates/WORKSPACE +++ b/examples/associates/WORKSPACE @@ -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") diff --git a/examples/dagger/WORKSPACE b/examples/dagger/WORKSPACE index 9563fa3ae..9c68e0251 100644 --- a/examples/dagger/WORKSPACE +++ b/examples/dagger/WORKSPACE @@ -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") diff --git a/examples/jetpack_compose/WORKSPACE b/examples/jetpack_compose/WORKSPACE index eb1273b57..344889636 100644 --- a/examples/jetpack_compose/WORKSPACE +++ b/examples/jetpack_compose/WORKSPACE @@ -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") diff --git a/examples/multiplex/WORKSPACE b/examples/multiplex/WORKSPACE index 16e6b8ff3..2be85a70c 100644 --- a/examples/multiplex/WORKSPACE +++ b/examples/multiplex/WORKSPACE @@ -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") diff --git a/examples/node/WORKSPACE b/examples/node/WORKSPACE index 6828a7385..1db77638c 100644 --- a/examples/node/WORKSPACE +++ b/examples/node/WORKSPACE @@ -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") diff --git a/examples/plugin/WORKSPACE b/examples/plugin/WORKSPACE index 36297bd96..fe0d6d25f 100644 --- a/examples/plugin/WORKSPACE +++ b/examples/plugin/WORKSPACE @@ -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") diff --git a/examples/trivial/WORKSPACE b/examples/trivial/WORKSPACE index 5ff78cdb4..99265a9cd 100644 --- a/examples/trivial/WORKSPACE +++ b/examples/trivial/WORKSPACE @@ -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") diff --git a/kotlin/dependencies.bzl b/kotlin/dependencies.bzl index 3246c3204..2fe01bffa 100644 --- a/kotlin/dependencies.bzl +++ b/kotlin/dependencies.bzl @@ -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 = "", +) + +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 = "/src/main/starklark/release_archive", +) + +archive_repository( + name = "io_bazel_rules_kotlin", +)""") + _kt_download_local_dev_dependencies() diff --git a/kotlin/repositories.bzl b/kotlin/repositories.bzl index 12ffad7f6..f9f26eaf4 100644 --- a/kotlin/repositories.bzl +++ b/kotlin/repositories.bzl @@ -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 diff --git a/src/main/starlark/core/repositories/initialize.bzl b/src/main/starlark/core/repositories/initialize.bzl index 30754babf..3c8ce8387 100644 --- a/src/main/starlark/core/repositories/initialize.bzl +++ b/src/main/starlark/core/repositories/initialize.bzl @@ -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. diff --git a/src/main/starlark/core/repositories/initialize.release.bzl b/src/main/starlark/core/repositories/initialize.release.bzl index 8fa8b89a3..93812d7b8 100644 --- a/src/main/starlark/core/repositories/initialize.release.bzl +++ b/src/main/starlark/core/repositories/initialize.release.bzl @@ -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 @@ -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, + ) diff --git a/src/main/starlark/core/repositories/setup.bzl b/src/main/starlark/core/repositories/setup.bzl index 7145da250..2c258ef30 100644 --- a/src/main/starlark/core/repositories/setup.bzl +++ b/src/main/starlark/core/repositories/setup.bzl @@ -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() """ @@ -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 + ] diff --git a/examples/release_archive/BUILD.bazel b/src/main/starlark/release_archive/BUILD.bazel similarity index 100% rename from examples/release_archive/BUILD.bazel rename to src/main/starlark/release_archive/BUILD.bazel diff --git a/examples/release_archive/README.md b/src/main/starlark/release_archive/README.md similarity index 100% rename from examples/release_archive/README.md rename to src/main/starlark/release_archive/README.md diff --git a/examples/release_archive/WORKSPACE b/src/main/starlark/release_archive/WORKSPACE similarity index 100% rename from examples/release_archive/WORKSPACE rename to src/main/starlark/release_archive/WORKSPACE diff --git a/examples/release_archive/repository.bzl b/src/main/starlark/release_archive/repository.bzl similarity index 100% rename from examples/release_archive/repository.bzl rename to src/main/starlark/release_archive/repository.bzl diff --git a/examples/release_archive/versions.bzl b/src/main/starlark/release_archive/versions.bzl similarity index 100% rename from examples/release_archive/versions.bzl rename to src/main/starlark/release_archive/versions.bzl