From 45cae781f16dac8fa69ddd306a255048a147d43d Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Thu, 10 Aug 2023 17:04:12 +0200 Subject: [PATCH 01/10] Remove unnecessary Java runtime dependencies (#1000) `kt_jvm_library` no longer depends on a Java runtime for the target platform, which ensures that cross-platform builds targeting platforms without standalone Java runtimes (e.g. Android) can succeed without hacks (currently, Bazel's local_jdk is marked as compatible with any target platform, but that will change in the future). --- kotlin/internal/jvm/jvm.bzl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/kotlin/internal/jvm/jvm.bzl b/kotlin/internal/jvm/jvm.bzl index 61fcb0ecc..822dd1597 100644 --- a/kotlin/internal/jvm/jvm.bzl +++ b/kotlin/internal/jvm/jvm.bzl @@ -149,6 +149,9 @@ _implicit_deps = { default = Label("@bazel_tools//tools/jdk:current_java_runtime"), cfg = "exec", ), +} + +_runnable_implicit_deps = { "_java_runtime": attr.label( default = Label("@bazel_tools//tools/jdk:current_java_runtime"), ), @@ -269,7 +272,7 @@ this is not transitive""", ), }) -_runnable_common_attr = utils.add_dicts(_common_attr, { +_runnable_common_attr = utils.add_dicts(_common_attr, _runnable_implicit_deps, { "jvm_flags": attr.string_list( doc = """A list of flags to embed in the wrapper script generated for running this binary. Note: does not yet support make variable substitution.""", @@ -287,6 +290,9 @@ _common_outputs = dict( _common_toolchains = [ _TOOLCHAIN_TYPE, _JAVA_TOOLCHAIN_TYPE, +] + +_runnable_common_toolchains = [ _JAVA_RUNTIME_TOOLCHAIN_TYPE, ] @@ -318,7 +324,7 @@ It is appropriate for building workspace utilities. `java_binary` should be pref }.items()), executable = True, outputs = _common_outputs, - toolchains = _common_toolchains, + toolchains = _common_toolchains + _runnable_common_toolchains, fragments = ["java"], # Required fragments of the target configuration host_fragments = ["java"], # Required fragments of the host configuration implementation = _kt_jvm_binary_impl, @@ -353,7 +359,7 @@ Setup a simple kotlin_test. executable = True, outputs = _common_outputs, test = True, - toolchains = _common_toolchains, + toolchains = _common_toolchains + _runnable_common_toolchains, implementation = _kt_jvm_junit_test_impl, fragments = ["java"], # Required fragments of the target configuration host_fragments = ["java"], # Required fragments of the host configuration From 20ff6ac82b801acbf28678e0ed325bbce957640e Mon Sep 17 00:00:00 2001 From: hvadehra Date: Fri, 11 Aug 2023 09:27:09 +0200 Subject: [PATCH 02/10] Migrate usages of deprecated `JavaInfo` fields (#1005) --- kotlin/internal/jvm/compile.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kotlin/internal/jvm/compile.bzl b/kotlin/internal/jvm/compile.bzl index 80cbf7a81..327a0bdc2 100644 --- a/kotlin/internal/jvm/compile.bzl +++ b/kotlin/internal/jvm/compile.bzl @@ -261,7 +261,7 @@ def _run_merge_jdeps_action(ctx, toolchains, jdeps, outputs, deps): ) # For sandboxing to work, and for this action to be deterministic, the compile jars need to be passed as inputs - inputs = depset(jdeps, transitive = [depset([], transitive = [dep.transitive_deps for dep in deps])]) + inputs = depset(jdeps, transitive = [depset([], transitive = [dep.transitive_compile_time_jars for dep in deps])]) ctx.actions.run( mnemonic = mnemonic, From ad66c8593ef9d4ed37c8e223831a1ff138fc79d3 Mon Sep 17 00:00:00 2001 From: Ben Lee Date: Sat, 12 Aug 2023 22:31:27 +0200 Subject: [PATCH 03/10] Update rules_jvm_external to 5.3 (#1009) --- examples/android/WORKSPACE | 5 ++++- examples/anvil/WORKSPACE | 5 ++++- examples/associates/WORKSPACE | 5 ++++- examples/dagger/WORKSPACE | 5 ++++- examples/deps/WORKSPACE | 5 ++++- examples/jetpack_compose/WORKSPACE | 5 ++++- examples/ksp/WORKSPACE | 5 ++++- examples/node/WORKSPACE | 5 ++++- examples/plugin/WORKSPACE | 5 ++++- examples/trivial/WORKSPACE | 5 ++++- src/main/starlark/core/repositories/download.bzl | 2 +- src/main/starlark/core/repositories/versions.bzl | 4 ++-- 12 files changed, 43 insertions(+), 13 deletions(-) diff --git a/examples/android/WORKSPACE b/examples/android/WORKSPACE index fa8c4f0c1..ab1bc65b9 100644 --- a/examples/android/WORKSPACE +++ b/examples/android/WORKSPACE @@ -33,7 +33,10 @@ http_archive( name = "rules_jvm_external", sha256 = versions.RULES_JVM_EXTERNAL_SHA, strip_prefix = "rules_jvm_external-%s" % versions.RULES_JVM_EXTERNAL_TAG, - url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % versions.RULES_JVM_EXTERNAL_TAG, + url = "https://github.com/bazelbuild/rules_jvm_external/releases/download/%s/rules_jvm_external-%s.tar.gz" % ( + versions.RULES_JVM_EXTERNAL_TAG, + versions.RULES_JVM_EXTERNAL_TAG, + ), ) load("@rules_jvm_external//:defs.bzl", "maven_install") diff --git a/examples/anvil/WORKSPACE b/examples/anvil/WORKSPACE index d1a1b25e0..1d668ae03 100644 --- a/examples/anvil/WORKSPACE +++ b/examples/anvil/WORKSPACE @@ -51,7 +51,10 @@ http_archive( name = "rules_jvm_external", sha256 = versions.RULES_JVM_EXTERNAL_SHA, strip_prefix = "rules_jvm_external-%s" % versions.RULES_JVM_EXTERNAL_TAG, - url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % versions.RULES_JVM_EXTERNAL_TAG, + url = "https://github.com/bazelbuild/rules_jvm_external/releases/download/%s/rules_jvm_external-%s.tar.gz" % ( + versions.RULES_JVM_EXTERNAL_TAG, + versions.RULES_JVM_EXTERNAL_TAG, + ), ) load("@rules_jvm_external//:defs.bzl", "maven_install") diff --git a/examples/associates/WORKSPACE b/examples/associates/WORKSPACE index a08b43dbf..2c83af27f 100644 --- a/examples/associates/WORKSPACE +++ b/examples/associates/WORKSPACE @@ -39,7 +39,10 @@ http_archive( name = "rules_jvm_external", sha256 = versions.RULES_JVM_EXTERNAL_SHA, strip_prefix = "rules_jvm_external-%s" % versions.RULES_JVM_EXTERNAL_TAG, - url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % versions.RULES_JVM_EXTERNAL_TAG, + url = "https://github.com/bazelbuild/rules_jvm_external/releases/download/%s/rules_jvm_external-%s.tar.gz" % ( + versions.RULES_JVM_EXTERNAL_TAG, + versions.RULES_JVM_EXTERNAL_TAG, + ), ) load("@rules_jvm_external//:defs.bzl", "maven_install") diff --git a/examples/dagger/WORKSPACE b/examples/dagger/WORKSPACE index 356538adf..9339a888a 100644 --- a/examples/dagger/WORKSPACE +++ b/examples/dagger/WORKSPACE @@ -21,7 +21,10 @@ http_archive( name = "rules_jvm_external", sha256 = versions.RULES_JVM_EXTERNAL_SHA, strip_prefix = "rules_jvm_external-%s" % versions.RULES_JVM_EXTERNAL_TAG, - url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % versions.RULES_JVM_EXTERNAL_TAG, + url = "https://github.com/bazelbuild/rules_jvm_external/releases/download/%s/rules_jvm_external-%s.tar.gz" % ( + versions.RULES_JVM_EXTERNAL_TAG, + versions.RULES_JVM_EXTERNAL_TAG, + ), ) load("@rules_jvm_external//:defs.bzl", "maven_install") diff --git a/examples/deps/WORKSPACE b/examples/deps/WORKSPACE index c84a4edb9..533055d22 100644 --- a/examples/deps/WORKSPACE +++ b/examples/deps/WORKSPACE @@ -31,7 +31,10 @@ http_archive( name = "rules_jvm_external", sha256 = versions.RULES_JVM_EXTERNAL_SHA, strip_prefix = "rules_jvm_external-%s" % versions.RULES_JVM_EXTERNAL_TAG, - url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % versions.RULES_JVM_EXTERNAL_TAG, + url = "https://github.com/bazelbuild/rules_jvm_external/releases/download/%s/rules_jvm_external-%s.tar.gz" % ( + versions.RULES_JVM_EXTERNAL_TAG, + versions.RULES_JVM_EXTERNAL_TAG, + ), ) load("@rules_jvm_external//:defs.bzl", "maven_install") diff --git a/examples/jetpack_compose/WORKSPACE b/examples/jetpack_compose/WORKSPACE index 0bcb0dbab..278c312a2 100644 --- a/examples/jetpack_compose/WORKSPACE +++ b/examples/jetpack_compose/WORKSPACE @@ -38,7 +38,10 @@ http_archive( name = "rules_jvm_external", sha256 = versions.RULES_JVM_EXTERNAL_SHA, strip_prefix = "rules_jvm_external-%s" % versions.RULES_JVM_EXTERNAL_TAG, - url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % versions.RULES_JVM_EXTERNAL_TAG, + url = "https://github.com/bazelbuild/rules_jvm_external/releases/download/%s/rules_jvm_external-%s.tar.gz" % ( + versions.RULES_JVM_EXTERNAL_TAG, + versions.RULES_JVM_EXTERNAL_TAG, + ), ) load("@rules_jvm_external//:defs.bzl", "maven_install") diff --git a/examples/ksp/WORKSPACE b/examples/ksp/WORKSPACE index 44a8fb20b..078721755 100644 --- a/examples/ksp/WORKSPACE +++ b/examples/ksp/WORKSPACE @@ -32,7 +32,10 @@ http_archive( name = "rules_jvm_external", sha256 = versions.RULES_JVM_EXTERNAL_SHA, strip_prefix = "rules_jvm_external-%s" % versions.RULES_JVM_EXTERNAL_TAG, - url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % versions.RULES_JVM_EXTERNAL_TAG, + url = "https://github.com/bazelbuild/rules_jvm_external/releases/download/%s/rules_jvm_external-%s.tar.gz" % ( + versions.RULES_JVM_EXTERNAL_TAG, + versions.RULES_JVM_EXTERNAL_TAG, + ), ) load("@rules_jvm_external//:defs.bzl", "maven_install") diff --git a/examples/node/WORKSPACE b/examples/node/WORKSPACE index 606684823..57cc23a99 100644 --- a/examples/node/WORKSPACE +++ b/examples/node/WORKSPACE @@ -25,7 +25,10 @@ http_archive( name = "rules_jvm_external", sha256 = versions.RULES_JVM_EXTERNAL_SHA, strip_prefix = "rules_jvm_external-%s" % versions.RULES_JVM_EXTERNAL_TAG, - url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % versions.RULES_JVM_EXTERNAL_TAG, + url = "https://github.com/bazelbuild/rules_jvm_external/releases/download/%s/rules_jvm_external-%s.tar.gz" % ( + versions.RULES_JVM_EXTERNAL_TAG, + versions.RULES_JVM_EXTERNAL_TAG, + ), ) http_archive( diff --git a/examples/plugin/WORKSPACE b/examples/plugin/WORKSPACE index 6d523a040..8dc608912 100644 --- a/examples/plugin/WORKSPACE +++ b/examples/plugin/WORKSPACE @@ -23,7 +23,10 @@ http_archive( name = "rules_jvm_external", sha256 = versions.RULES_JVM_EXTERNAL_SHA, strip_prefix = "rules_jvm_external-%s" % versions.RULES_JVM_EXTERNAL_TAG, - url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % versions.RULES_JVM_EXTERNAL_TAG, + url = "https://github.com/bazelbuild/rules_jvm_external/releases/download/%s/rules_jvm_external-%s.tar.gz" % ( + versions.RULES_JVM_EXTERNAL_TAG, + versions.RULES_JVM_EXTERNAL_TAG, + ), ) load("@rules_jvm_external//:defs.bzl", "maven_install") diff --git a/examples/trivial/WORKSPACE b/examples/trivial/WORKSPACE index 90eb8a48f..75435ae87 100644 --- a/examples/trivial/WORKSPACE +++ b/examples/trivial/WORKSPACE @@ -23,7 +23,10 @@ http_archive( name = "rules_jvm_external", sha256 = versions.RULES_JVM_EXTERNAL_SHA, strip_prefix = "rules_jvm_external-%s" % versions.RULES_JVM_EXTERNAL_TAG, - url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % versions.RULES_JVM_EXTERNAL_TAG, + url = "https://github.com/bazelbuild/rules_jvm_external/releases/download/%s/rules_jvm_external-%s.tar.gz" % ( + versions.RULES_JVM_EXTERNAL_TAG, + versions.RULES_JVM_EXTERNAL_TAG, + ), ) load("@rules_jvm_external//:defs.bzl", "maven_install") diff --git a/src/main/starlark/core/repositories/download.bzl b/src/main/starlark/core/repositories/download.bzl index 2aa8d703c..0ce95d020 100644 --- a/src/main/starlark/core/repositories/download.bzl +++ b/src/main/starlark/core/repositories/download.bzl @@ -63,7 +63,7 @@ def kt_download_local_dev_dependencies(): name = "rules_jvm_external", sha256 = versions.RULES_JVM_EXTERNAL_SHA, strip_prefix = "rules_jvm_external-%s" % versions.RULES_JVM_EXTERNAL_TAG, - url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % versions.RULES_JVM_EXTERNAL_TAG, + url = "https://github.com/bazelbuild/rules_jvm_external/releases/download/%s/rules_jvm_external-%s.tar.gz" % (versions.RULES_JVM_EXTERNAL_TAG, versions.RULES_JVM_EXTERNAL_TAG), ) versions.use_repository( diff --git a/src/main/starlark/core/repositories/versions.bzl b/src/main/starlark/core/repositories/versions.bzl index 5ee0999de..74979ce1b 100644 --- a/src/main/starlark/core/repositories/versions.bzl +++ b/src/main/starlark/core/repositories/versions.bzl @@ -35,8 +35,8 @@ versions = struct( SKYLIB_SHA = "f7be3474d42aae265405a592bb7da8e171919d74c16f082a5457840f06054728", PROTOBUF_VERSION = "3.11.3", PROTOBUF_SHA = "cf754718b0aa945b00550ed7962ddc167167bd922b842199eeb6505e6f344852", - RULES_JVM_EXTERNAL_TAG = "4.4.2", - RULES_JVM_EXTERNAL_SHA = "735602f50813eb2ea93ca3f5e43b1959bd80b213b836a07a62a29d757670b77b", + RULES_JVM_EXTERNAL_TAG = "5.3", + RULES_JVM_EXTERNAL_SHA = "d31e369b854322ca5098ea12c69d7175ded971435e55c18dd9dd5f29cc5249ac", RULES_PROTO = version( version = "5.3.0-21.7", sha256 = "dc3fb206a2cb3441b485eb1e423165b231235a1ea9b031b4433cf7bc1fa460dd", From 4b95bd3aa2b1c2e85fd8dacf3b90bec615992b6f Mon Sep 17 00:00:00 2001 From: Ben Lee Date: Sun, 13 Aug 2023 20:08:51 -0400 Subject: [PATCH 04/10] Update Bazel to 6.3.2 (#1007) --- .bazelci/presubmit.yml | 2 +- .bazelversion | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 30c1f22b0..60dac1660 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -1,6 +1,6 @@ --- validate_config: 1 -bazel: 6.1.1 +bazel: 6.3.2 buildifier: version: 6.1.0 # no lint warnings for the moment. They are basically a smoke alarm in hell. diff --git a/.bazelversion b/.bazelversion index f3b5af39e..91e4a9f26 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -6.1.1 +6.3.2 From b8892e6a2f52590257aac85e9f0add67b115bca2 Mon Sep 17 00:00:00 2001 From: Ben Lee Date: Sun, 13 Aug 2023 20:09:12 -0400 Subject: [PATCH 05/10] Add rules_java 6.4.0 (#1010) --- .../starlark/core/repositories/initialize.release.bzl | 6 ++++++ src/main/starlark/core/repositories/versions.bzl | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/src/main/starlark/core/repositories/initialize.release.bzl b/src/main/starlark/core/repositories/initialize.release.bzl index dccdfb492..791a2297c 100644 --- a/src/main/starlark/core/repositories/initialize.release.bzl +++ b/src/main/starlark/core/repositories/initialize.release.bzl @@ -95,6 +95,12 @@ def kotlin_repositories( version = versions.RULES_PYTHON, ) + versions.use_repository( + name = "rules_java", + rule = http_archive, + version = versions.RULES_JAVA, + ) + # See note in versions.bzl before updating bazel_skylib maybe( http_archive, diff --git a/src/main/starlark/core/repositories/versions.bzl b/src/main/starlark/core/repositories/versions.bzl index 74979ce1b..83869e816 100644 --- a/src/main/starlark/core/repositories/versions.bzl +++ b/src/main/starlark/core/repositories/versions.bzl @@ -102,6 +102,14 @@ versions = struct( ], sha256 = "a644da969b6824cc87f8fe7b18101a8a6c57da5db39caa6566ec6109f37d2141", ), + # needed for rules_pkg and java + RULES_JAVA = version( + version = "6.4.0", + url_templates = [ + "https://github.com/bazelbuild/rules_java/releases/download/{version}/rules_java-{version}.tar.gz", + ], + sha256 = "27abf8d2b26f4572ba4112ae8eb4439513615018e03a299f85a8460f6992f6a3", + ), RULES_LICENSE = version( version = "0.0.3", url_templates = [ From 7355e7c8561599b23184ae756f63cee66a485efa Mon Sep 17 00:00:00 2001 From: Ben Lee Date: Fri, 18 Aug 2023 16:05:35 -0400 Subject: [PATCH 06/10] Group the all_tests jobs together in presubmit.yml (#1008) --- .bazelci/presubmit.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 60dac1660..446efb6b4 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -12,6 +12,9 @@ tasks: - "//:all_tests" build_targets: - "//:rules_kotlin_release" + macos: + test_targets: + - "//:all_tests" rbe_ubuntu1604: test_targets: - "--" @@ -24,9 +27,6 @@ tasks: # Override the default worker strategy for remote builds (worker strategy # cannot be used with remote builds) - "--strategy=KotlinCompile=remote" - macos: - test_targets: - - "//:all_tests" example-android: name: "Example - Android" platform: ubuntu1804 From 9994b6aeae68b51503828cf640c2350eff66e829 Mon Sep 17 00:00:00 2001 From: Ben Lee Date: Fri, 18 Aug 2023 16:34:08 -0400 Subject: [PATCH 07/10] Disable strict deps for Android example (#1013) --- examples/android/bzl/BUILD.bazel | 4 ---- 1 file changed, 4 deletions(-) diff --git a/examples/android/bzl/BUILD.bazel b/examples/android/bzl/BUILD.bazel index dc16bfa70..116da98d2 100644 --- a/examples/android/bzl/BUILD.bazel +++ b/examples/android/bzl/BUILD.bazel @@ -12,10 +12,6 @@ kt_javac_options( define_kt_toolchain( name = "experimental_toolchain", api_version = "1.5", - # TODO(630): enable when the reduced classpath can correctly manage transitive maven dependencies. - # experimental_reduce_classpath_mode = "KOTLINBUILDER_REDUCED", - experimental_report_unused_deps = "warn", - experimental_strict_kotlin_deps = "warn", experimental_use_abi_jars = True, javac_options = ":default_javac_options", kotlinc_options = ":default_kotlinc_options", From 23a20dd0d3117069982920e34f4b0378191cb36c Mon Sep 17 00:00:00 2001 From: Ben Lee Date: Fri, 18 Aug 2023 16:35:54 -0400 Subject: [PATCH 08/10] Update kt_java_stub_template to 6.2.1 (#992) --- src/main/starlark/core/repositories/initialize.release.bzl | 2 +- src/main/starlark/core/repositories/versions.bzl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/starlark/core/repositories/initialize.release.bzl b/src/main/starlark/core/repositories/initialize.release.bzl index 791a2297c..a61aafc0c 100644 --- a/src/main/starlark/core/repositories/initialize.release.bzl +++ b/src/main/starlark/core/repositories/initialize.release.bzl @@ -70,7 +70,7 @@ def kotlin_repositories( versions.BAZEL_JAVA_LAUNCHER_VERSION + "/src/main/java/com/google/devtools/build/lib/bazel/rules/java/" + "java_stub_template.txt")], - sha256 = "ab1370fd990a8bff61a83c7bd94746a3401a6d5d2299e54b1b6bc02db4f87f68", + sha256 = "78e29525872594ffc783c825f428b3e61d4f3e632f46eaa64f004b2814c4a612", ) maybe( diff --git a/src/main/starlark/core/repositories/versions.bzl b/src/main/starlark/core/repositories/versions.bzl index 83869e816..809854ef0 100644 --- a/src/main/starlark/core/repositories/versions.bzl +++ b/src/main/starlark/core/repositories/versions.bzl @@ -53,7 +53,7 @@ versions = struct( "https://github.com/bazelbuild/stardoc/releases/download/{version}/stardoc-{version}.tar.gz", ], ), - BAZEL_JAVA_LAUNCHER_VERSION = "5.0.0", + BAZEL_JAVA_LAUNCHER_VERSION = "6.2.1", PINTEREST_KTLINT = version( version = "0.49.1", url_templates = [ From afff5acb1d8518f5ddc31c68c4420ca5927fc4a4 Mon Sep 17 00:00:00 2001 From: Ben Lee Date: Fri, 18 Aug 2023 16:44:12 -0400 Subject: [PATCH 09/10] Avoid running java_common#compile against KSP generated outputs (#990) --- kotlin/internal/jvm/compile.bzl | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/kotlin/internal/jvm/compile.bzl b/kotlin/internal/jvm/compile.bzl index 327a0bdc2..cc692e96e 100644 --- a/kotlin/internal/jvm/compile.bzl +++ b/kotlin/internal/jvm/compile.bzl @@ -537,7 +537,8 @@ def kt_jvm_produce_jar_actions(ctx, rule_kind): rule_kind = rule_kind, toolchains = toolchains, srcs = srcs, - generated_src_jars = [], + generated_kapt_src_jars = [], + generated_ksp_src_jars = [], associates = associates, compile_deps = compile_deps, deps_artifacts = deps_artifacts, @@ -626,7 +627,8 @@ def _run_kt_java_builder_actions( rule_kind, toolchains, srcs, - generated_src_jars, + generated_kapt_src_jars, + generated_ksp_src_jars, associates, compile_deps, deps_artifacts, @@ -660,7 +662,7 @@ def _run_kt_java_builder_actions( transitive_runtime_jars = transitive_runtime_jars, plugins = plugins, ) - generated_src_jars.append(kapt_outputs.ap_generated_src_jar) + generated_kapt_src_jars.append(kapt_outputs.ap_generated_src_jar) output_jars.append(kapt_outputs.kapt_generated_class_jar) kt_stubs_for_java.append( JavaInfo( @@ -684,7 +686,7 @@ def _run_kt_java_builder_actions( transitive_runtime_jars = transitive_runtime_jars, plugins = plugins, ) - generated_src_jars.append(ksp_outputs.ksp_generated_class_jar) + generated_ksp_src_jars.append(ksp_outputs.ksp_generated_class_jar) java_infos = [] @@ -713,7 +715,7 @@ def _run_kt_java_builder_actions( rule_kind = rule_kind, toolchains = toolchains, srcs = srcs, - generated_src_jars = generated_src_jars, + generated_src_jars = generated_kapt_src_jars + generated_ksp_src_jars, associates = associates, compile_deps = compile_deps, deps_artifacts = deps_artifacts, @@ -744,7 +746,7 @@ def _run_kt_java_builder_actions( # Build Java # If there is Java source or KAPT generated Java source compile that Java and fold it into # the final ABI jar. Otherwise just use the KT ABI jar as final ABI jar. - if srcs.java or generated_src_jars or srcs.src_jars: + if srcs.java or generated_kapt_src_jars or srcs.src_jars: javac_opts = javac_options_to_flags(toolchains.kt.javac_options) # Kotlin takes care of annotation processing. Note that JavaBuilder "discovers" @@ -754,7 +756,7 @@ def _run_kt_java_builder_actions( java_info = java_common.compile( ctx, source_files = srcs.java, - source_jars = generated_src_jars + srcs.src_jars, + source_jars = generated_kapt_src_jars + srcs.src_jars, output = ctx.actions.declare_file(ctx.label.name + "-java.jar"), deps = compile_deps.deps + kt_stubs_for_java, java_toolchain = toolchains.java, @@ -815,7 +817,7 @@ def _run_kt_java_builder_actions( return struct( output_jars = output_jars, - generated_src_jars = generated_src_jars, + generated_src_jars = generated_kapt_src_jars + generated_ksp_src_jars, annotation_processing = annotation_processing, ) From 8d79e6a520df5a43c195bf92a31e7539fbb2faae Mon Sep 17 00:00:00 2001 From: Ben Lee Date: Fri, 8 Sep 2023 23:05:03 +0000 Subject: [PATCH 10/10] Move the KSP and compiler target definitions into rules_kotlin (#1014) * Move the KSP and compiler target definitions into rules_kotlin * Docs * Fix JS * More fixes * More * Docs --- README.md | 2 +- docs/kotlin.md | 4 +- examples/android/libKtAndroid/BUILD.bazel | 2 +- examples/plugin/src/allopen/BUILD | 2 +- examples/plugin/src/allopennoarg/BUILD | 6 +- examples/plugin/src/noarg/BUILD | 4 +- examples/plugin/src/parcelize/BUILD | 4 +- examples/plugin/src/sam_with_receiver/BUILD | 2 +- examples/plugin/src/serialization/BUILD | 2 +- kotlin/BUILD | 1 + kotlin/compiler/BUILD | 32 ++++ kotlin/compiler/BUILD.release.bazel | 23 +++ kotlin/compiler/compiler.bzl | 127 +++++++++++++++ kotlin/compiler/ksp.bzl | 42 +++++ kotlin/internal/js/js.bzl | 4 +- kotlin/internal/jvm/jvm.bzl | 9 +- kotlin/internal/toolchains.bzl | 12 +- src/main/kotlin/BUILD.release.bazel | 21 +-- src/main/kotlin/bootstrap.bzl | 8 +- src/main/kotlin/io/bazel/kotlin/builder/BUILD | 8 +- .../io/bazel/kotlin/builder/cmd/BUILD.bazel | 21 +-- .../io/bazel/kotlin/builder/tasks/BUILD.bazel | 2 +- .../kotlin/builder/toolchain/BUILD.bazel | 10 +- .../io/bazel/kotlin/compiler/BUILD.bazel | 6 +- .../io/bazel/kotlin/generate/BUILD.bazel | 4 +- .../kotlin/io/bazel/kotlin/plugin/BUILD.bazel | 2 +- .../io/bazel/kotlin/plugin/jdeps/BUILD.bazel | 2 +- src/main/starlark/BUILD.bazel | 5 +- src/main/starlark/core/options/BUILD.bazel | 7 +- src/main/starlark/core/repositories/BUILD | 3 +- .../BUILD.com_github_google_ksp.bazel | 16 -- .../BUILD.com_github_jetbrains_kotlin.bazel | 20 +++ .../repositories/{kotlin => }/compiler.bzl | 21 +-- .../core/repositories/initialize.release.bzl | 4 +- .../starlark/core/repositories/kotlin/BUILD | 9 -- .../BUILD.com_github_jetbrains_kotlin.bazel | 146 ------------------ src/main/starlark/core/repositories/ksp.bzl | 7 - src/test/kotlin/io/bazel/kotlin/BUILD | 4 +- src/test/kotlin/io/bazel/kotlin/builder/BUILD | 4 +- .../builder/KotlinAbstractTestBuilder.java | 10 +- .../kotlin/builder/KotlinJvmTestBuilder.java | 10 +- src/test/kotlin/io/bazel/kotlin/defs.bzl | 18 +-- .../io/bazel/kotlin/integration/BUILD.bazel | 4 +- 43 files changed, 353 insertions(+), 297 deletions(-) create mode 100644 kotlin/compiler/BUILD create mode 100644 kotlin/compiler/BUILD.release.bazel create mode 100644 kotlin/compiler/compiler.bzl create mode 100644 kotlin/compiler/ksp.bzl create mode 100644 src/main/starlark/core/repositories/BUILD.com_github_jetbrains_kotlin.bazel rename src/main/starlark/core/repositories/{kotlin => }/compiler.bzl (69%) delete mode 100644 src/main/starlark/core/repositories/kotlin/BUILD.com_github_jetbrains_kotlin.bazel diff --git a/README.md b/README.md index 81fc089a1..b9cce1123 100644 --- a/README.md +++ b/README.md @@ -320,7 +320,7 @@ kt_compiler_plugin( "annotation": "plugin.allopen.OpenForTesting", }, deps = [ - "@com_github_jetbrains_kotlin//:allopen-compiler-plugin", + "//kotlin/compiler:allopen-compiler-plugin", ], ) diff --git a/docs/kotlin.md b/docs/kotlin.md index 534ac1c61..26720f7a1 100755 --- a/docs/kotlin.md +++ b/docs/kotlin.md @@ -211,7 +211,7 @@ kt_jvm_test(name, name, ALL_DIRECTORY_TYPES = diff --git a/src/test/kotlin/io/bazel/kotlin/defs.bzl b/src/test/kotlin/io/bazel/kotlin/defs.bzl index b9ebd5077..fbc96bfe7 100644 --- a/src/test/kotlin/io/bazel/kotlin/defs.bzl +++ b/src/test/kotlin/io/bazel/kotlin/defs.bzl @@ -34,15 +34,15 @@ def kt_rules_test(name, **kwargs): "//src/main/kotlin/io/bazel/kotlin/compiler", "//src/main/kotlin:skip-code-gen", "//src/main/kotlin:jdeps-gen", - "@com_github_google_ksp//:symbol-processing-api", - "@com_github_google_ksp//:symbol-processing-cmdline", - "@com_github_jetbrains_kotlin//:annotations", - "@com_github_jetbrains_kotlin//:jvm-abi-gen", - "@com_github_jetbrains_kotlin//:kotlin-compiler", - "@com_github_jetbrains_kotlin//:kotlin-stdlib", - "@com_github_jetbrains_kotlin//:kotlin-stdlib-jdk7", - "@com_github_jetbrains_kotlin//:kotlin-stdlib-jdk8", - "@com_github_jetbrains_kotlin//:kotlin-annotation-processing", + "//kotlin/compiler:symbol-processing-api", + "//kotlin/compiler:symbol-processing-cmdline", + "//kotlin/compiler:annotations", + "//kotlin/compiler:jvm-abi-gen", + "//kotlin/compiler:kotlin-compiler", + "//kotlin/compiler:kotlin-stdlib", + "//kotlin/compiler:kotlin-stdlib-jdk7", + "//kotlin/compiler:kotlin-stdlib-jdk8", + "//kotlin/compiler:kotlin-annotation-processing", ] + args["data"]: if dep not in args["data"]: args["data"].append(dep) diff --git a/src/test/kotlin/io/bazel/kotlin/integration/BUILD.bazel b/src/test/kotlin/io/bazel/kotlin/integration/BUILD.bazel index bbe02ffec..1bf2ffb97 100644 --- a/src/test/kotlin/io/bazel/kotlin/integration/BUILD.bazel +++ b/src/test/kotlin/io/bazel/kotlin/integration/BUILD.bazel @@ -14,7 +14,7 @@ kt_jvm_test( srcs = ["WriteWorkspaceTest.kt"], deps = [ ":lib", - "@com_github_jetbrains_kotlin//:kotlin-test", + "//kotlin/compiler:kotlin-test", "@kotlin_rules_maven//:com_google_truth_truth", "@kotlin_rules_maven//:junit_junit", ], @@ -30,7 +30,7 @@ kt_jvm_test( test_class = "io.bazel.kotlin.integration.MixedSourceCompileTest", deps = [ ":lib", - "@com_github_jetbrains_kotlin//:kotlin-test", + "//kotlin/compiler:kotlin-test", "@kotlin_rules_maven//:com_google_truth_truth", "@kotlin_rules_maven//:junit_junit", ],