From 6ac194c6bd481d0403a488c17836a665d27bf6d4 Mon Sep 17 00:00:00 2001 From: Benjamin Lee Date: Fri, 18 Aug 2023 14:23:45 -0700 Subject: [PATCH 1/6] Move the KSP and compiler target definitions into rules_kotlin --- README.md | 2 +- 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/core/options/BUILD.bazel | 3 - src/main/starlark/core/repositories/BUILD | 2 + .../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 | 2 - .../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 +- 41 files changed, 347 insertions(+), 282 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/examples/android/libKtAndroid/BUILD.bazel b/examples/android/libKtAndroid/BUILD.bazel index c8eb3affb..a75d9a82a 100644 --- a/examples/android/libKtAndroid/BUILD.bazel +++ b/examples/android/libKtAndroid/BUILD.bazel @@ -8,7 +8,7 @@ kt_compiler_plugin( id = "org.jetbrains.kotlin.serialization", stubs_phase = True, deps = [ - "@com_github_jetbrains_kotlin//:kotlinx-serialization-compiler-plugin", + "@io_bazel_rules_kotlin//kotlin/compiler:kotlinx-serialization-compiler-plugin", ], ) diff --git a/examples/plugin/src/allopen/BUILD b/examples/plugin/src/allopen/BUILD index 39f10f566..df40efe5d 100644 --- a/examples/plugin/src/allopen/BUILD +++ b/examples/plugin/src/allopen/BUILD @@ -10,7 +10,7 @@ kt_compiler_plugin( }, stubs_phase = True, deps = [ - "@com_github_jetbrains_kotlin//:allopen-compiler-plugin", + "@io_bazel_rules_kotlin//kotlin/compiler:allopen-compiler-plugin", ], ) diff --git a/examples/plugin/src/allopennoarg/BUILD b/examples/plugin/src/allopennoarg/BUILD index be7f31afb..3f89c1ef0 100644 --- a/examples/plugin/src/allopennoarg/BUILD +++ b/examples/plugin/src/allopennoarg/BUILD @@ -10,7 +10,7 @@ kt_compiler_plugin( }, stubs_phase = True, deps = [ - "@com_github_jetbrains_kotlin//:allopen-compiler-plugin", + "@io_bazel_rules_kotlin//kotlin/compiler:allopen-compiler-plugin", ], ) @@ -23,7 +23,7 @@ kt_compiler_plugin( }, stubs_phase = True, deps = [ - "@com_github_jetbrains_kotlin//:noarg-compiler-plugin", + "@io_bazel_rules_kotlin//kotlin/compiler:noarg-compiler-plugin", ], ) @@ -64,7 +64,7 @@ kt_jvm_test( test_class = "plugin.allopennoarg.UserHasNoargConstructorTest", deps = [ ":user", - "@com_github_jetbrains_kotlin//:kotlin-reflect", + "@io_bazel_rules_kotlin//kotlin/compiler:kotlin-reflect", "@maven//:junit_junit", ], ) diff --git a/examples/plugin/src/noarg/BUILD b/examples/plugin/src/noarg/BUILD index 4d786ebc2..1e57e693a 100644 --- a/examples/plugin/src/noarg/BUILD +++ b/examples/plugin/src/noarg/BUILD @@ -10,7 +10,7 @@ kt_compiler_plugin( }, stubs_phase = True, deps = [ - "@com_github_jetbrains_kotlin//:noarg-compiler-plugin", + "@io_bazel_rules_kotlin//kotlin/compiler:noarg-compiler-plugin", ], ) @@ -35,7 +35,7 @@ kt_jvm_test( test_class = "plugin.noarg.UserHasNoargConstructorTest", deps = [ ":user", - "@com_github_jetbrains_kotlin//:kotlin-reflect", + "@io_bazel_rules_kotlin//kotlin/compiler:kotlin-reflect", "@maven//:junit_junit", ], ) diff --git a/examples/plugin/src/parcelize/BUILD b/examples/plugin/src/parcelize/BUILD index e0ac8be71..945388777 100644 --- a/examples/plugin/src/parcelize/BUILD +++ b/examples/plugin/src/parcelize/BUILD @@ -8,7 +8,7 @@ kt_compiler_plugin( id = "org.jetbrains.kotlin.parcelize", stubs_phase = True, deps = [ - "@com_github_jetbrains_kotlin//:parcelize-compiler-plugin", + "@io_bazel_rules_kotlin//kotlin/compiler:parcelize-compiler-plugin", ], ) @@ -21,7 +21,7 @@ kt_jvm_library( ], visibility = ["//visibility:public"], exports = [ - "@com_github_jetbrains_kotlin//:parcelize-runtime", + "@io_bazel_rules_kotlin//kotlin/compiler:parcelize-runtime", ], ) diff --git a/examples/plugin/src/sam_with_receiver/BUILD b/examples/plugin/src/sam_with_receiver/BUILD index 33e518485..a2d4a43f7 100644 --- a/examples/plugin/src/sam_with_receiver/BUILD +++ b/examples/plugin/src/sam_with_receiver/BUILD @@ -11,7 +11,7 @@ kt_compiler_plugin( }, stubs_phase = True, deps = [ - "@com_github_jetbrains_kotlin//:sam-with-receiver-compiler-plugin", + "@io_bazel_rules_kotlin//kotlin/compiler:sam-with-receiver-compiler-plugin", ], ) diff --git a/examples/plugin/src/serialization/BUILD b/examples/plugin/src/serialization/BUILD index 3943085a6..1d8b7a5cb 100644 --- a/examples/plugin/src/serialization/BUILD +++ b/examples/plugin/src/serialization/BUILD @@ -7,7 +7,7 @@ kt_compiler_plugin( id = "org.jetbrains.kotlin.serialization", stubs_phase = True, deps = [ - "@com_github_jetbrains_kotlin//:kotlinx-serialization-compiler-plugin", + "@io_bazel_rules_kotlin//kotlin/compiler:kotlinx-serialization-compiler-plugin", ], ) diff --git a/kotlin/BUILD b/kotlin/BUILD index e5919ea1b..8ef4e35c4 100644 --- a/kotlin/BUILD +++ b/kotlin/BUILD @@ -28,6 +28,7 @@ release_archive( "BUILD.release.bazel": "BUILD.bazel", }, deps = [ + "//kotlin/compiler:pkg", "//kotlin/internal:pkg", "//kotlin/settings:pkg", ], diff --git a/kotlin/compiler/BUILD b/kotlin/compiler/BUILD new file mode 100644 index 000000000..2afe7199a --- /dev/null +++ b/kotlin/compiler/BUILD @@ -0,0 +1,32 @@ +# Copyright 2020 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. +load(":compiler.bzl", "kt_configure_compiler") +load(":ksp.bzl", "kt_configure_ksp") +load("//src/main/starlark/release:packager.bzl", "release_archive") + +package(default_visibility = ["//visibility:public"]) + +# Configures the compiler +kt_configure_compiler() + +# Configures the KSP plugins +kt_configure_ksp() + +release_archive( + name = "pkg", + srcs = glob(["*.bzl"]), + src_map = { + "BUILD.release.bazel": "BUILD.bazel", + }, +) diff --git a/kotlin/compiler/BUILD.release.bazel b/kotlin/compiler/BUILD.release.bazel new file mode 100644 index 000000000..a512a021c --- /dev/null +++ b/kotlin/compiler/BUILD.release.bazel @@ -0,0 +1,23 @@ +# Copyright 2020 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. +load(":compiler.bzl", "kt_configure_compiler") +load(":ksp.bzl", "kt_configure_ksp") + +package(default_visibility = ["//visibility:public"]) + +# Configures the compiler +kt_configure_compiler() + +# Configures the KSP plugins +kt_configure_ksp() diff --git a/kotlin/compiler/compiler.bzl b/kotlin/compiler/compiler.bzl new file mode 100644 index 000000000..128d0aad7 --- /dev/null +++ b/kotlin/compiler/compiler.bzl @@ -0,0 +1,127 @@ +# Copyright 2022 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + +load("//kotlin:jvm.bzl", "kt_jvm_import") +load("//kotlin:js.bzl", "kt_js_import") +load("@rules_java//java:defs.bzl", "java_import") +load("//kotlin/internal:defs.bzl", _KT_COMPILER_REPO = "KT_COMPILER_REPO") + +_KT_COMPILER_REPO_PREFIX = "@" + _KT_COMPILER_REPO + "//:" + +def kt_configure_compiler(): + """ + Defines the toolchain_type and default toolchain for kotlin compilation. + + Must be called in kotlin/internal/BUILD.bazel + """ + if native.package_name() != "kotlin/compiler": + fail("kt_configure_compiler must be called in kotlin/compiler not %s" % native.package_name()) + + kt_jvm_import( + name = "annotations", + jar = _KT_COMPILER_REPO_PREFIX + "lib/annotations-13.0.jar", + neverlink = 1, + ) + + kt_jvm_import( + name = "jvm-abi-gen", + jar = _KT_COMPILER_REPO_PREFIX + "lib/jvm-abi-gen.jar", + ) + + # Kotlin dependencies that are internal to this repo and are meant to be loaded manually into a classloader. + [ + kt_jvm_import( + name = "kotlin-%s" % art, + jar = _KT_COMPILER_REPO_PREFIX + "lib/kotlin-%s.jar" % art, + neverlink = 1, + ) + for art in [ + "annotation-processing", + "annotation-processing-runtime", + "compiler", + ] + ] + + kt_jvm_import( + name = "kotlinx-serialization-compiler-plugin", + jar = _KT_COMPILER_REPO_PREFIX + "lib/kotlinx-serialization-compiler-plugin.jar", + ) + + kt_jvm_import( + name = "allopen-compiler-plugin", + jar = _KT_COMPILER_REPO_PREFIX + "lib/allopen-compiler-plugin.jar", + ) + + kt_jvm_import( + name = "noarg-compiler-plugin", + jar = _KT_COMPILER_REPO_PREFIX + "lib/noarg-compiler-plugin.jar", + ) + + kt_jvm_import( + name = "sam-with-receiver-compiler-plugin", + jar = _KT_COMPILER_REPO_PREFIX + "lib/sam-with-receiver-compiler-plugin.jar", + ) + + kt_jvm_import( + name = "parcelize-compiler-plugin", + jar = _KT_COMPILER_REPO_PREFIX + "lib/parcelize-compiler.jar", + ) + + kt_jvm_import( + name = "parcelize-runtime", + jar = _KT_COMPILER_REPO_PREFIX + "lib/parcelize-runtime.jar", + ) + + # Kotlin dependencies that are internal to this repo and may be linked. + [ + java_import( + name = "kotlin-%s" % art, + jars = [_KT_COMPILER_REPO_PREFIX + "lib/kotlin-%s.jar" % art], + ) + for art in [ + "preloader", + ] + ] + + # The Kotlin standard libraries. These should be setup in a Toolchain. + [ + kt_jvm_import( + name = "kotlin-%s" % art, + jar = _KT_COMPILER_REPO_PREFIX + "lib/kotlin-%s.jar" % art, + srcjar = _KT_COMPILER_REPO_PREFIX + "lib/kotlin-%s-sources.jar" % art, + visibility = ["//visibility:public"], + ) + for art in [ + "stdlib", + "stdlib-jdk7", + "stdlib-jdk8", + "reflect", + "test", + "script-runtime", + ] + ] + + # The Kotlin JS standard libraries. These should be setup in a Toolchain. + [ + kt_js_import( + name = "kotlin-%s" % art, + jars = [_KT_COMPILER_REPO_PREFIX + "lib/kotlin-%s.jar" % art], + srcjar = _KT_COMPILER_REPO_PREFIX + "lib/kotlin-%s-sources.jar" % art, + visibility = ["//visibility:public"], + ) + for art in [ + "test-js", + "stdlib-js", + ] + ] diff --git a/kotlin/compiler/ksp.bzl b/kotlin/compiler/ksp.bzl new file mode 100644 index 000000000..483741ecf --- /dev/null +++ b/kotlin/compiler/ksp.bzl @@ -0,0 +1,42 @@ +# Copyright 2022 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + +load("//kotlin:jvm.bzl", "kt_jvm_import") +load("//kotlin/internal:defs.bzl", _KSP_COMPILER_PLUGIN_REPO = "KSP_COMPILER_PLUGIN_REPO") + +_KSP_COMPILER_PLUGIN_REPO_PREFIX = "@" + _KSP_COMPILER_PLUGIN_REPO + "//:" + +def kt_configure_ksp(): + """ + Defines the toolchain_type and default toolchain for KSP plugins. + + Must be called in kotlin/internal/BUILD.bazel + """ + if native.package_name() != "kotlin/compiler": + fail("kt_configure_ksp must be called in kotlin/compiler not %s" % native.package_name()) + + kt_jvm_import( + name = "symbol-processing", + jar = _KSP_COMPILER_PLUGIN_REPO_PREFIX + "symbol-processing.jar", + ) + + kt_jvm_import( + name = "symbol-processing-api", + jar = _KSP_COMPILER_PLUGIN_REPO_PREFIX + "symbol-processing-api.jar", + ) + + kt_jvm_import( + name = "symbol-processing-cmdline", + jar = _KSP_COMPILER_PLUGIN_REPO_PREFIX + "symbol-processing-cmdline.jar", + ) diff --git a/kotlin/internal/js/js.bzl b/kotlin/internal/js/js.bzl index b6f69edd2..b37127fca 100644 --- a/kotlin/internal/js/js.bzl +++ b/kotlin/internal/js/js.bzl @@ -89,7 +89,7 @@ kt_js_library = rule( ), "_toolchain": attr.label( doc = """The Kotlin JS Runtime.""", - default = Label("@" + _KT_COMPILER_REPO + "//:kotlin-stdlib-js"), + default = Label("//kotlin/compiler:kotlin-stdlib-js"), cfg = "target", ), }, @@ -108,7 +108,7 @@ def kt_js_library_macro(name, **kwargs): kwargs = _lock_attrs(name, kwargs) # TODO this is a runtime dep, it should be picked up from the _toolchain attr or from a provider. - kwargs["deps"] = kwargs.get("deps", []) + ["@" + _KT_COMPILER_REPO + "//:kotlin-stdlib-js"] + kwargs["deps"] = kwargs.get("deps", []) + ["//kotlin/compiler:kotlin-stdlib-js"] kt_js_library(name = name, **kwargs) kt_js_import = rule( diff --git a/kotlin/internal/jvm/jvm.bzl b/kotlin/internal/jvm/jvm.bzl index 822dd1597..77e769ac4 100644 --- a/kotlin/internal/jvm/jvm.bzl +++ b/kotlin/internal/jvm/jvm.bzl @@ -46,7 +46,7 @@ the repository the following Kotlin Libraries are also made available from the w * `kotlin-test`, * `kotlin-reflect`. -So if you needed to add reflect as a dep use the following label `@com_github_jetbrains_kotlin//:kotlin-reflect`. +So if you needed to add reflect as a dep use the following label `//kotlin/compiler:kotlin-reflect`. ### Mixed Mode compilation @@ -96,7 +96,6 @@ load( "//kotlin/internal:defs.bzl", _JAVA_RUNTIME_TOOLCHAIN_TYPE = "JAVA_RUNTIME_TOOLCHAIN_TYPE", _JAVA_TOOLCHAIN_TYPE = "JAVA_TOOLCHAIN_TYPE", - _KT_COMPILER_REPO = "KT_COMPILER_REPO", _KspPluginInfo = "KspPluginInfo", _KtCompilerPluginInfo = "KtCompilerPluginInfo", _KtJvmInfo = "KtJvmInfo", @@ -139,7 +138,7 @@ _implicit_deps = { "_toolchain": attr.label( doc = """The Kotlin JVM Runtime. it's only purpose is to enable the Android native rules to discover the Kotlin runtime for dexing""", - default = Label("@" + _KT_COMPILER_REPO + "//:kotlin-stdlib"), + default = Label("//kotlin/compiler:kotlin-stdlib"), cfg = "target", ), "_java_toolchain": attr.label( @@ -336,7 +335,7 @@ Setup a simple kotlin_test. **Notes:** * The kotlin test library is not added implicitly, it is available with the label -`@com_github_jetbrains_kotlin//:kotlin-test`. +`//kotlin/compiler:kotlin-test`. """, attrs = utils.add_dicts(_runnable_common_attr, { "_bazel_test_runner": attr.label( @@ -493,7 +492,7 @@ kt_compiler_plugin( "annotation": "plugin.OpenForTesting", }, deps = [ - "@com_github_jetbrains_kotlin//:allopen-compiler-plugin", + "//kotlin/compiler:allopen-compiler-plugin", ], ) diff --git a/kotlin/internal/toolchains.bzl b/kotlin/internal/toolchains.bzl index 9d1999361..9f1760fb8 100644 --- a/kotlin/internal/toolchains.bzl +++ b/kotlin/internal/toolchains.bzl @@ -157,7 +157,7 @@ _kt_toolchain = rule( "jvm_runtime": attr.label_list( doc = "The implicit jvm runtime libraries. This is internal.", default = [ - Label("@" + _KT_COMPILER_REPO + "//:kotlin-stdlib"), + Label("//kotlin/compiler:kotlin-stdlib"), ], providers = [JavaInfo], cfg = "target", @@ -165,12 +165,12 @@ _kt_toolchain = rule( "jvm_stdlibs": attr.label_list( doc = "The jvm stdlibs. This is internal.", default = [ - Label("@" + _KT_COMPILER_REPO + "//:annotations"), - Label("@" + _KT_COMPILER_REPO + "//:kotlin-stdlib"), - Label("@" + _KT_COMPILER_REPO + "//:kotlin-stdlib-jdk7"), + Label("//kotlin/compiler:annotations"), + Label("//kotlin/compiler:kotlin-stdlib"), + Label("//kotlin/compiler:kotlin-stdlib-jdk7"), # JDK8 is being added blindly but I think we will probably not support bytecode levels 1.6 when the # repo stabelizes so this should be fine. - Label("@" + _KT_COMPILER_REPO + "//:kotlin-stdlib-jdk8"), + Label("//kotlin/compiler:kotlin-stdlib-jdk8"), ], providers = [JavaInfo], cfg = "target", @@ -197,7 +197,7 @@ _kt_toolchain = rule( ), "js_stdlibs": attr.label_list( default = [ - Label("@" + _KT_COMPILER_REPO + "//:kotlin-stdlib-js"), + Label("//kotlin/compiler:kotlin-stdlib-js"), ], providers = [_KtJsInfo], ), diff --git a/src/main/kotlin/BUILD.release.bazel b/src/main/kotlin/BUILD.release.bazel index 7e2d6d119..37272bdc6 100644 --- a/src/main/kotlin/BUILD.release.bazel +++ b/src/main/kotlin/BUILD.release.bazel @@ -39,22 +39,23 @@ java_binary( data = [ ":jdeps-gen", ":skip-code-gen", + "//kotlin/compiler:jvm-abi-gen", + "//kotlin/compiler:kotlin-annotation-processing", + "//kotlin/compiler:kotlin-compiler", + "//kotlin/compiler:symbol-processing-api", + "//kotlin/compiler:symbol-processing-cmdline", "//src/main/kotlin/io/bazel/kotlin/compiler", - "@com_github_google_ksp//:symbol-processing-api", - "@com_github_google_ksp//:symbol-processing-cmdline", - "@com_github_jetbrains_kotlin//:jvm-abi-gen", - "@com_github_jetbrains_kotlin//:kotlin-annotation-processing", - "@com_github_jetbrains_kotlin//:kotlin-compiler", + "@com_github_jetbrains_kotlin//:home", ], jvm_flags = [ - "-D@com_github_jetbrains_kotlin...jvm-abi-gen=$(rlocationpath @com_github_jetbrains_kotlin//:jvm-abi-gen)", - "-D@com_github_jetbrains_kotlin...kotlin-compiler=$(rlocationpath @com_github_jetbrains_kotlin//:kotlin-compiler)", - "-D@com_github_jetbrains_kotlin...kapt=$(rlocationpath @com_github_jetbrains_kotlin//:kotlin-annotation-processing)", + "-D@com_github_jetbrains_kotlin...jvm-abi-gen=$(rlocationpath //kotlin/compiler:jvm-abi-gen)", + "-D@com_github_jetbrains_kotlin...kotlin-compiler=$(rlocationpath //kotlin/compiler:kotlin-compiler)", + "-D@com_github_jetbrains_kotlin...kapt=$(rlocationpath //kotlin/compiler:kotlin-annotation-processing)", "-D@rules_kotlin...jdeps-gen=$(rlocationpath //src/main/kotlin:jdeps-gen)", "-D@rules_kotlin...skip-code-gen=$(rlocationpath //src/main/kotlin:skip-code-gen)", "-D@rules_kotlin...compiler=$(rlocationpath //src/main/kotlin/io/bazel/kotlin/compiler)", - "-D@com_github_google_ksp...symbol-processing-api=$(rlocationpath @com_github_google_ksp//:symbol-processing-api)", - "-D@com_github_google_ksp...symbol-processing-cmdline=$(rlocationpath @com_github_google_ksp//:symbol-processing-cmdline)", + "-D@com_github_google_ksp...symbol-processing-api=$(rlocationpath //kotlin/compiler:symbol-processing-api)", + "-D@com_github_google_ksp...symbol-processing-cmdline=$(rlocationpath //kotlin/compiler:symbol-processing-cmdline)", "-XX:-MaxFDLimit", ], main_class = "io.bazel.kotlin.builder.cmd.Build", diff --git a/src/main/kotlin/bootstrap.bzl b/src/main/kotlin/bootstrap.bzl index db7728d84..9b2c9ce97 100644 --- a/src/main/kotlin/bootstrap.bzl +++ b/src/main/kotlin/bootstrap.bzl @@ -64,8 +64,8 @@ CP="%s" ARGS="%s" CMD="$(JAVA) -Xmx256M -Xms32M -noverify \ - -cp $(location @com_github_jetbrains_kotlin//:kotlin-preloader) org.jetbrains.kotlin.preloading.Preloader \ - -cp $(location @com_github_jetbrains_kotlin//:kotlin-compiler) org.jetbrains.kotlin.cli.jvm.K2JVMCompiler \ + -cp $(location //kotlin/compiler:kotlin-preloader) org.jetbrains.kotlin.preloading.Preloader \ + -cp $(location //kotlin/compiler:kotlin-compiler) org.jetbrains.kotlin.cli.jvm.K2JVMCompiler \ $$CP -d $(@D)/$${NAME}_temp.jar $${ARGS} $(SRCS)" $$CMD @@ -91,8 +91,8 @@ rm $(@D)/$${NAME}_temp.jar name = jar_label, tools = [ "@com_github_jetbrains_kotlin//:home", - "@com_github_jetbrains_kotlin//:kotlin-preloader", - "@com_github_jetbrains_kotlin//:kotlin-compiler", + "//kotlin/compiler:kotlin-preloader", + "//kotlin/compiler:kotlin-compiler", "@bazel_tools//tools/jdk:singlejar", dep_label, ], diff --git a/src/main/kotlin/io/bazel/kotlin/builder/BUILD b/src/main/kotlin/io/bazel/kotlin/builder/BUILD index 54966de81..565f2f297 100644 --- a/src/main/kotlin/io/bazel/kotlin/builder/BUILD +++ b/src/main/kotlin/io/bazel/kotlin/builder/BUILD @@ -18,10 +18,12 @@ java_library( srcs = glob(["*.java"]), visibility = ["//src:__subpackages__"], runtime_deps = [ - "@com_github_jetbrains_kotlin//:kotlin-stdlib-jdk7", - "@com_github_jetbrains_kotlin//:kotlin-stdlib-jdk8", + "//kotlin/compiler:kotlin-stdlib-jdk7", + "//kotlin/compiler:kotlin-stdlib-jdk8", ], deps = [ + "//kotlin/compiler:annotations", + "//kotlin/compiler:kotlin-stdlib", "//src/main/kotlin/io/bazel/kotlin/builder/tasks", "//src/main/kotlin/io/bazel/kotlin/builder/toolchain", "//src/main/kotlin/io/bazel/kotlin/builder/utils", @@ -30,8 +32,6 @@ java_library( "//src/main/protobuf:kotlin_model_java_proto", "//src/main/protobuf:worker_protocol_java_proto", "//third_party:dagger", - "@com_github_jetbrains_kotlin//:annotations", - "@com_github_jetbrains_kotlin//:kotlin-stdlib", "@kotlin_rules_maven//:javax_annotation_javax_annotation_api", "@kotlin_rules_maven//:javax_inject_javax_inject", ], diff --git a/src/main/kotlin/io/bazel/kotlin/builder/cmd/BUILD.bazel b/src/main/kotlin/io/bazel/kotlin/builder/cmd/BUILD.bazel index 4eaaac62c..76da46109 100644 --- a/src/main/kotlin/io/bazel/kotlin/builder/cmd/BUILD.bazel +++ b/src/main/kotlin/io/bazel/kotlin/builder/cmd/BUILD.bazel @@ -15,24 +15,25 @@ kt_bootstrap_library( kt_bootstrap_binary( name = "build", data = [ + "//kotlin/compiler:jvm-abi-gen", + "//kotlin/compiler:kotlin-annotation-processing", + "//kotlin/compiler:kotlin-compiler", + "//kotlin/compiler:symbol-processing-api", + "//kotlin/compiler:symbol-processing-cmdline", "//src/main/kotlin:jdeps-gen", "//src/main/kotlin:skip-code-gen", "//src/main/kotlin/io/bazel/kotlin/compiler", - "@com_github_google_ksp//:symbol-processing-api", - "@com_github_google_ksp//:symbol-processing-cmdline", - "@com_github_jetbrains_kotlin//:jvm-abi-gen", - "@com_github_jetbrains_kotlin//:kotlin-annotation-processing", - "@com_github_jetbrains_kotlin//:kotlin-compiler", + "@com_github_jetbrains_kotlin//:home", ], jvm_flags = [ - "-D@com_github_jetbrains_kotlin...jvm-abi-gen=$(rlocationpath @com_github_jetbrains_kotlin//:jvm-abi-gen)", - "-D@com_github_jetbrains_kotlin...kotlin-compiler=$(rlocationpath @com_github_jetbrains_kotlin//:kotlin-compiler)", - "-D@com_github_jetbrains_kotlin...kapt=$(rlocationpath @com_github_jetbrains_kotlin//:kotlin-annotation-processing)", + "-D@com_github_jetbrains_kotlin...jvm-abi-gen=$(rlocationpath //kotlin/compiler:jvm-abi-gen)", + "-D@com_github_jetbrains_kotlin...kotlin-compiler=$(rlocationpath //kotlin/compiler:kotlin-compiler)", + "-D@com_github_jetbrains_kotlin...kapt=$(rlocationpath //kotlin/compiler:kotlin-annotation-processing)", "-D@rules_kotlin...jdeps-gen=$(rlocationpath //src/main/kotlin:jdeps-gen)", "-D@rules_kotlin...skip-code-gen=$(rlocationpath //src/main/kotlin:skip-code-gen)", "-D@rules_kotlin...compiler=$(rlocationpath //src/main/kotlin/io/bazel/kotlin/compiler)", - "-D@com_github_google_ksp...symbol-processing-api=$(rlocationpath @com_github_google_ksp//:symbol-processing-api)", - "-D@com_github_google_ksp...symbol-processing-cmdline=$(rlocationpath @com_github_google_ksp//:symbol-processing-cmdline)", + "-D@com_github_google_ksp...symbol-processing-api=$(rlocationpath //kotlin/compiler:symbol-processing-api)", + "-D@com_github_google_ksp...symbol-processing-cmdline=$(rlocationpath //kotlin/compiler:symbol-processing-cmdline)", "-XX:-MaxFDLimit", ], main_class = "io.bazel.kotlin.builder.cmd.Build", diff --git a/src/main/kotlin/io/bazel/kotlin/builder/tasks/BUILD.bazel b/src/main/kotlin/io/bazel/kotlin/builder/tasks/BUILD.bazel index 10d018393..d8acfc648 100644 --- a/src/main/kotlin/io/bazel/kotlin/builder/tasks/BUILD.bazel +++ b/src/main/kotlin/io/bazel/kotlin/builder/tasks/BUILD.bazel @@ -24,6 +24,7 @@ kt_bootstrap_library( ], visibility = ["//src:__subpackages__"], deps = [ + "//kotlin/compiler:kotlin-preloader", "//src/main/kotlin/io/bazel/kotlin/builder/toolchain", "//src/main/kotlin/io/bazel/kotlin/builder/utils", "//src/main/kotlin/io/bazel/kotlin/builder/utils/jars", @@ -31,7 +32,6 @@ kt_bootstrap_library( "//src/main/protobuf:deps_java_proto", "//src/main/protobuf:kotlin_model_java_proto", "//src/main/protobuf:worker_protocol_java_proto", - "@com_github_jetbrains_kotlin//:kotlin-preloader", "@kotlin_rules_maven//:com_google_protobuf_protobuf_java", "@kotlin_rules_maven//:com_google_protobuf_protobuf_java_util", "@kotlin_rules_maven//:javax_inject_javax_inject", diff --git a/src/main/kotlin/io/bazel/kotlin/builder/toolchain/BUILD.bazel b/src/main/kotlin/io/bazel/kotlin/builder/toolchain/BUILD.bazel index 4cda9aeeb..1d579832f 100644 --- a/src/main/kotlin/io/bazel/kotlin/builder/toolchain/BUILD.bazel +++ b/src/main/kotlin/io/bazel/kotlin/builder/toolchain/BUILD.bazel @@ -19,18 +19,18 @@ kt_bootstrap_library( "*.kt", ]), neverlink_deps = [ - "@com_github_jetbrains_kotlin//:jvm-abi-gen", - "@com_github_jetbrains_kotlin//:kotlin-compiler", - "@com_github_google_ksp//:symbol-processing-api", - "@com_github_google_ksp//:symbol-processing-cmdline", + "//kotlin/compiler:jvm-abi-gen", + "//kotlin/compiler:kotlin-compiler", + "//kotlin/compiler:symbol-processing-api", + "//kotlin/compiler:symbol-processing-cmdline", ], visibility = ["//src:__subpackages__"], deps = [ + "//kotlin/compiler:kotlin-preloader", "//src/main/kotlin/io/bazel/kotlin/builder/utils", "//src/main/kotlin/io/bazel/kotlin/plugin:skip-code-gen-lib", "//src/main/kotlin/io/bazel/kotlin/plugin/jdeps:jdeps-gen-lib", "//src/main/protobuf:kotlin_model_java_proto", - "@com_github_jetbrains_kotlin//:kotlin-preloader", "@kotlin_rules_maven//:com_google_protobuf_protobuf_java", "@kotlin_rules_maven//:com_google_protobuf_protobuf_java_util", "@kotlin_rules_maven//:javax_inject_javax_inject", diff --git a/src/main/kotlin/io/bazel/kotlin/compiler/BUILD.bazel b/src/main/kotlin/io/bazel/kotlin/compiler/BUILD.bazel index 4c310e7e8..3a1472670 100644 --- a/src/main/kotlin/io/bazel/kotlin/compiler/BUILD.bazel +++ b/src/main/kotlin/io/bazel/kotlin/compiler/BUILD.bazel @@ -20,9 +20,9 @@ kt_bootstrap_library( name = "compiler", srcs = glob(["*.kt"]), neverlink_deps = [ - "@com_github_jetbrains_kotlin//:kotlin-compiler", - "@com_github_jetbrains_kotlin//:kotlin-annotation-processing", - "@com_github_jetbrains_kotlin//:kotlin-script-runtime", + "//kotlin/compiler:kotlin-compiler", + "//kotlin/compiler:kotlin-annotation-processing", + "//kotlin/compiler:kotlin-script-runtime", ], visibility = ["//src:__subpackages__"], ) diff --git a/src/main/kotlin/io/bazel/kotlin/generate/BUILD.bazel b/src/main/kotlin/io/bazel/kotlin/generate/BUILD.bazel index 82e305c13..4ce016764 100644 --- a/src/main/kotlin/io/bazel/kotlin/generate/BUILD.bazel +++ b/src/main/kotlin/io/bazel/kotlin/generate/BUILD.bazel @@ -4,8 +4,8 @@ kt_jvm_library( name = "kotlin_release_options_lib", srcs = glob(["**/*.kt"]), deps = [ - "@com_github_jetbrains_kotlin//:kotlin-compiler", - "@com_github_jetbrains_kotlin//:kotlin-reflect", + "//kotlin/compiler:kotlin-compiler", + "//kotlin/compiler:kotlin-reflect", ], ) diff --git a/src/main/kotlin/io/bazel/kotlin/plugin/BUILD.bazel b/src/main/kotlin/io/bazel/kotlin/plugin/BUILD.bazel index eaa662124..dc1cd8502 100644 --- a/src/main/kotlin/io/bazel/kotlin/plugin/BUILD.bazel +++ b/src/main/kotlin/io/bazel/kotlin/plugin/BUILD.bazel @@ -22,7 +22,7 @@ kt_bootstrap_library( srcs = glob(["*.kt"]), visibility = ["//src:__subpackages__"], deps = [ - "@com_github_jetbrains_kotlin//:kotlin-compiler", + "//kotlin/compiler:kotlin-compiler", ], ) diff --git a/src/main/kotlin/io/bazel/kotlin/plugin/jdeps/BUILD.bazel b/src/main/kotlin/io/bazel/kotlin/plugin/jdeps/BUILD.bazel index 60f5b07ee..48a6f1bf8 100644 --- a/src/main/kotlin/io/bazel/kotlin/plugin/jdeps/BUILD.bazel +++ b/src/main/kotlin/io/bazel/kotlin/plugin/jdeps/BUILD.bazel @@ -22,9 +22,9 @@ kt_bootstrap_library( srcs = glob(["*.kt"]), visibility = ["//src:__subpackages__"], deps = [ + "//kotlin/compiler:kotlin-compiler", "//src/main/kotlin/io/bazel/kotlin/builder/utils/jars", "//src/main/protobuf:deps_java_proto", - "@com_github_jetbrains_kotlin//:kotlin-compiler", "@kotlin_rules_maven//:com_google_protobuf_protobuf_java", ], ) diff --git a/src/main/starlark/core/options/BUILD.bazel b/src/main/starlark/core/options/BUILD.bazel index af636259a..aae25093f 100644 --- a/src/main/starlark/core/options/BUILD.bazel +++ b/src/main/starlark/core/options/BUILD.bazel @@ -15,7 +15,4 @@ bzl_library( name = "options", srcs = glob(["*.bzl"]), visibility = ["//:__subpackages__"], - deps = [ - "@com_github_jetbrains_kotlin//:capabilities", - ], ) diff --git a/src/main/starlark/core/repositories/BUILD b/src/main/starlark/core/repositories/BUILD index d5a58b72f..dc8b3beb4 100644 --- a/src/main/starlark/core/repositories/BUILD +++ b/src/main/starlark/core/repositories/BUILD @@ -18,6 +18,8 @@ release_archive( name = "pkg", srcs = [ "BUILD.com_github_google_ksp.bazel", + "BUILD.com_github_jetbrains_kotlin.bazel", + "compiler.bzl", "ksp.bzl", "versions.bzl", ], diff --git a/src/main/starlark/core/repositories/BUILD.com_github_google_ksp.bazel b/src/main/starlark/core/repositories/BUILD.com_github_google_ksp.bazel index ade6ddfe3..4114f50d2 100644 --- a/src/main/starlark/core/repositories/BUILD.com_github_google_ksp.bazel +++ b/src/main/starlark/core/repositories/BUILD.com_github_google_ksp.bazel @@ -11,9 +11,6 @@ # 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. -# io_bazel_rules_kotlin -load("@{{.KotlinRulesRepository}}//kotlin:jvm.bzl", "kt_jvm_import") - package(default_visibility = ["//visibility:public"]) # KSP filegroup containing everything that might be needed @@ -21,16 +18,3 @@ filegroup( name = "ksp", srcs = glob(["**"]), ) - -# Create imports for all of the jars -[ - kt_jvm_import( - name = "%s" % jar, - jar = "%s.jar" % jar, - ) - for jar in [ - "symbol-processing", - "symbol-processing-api", - "symbol-processing-cmdline", - ] -] diff --git a/src/main/starlark/core/repositories/BUILD.com_github_jetbrains_kotlin.bazel b/src/main/starlark/core/repositories/BUILD.com_github_jetbrains_kotlin.bazel new file mode 100644 index 000000000..782b6e857 --- /dev/null +++ b/src/main/starlark/core/repositories/BUILD.com_github_jetbrains_kotlin.bazel @@ -0,0 +1,20 @@ +# Copyright 2018 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. +package(default_visibility = ["//visibility:public"]) + +# Kotlin home filegroup containing everything that is needed. +filegroup( + name = "home", + srcs = glob(["**"]), +) diff --git a/src/main/starlark/core/repositories/kotlin/compiler.bzl b/src/main/starlark/core/repositories/compiler.bzl similarity index 69% rename from src/main/starlark/core/repositories/kotlin/compiler.bzl rename to src/main/starlark/core/repositories/compiler.bzl index ab03814bb..98919b5c1 100644 --- a/src/main/starlark/core/repositories/kotlin/compiler.bzl +++ b/src/main/starlark/core/repositories/compiler.bzl @@ -13,9 +13,6 @@ def _kotlin_compiler_impl(repository_ctx): repository_ctx.template( "BUILD.bazel", attr._template, - substitutions = { - "{{.KotlinRulesRepository}}": attr.kotlin_rules, - }, executable = False, ) @@ -38,12 +35,12 @@ def _get_capability_template(compiler_version, templates): return templates[0] _CAPABILITIES_TEMPLATES = { - "legacy": "capabilities_legacy.bzl.com_github_jetbrains_kotlin.bazel", # keep first - "1.4": "capabilities_1.4.bzl.com_github_jetbrains_kotlin.bazel", - "1.5": "capabilities_1.5.bzl.com_github_jetbrains_kotlin.bazel", - "1.6": "capabilities_1.6.bzl.com_github_jetbrains_kotlin.bazel", - "1.7": "capabilities_1.7.bzl.com_github_jetbrains_kotlin.bazel", - "1.8": "capabilities_1.8.bzl.com_github_jetbrains_kotlin.bazel", + "legacy": "//src/main/starlark/core/repositories/kotlin:capabilities_legacy.bzl.com_github_jetbrains_kotlin.bazel", # keep first + "1.4": "//src/main/starlark/core/repositories/kotlin:capabilities_1.4.bzl.com_github_jetbrains_kotlin.bazel", + "1.5": "//src/main/starlark/core/repositories/kotlin:capabilities_1.5.bzl.com_github_jetbrains_kotlin.bazel", + "1.6": "//src/main/starlark/core/repositories/kotlin:capabilities_1.6.bzl.com_github_jetbrains_kotlin.bazel", + "1.7": "//src/main/starlark/core/repositories/kotlin:capabilities_1.7.bzl.com_github_jetbrains_kotlin.bazel", + "1.8": "//src/main/starlark/core/repositories/kotlin:capabilities_1.8.bzl.com_github_jetbrains_kotlin.bazel", } kotlin_compiler_repository = repository_rule( @@ -53,10 +50,6 @@ kotlin_compiler_repository = repository_rule( doc = "A list of urls for the kotlin compiler", mandatory = True, ), - "kotlin_rules": attr.string( - doc = "target of the kotlin rules.", - mandatory = True, - ), "sha256": attr.string( doc = "sha256 of the compiler archive", ), @@ -65,7 +58,7 @@ kotlin_compiler_repository = repository_rule( ), "_template": attr.label( doc = "repository build file template", - default = "BUILD.com_github_jetbrains_kotlin.bazel", + default = ":BUILD.com_github_jetbrains_kotlin.bazel", ), "_capabilities_templates": attr.label_list( doc = "compiler capabilities file templates", diff --git a/src/main/starlark/core/repositories/initialize.release.bzl b/src/main/starlark/core/repositories/initialize.release.bzl index a61aafc0c..d32caccc4 100644 --- a/src/main/starlark/core/repositories/initialize.release.bzl +++ b/src/main/starlark/core/repositories/initialize.release.bzl @@ -25,7 +25,7 @@ load( "http_file", ) load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") -load("//src/main/starlark/core/repositories/kotlin:compiler.bzl", "kotlin_compiler_repository") +load(":compiler.bzl", "kotlin_compiler_repository") load(":ksp.bzl", "ksp_compiler_plugin_repository") load(":versions.bzl", "version", _versions = "versions") @@ -52,7 +52,6 @@ def kotlin_repositories( name = compiler_repository_name, urls = [url.format(version = compiler_release.version) for url in compiler_release.url_templates], sha256 = compiler_release.sha256, - kotlin_rules = RULES_KOTLIN.workspace_name, compiler_version = compiler_release.version, ) @@ -61,7 +60,6 @@ def kotlin_repositories( urls = [url.format(version = ksp_compiler_release.version) for url in ksp_compiler_release.url_templates], sha256 = ksp_compiler_release.sha256, strip_version = ksp_compiler_release.version, - kotlin_rules = RULES_KOTLIN.workspace_name, ) http_file( diff --git a/src/main/starlark/core/repositories/kotlin/BUILD b/src/main/starlark/core/repositories/kotlin/BUILD index a104eced6..b8d84766e 100644 --- a/src/main/starlark/core/repositories/kotlin/BUILD +++ b/src/main/starlark/core/repositories/kotlin/BUILD @@ -5,8 +5,6 @@ release_archive( name = "pkg", srcs = [ "BUILD", - "BUILD.com_github_jetbrains_kotlin.bazel", - "compiler.bzl", ] + glob(["capabilities_*.bazel"]), ) diff --git a/src/main/starlark/core/repositories/kotlin/BUILD.com_github_jetbrains_kotlin.bazel b/src/main/starlark/core/repositories/kotlin/BUILD.com_github_jetbrains_kotlin.bazel deleted file mode 100644 index 9e0559964..000000000 --- a/src/main/starlark/core/repositories/kotlin/BUILD.com_github_jetbrains_kotlin.bazel +++ /dev/null @@ -1,146 +0,0 @@ -# Copyright 2018 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# 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. -# io_bazel_rules_kotlin -load("@{{.KotlinRulesRepository}}//kotlin:jvm.bzl", "kt_jvm_import") -load("@{{.KotlinRulesRepository}}//kotlin:js.bzl", "kt_js_import") -load("@rules_java//java:defs.bzl", "java_import") -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - -package(default_visibility = ["//visibility:public"]) - -exports_files( - ["capabilities.bzl"], -) - -# Kotlin home filegroup containing everything that is needed. -filegroup( - name = "home", - srcs = glob(["**"]), -) - -kt_jvm_import( - name = "annotations", - jar = "lib/annotations-13.0.jar", -) - -kt_jvm_import( - name = "trove4j", - jar = "lib/trove4j.jar", -) - -kt_jvm_import( - name = "jvm-abi-gen", - jar = "lib/jvm-abi-gen.jar", -) - -kt_jvm_import( - name = "kotlin-compiler", - jar = "lib/kotlin-compiler.jar", - neverlink = 1, - deps = [ - ":annotations", - ":kotlin-reflect", - ":kotlin-script-runtime", - ":kotlin-stdlib", - ":trove4j", - ], -) - -kt_jvm_import( - name = "kotlin-annotation-processing-runtime", - jar = "lib/kotlin-annotation-processing-runtime.jar", -) - -kt_jvm_import( - name = "kotlin-annotation-processing", - jar = "lib/kotlin-annotation-processing.jar", -) - -kt_jvm_import( - name = "kotlinx-serialization-compiler-plugin", - jar = "lib/kotlinx-serialization-compiler-plugin.jar", -) - -kt_jvm_import( - name = "allopen-compiler-plugin", - jar = "lib/allopen-compiler-plugin.jar", -) - -kt_jvm_import( - name = "noarg-compiler-plugin", - jar = "lib/noarg-compiler-plugin.jar", -) - -kt_jvm_import( - name = "sam-with-receiver-compiler-plugin", - jar = "lib/sam-with-receiver-compiler-plugin.jar", -) - -kt_jvm_import( - name = "parcelize-compiler-plugin", - jar = "lib/parcelize-compiler.jar", -) - -kt_jvm_import( - name = "parcelize-runtime", - jar = "lib/parcelize-runtime.jar", -) - -# Kotlin dependencies that are internal to this repo and may be linked. -[ - java_import( - name = "kotlin-%s" % art, - jars = ["lib/kotlin-%s.jar" % art], - ) - for art in [ - "preloader", - ] -] - -# The Kotlin standard libraries. These should be setup in a Toolchain. -[ - kt_jvm_import( - name = "kotlin-%s" % art, - jar = "lib/kotlin-%s.jar" % art, - srcjar = "lib/kotlin-%s-sources.jar" % art, - visibility = ["//visibility:public"], - ) - for art in [ - "stdlib", - "stdlib-jdk7", - "stdlib-jdk8", - "reflect", - "test", - "script-runtime", - ] -] - -# The Kotlin JS standard libraries. These should be setup in a Toolchain. -[ - kt_js_import( - name = "kotlin-%s" % art, - jars = ["lib/kotlin-%s.jar" % art], - srcjar = "lib/kotlin-%s-sources.jar" % art, - visibility = ["//visibility:public"], - ) - for art in [ - "test-js", - "stdlib-js", - ] -] - -bzl_library( - name = "capabilities", - srcs = ["capabilities.bzl"], -) diff --git a/src/main/starlark/core/repositories/ksp.bzl b/src/main/starlark/core/repositories/ksp.bzl index f605c09e5..dc1c3ca19 100644 --- a/src/main/starlark/core/repositories/ksp.bzl +++ b/src/main/starlark/core/repositories/ksp.bzl @@ -30,9 +30,6 @@ def _ksp_compiler_plugin_repository_impl(repository_ctx): repository_ctx.template( "BUILD.bazel", attr._template, - substitutions = { - "{{.KotlinRulesRepository}}": attr.kotlin_rules, - }, executable = False, ) @@ -43,10 +40,6 @@ ksp_compiler_plugin_repository = repository_rule( doc = "A list of urls for the kotlin compiler", mandatory = True, ), - "kotlin_rules": attr.string( - doc = "target of the kotlin rules.", - mandatory = True, - ), "sha256": attr.string( doc = "sha256 of the compiler archive", ), diff --git a/src/test/kotlin/io/bazel/kotlin/BUILD b/src/test/kotlin/io/bazel/kotlin/BUILD index 513ec3f32..f87a75b32 100644 --- a/src/test/kotlin/io/bazel/kotlin/BUILD +++ b/src/test/kotlin/io/bazel/kotlin/BUILD @@ -22,13 +22,13 @@ kt_jvm_library( srcs = ["KotlinAssertionTestCase.kt"], visibility = ["//visibility:public"], exports = [ - "@com_github_jetbrains_kotlin//:kotlin-test", + "//kotlin/compiler:kotlin-test", "@kotlin_rules_maven//:com_google_guava_guava", "@kotlin_rules_maven//:com_google_truth_truth", "@kotlin_rules_maven//:junit_junit", ], deps = [ - "@com_github_jetbrains_kotlin//:kotlin-test", + "//kotlin/compiler:kotlin-test", "@kotlin_rules_maven//:com_google_guava_guava", ], ) diff --git a/src/test/kotlin/io/bazel/kotlin/builder/BUILD b/src/test/kotlin/io/bazel/kotlin/builder/BUILD index 9a1a714ca..26e205e1e 100644 --- a/src/test/kotlin/io/bazel/kotlin/builder/BUILD +++ b/src/test/kotlin/io/bazel/kotlin/builder/BUILD @@ -45,9 +45,9 @@ java_library( ], exports = _COMMON_DEPS, runtime_deps = [ + "//kotlin/compiler:kotlin-reflect", + "//kotlin/compiler:kotlin-stdlib", "@bazel_tools//tools/jdk:JacocoCoverage", - "@com_github_jetbrains_kotlin//:kotlin-reflect", - "@com_github_jetbrains_kotlin//:kotlin-stdlib", ], deps = _COMMON_DEPS + [ "//src/main/kotlin/io/bazel/kotlin/builder/tasks", diff --git a/src/test/kotlin/io/bazel/kotlin/builder/KotlinAbstractTestBuilder.java b/src/test/kotlin/io/bazel/kotlin/builder/KotlinAbstractTestBuilder.java index 8aff079e2..dc1a804b2 100644 --- a/src/test/kotlin/io/bazel/kotlin/builder/KotlinAbstractTestBuilder.java +++ b/src/test/kotlin/io/bazel/kotlin/builder/KotlinAbstractTestBuilder.java @@ -229,14 +229,14 @@ static KotlinToolchain toolchainForTest() { } return KotlinToolchain.createToolchain( javaHome, - new File(Deps.Dep.fromLabel("@com_github_jetbrains_kotlin//:kotlin-compiler").singleCompileJar()), + new File(Deps.Dep.fromLabel("//kotlin/compiler:kotlin-compiler").singleCompileJar()), new File(Deps.Dep.fromLabel("//src/main/kotlin/io/bazel/kotlin/compiler").singleCompileJar()), - new File(Deps.Dep.fromLabel("@com_github_jetbrains_kotlin//:jvm-abi-gen").singleCompileJar()), + new File(Deps.Dep.fromLabel("//kotlin/compiler:jvm-abi-gen").singleCompileJar()), new File(Deps.Dep.fromLabel("//src/main/kotlin:skip-code-gen").singleCompileJar()), new File(Deps.Dep.fromLabel("//src/main/kotlin:jdeps-gen").singleCompileJar()), - new File(Deps.Dep.fromLabel("@com_github_jetbrains_kotlin//:kotlin-annotation-processing").singleCompileJar()), - new File(Deps.Dep.fromLabel("@com_github_google_ksp//:symbol-processing-api").singleCompileJar()), - new File(Deps.Dep.fromLabel("@com_github_google_ksp//:symbol-processing-cmdline").singleCompileJar()) + new File(Deps.Dep.fromLabel("//kotlin/compiler:kotlin-annotation-processing").singleCompileJar()), + new File(Deps.Dep.fromLabel("//kotlin/compiler:symbol-processing-api").singleCompileJar()), + new File(Deps.Dep.fromLabel("//kotlin/compiler:symbol-processing-cmdline").singleCompileJar()) ); } } diff --git a/src/test/kotlin/io/bazel/kotlin/builder/KotlinJvmTestBuilder.java b/src/test/kotlin/io/bazel/kotlin/builder/KotlinJvmTestBuilder.java index b74a91486..39c07aeb8 100644 --- a/src/test/kotlin/io/bazel/kotlin/builder/KotlinJvmTestBuilder.java +++ b/src/test/kotlin/io/bazel/kotlin/builder/KotlinJvmTestBuilder.java @@ -35,11 +35,11 @@ public final class KotlinJvmTestBuilder extends KotlinAbstractTestBuilder 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", ], From 0e529dca461c099f9e10f8714ab8046a12278bc0 Mon Sep 17 00:00:00 2001 From: Benjamin Lee Date: Fri, 18 Aug 2023 14:27:04 -0700 Subject: [PATCH 2/6] Docs --- docs/kotlin.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/kotlin.md b/docs/kotlin.md index 534ac1c61..a4aa912b1 100755 --- a/docs/kotlin.md +++ b/docs/kotlin.md @@ -211,7 +211,7 @@ kt_jvm_test(name, name, Date: Tue, 5 Sep 2023 10:52:42 -0700 Subject: [PATCH 3/6] Fix JS --- kotlin/internal/js/js.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kotlin/internal/js/js.bzl b/kotlin/internal/js/js.bzl index b37127fca..7a360d5f4 100644 --- a/kotlin/internal/js/js.bzl +++ b/kotlin/internal/js/js.bzl @@ -108,7 +108,7 @@ def kt_js_library_macro(name, **kwargs): kwargs = _lock_attrs(name, kwargs) # TODO this is a runtime dep, it should be picked up from the _toolchain attr or from a provider. - kwargs["deps"] = kwargs.get("deps", []) + ["//kotlin/compiler:kotlin-stdlib-js"] + kwargs["deps"] = kwargs.get("deps", []) + ["@io_bazel_rules_kotlin//kotlin/compiler:kotlin-stdlib-js"] kt_js_library(name = name, **kwargs) kt_js_import = rule( From ddcfcab738de1fb051ba6a2660f4c0842403454a Mon Sep 17 00:00:00 2001 From: Benjamin Lee Date: Tue, 5 Sep 2023 11:08:04 -0700 Subject: [PATCH 4/6] More fixes --- kotlin/internal/BUILD | 1 - src/main/starlark/BUILD.bazel | 5 +---- src/main/starlark/core/repositories/BUILD | 1 - src/main/starlark/core/repositories/kotlin/BUILD | 7 ------- 4 files changed, 1 insertion(+), 13 deletions(-) diff --git a/kotlin/internal/BUILD b/kotlin/internal/BUILD index b98b89da9..5c1210fe6 100644 --- a/kotlin/internal/BUILD +++ b/kotlin/internal/BUILD @@ -43,6 +43,5 @@ bzl_library( "//kotlin/internal/jvm", "//kotlin/internal/lint", "//kotlin/internal/utils", - "//src/main/starlark", ], ) diff --git a/src/main/starlark/BUILD.bazel b/src/main/starlark/BUILD.bazel index 4d7c3bf4d..39795f02f 100644 --- a/src/main/starlark/BUILD.bazel +++ b/src/main/starlark/BUILD.bazel @@ -3,9 +3,6 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") release_archive( name = "pkg", - srcs = glob( - ["*.bzl"], - ), package_dir = "src/main/starlark", # explicitly set the package directory, as there are no parent release_archives. src_map = { "BUILD.release.bazel": "BUILD.bazel", @@ -17,7 +14,7 @@ release_archive( bzl_library( name = "starlark", - srcs = glob(["*.bzl"]), + srcs = [], visibility = ["//visibility:public"], deps = [ "//src/main/starlark/core", diff --git a/src/main/starlark/core/repositories/BUILD b/src/main/starlark/core/repositories/BUILD index dc8b3beb4..09d8a2c6f 100644 --- a/src/main/starlark/core/repositories/BUILD +++ b/src/main/starlark/core/repositories/BUILD @@ -37,7 +37,6 @@ bzl_library( srcs = glob(["*.bzl"]), visibility = ["//:__subpackages__"], deps = [ - "//src/main/starlark/core/repositories/kotlin", "@rules_proto//proto", "@rules_proto//proto/private", ], diff --git a/src/main/starlark/core/repositories/kotlin/BUILD b/src/main/starlark/core/repositories/kotlin/BUILD index b8d84766e..61d1d09d1 100644 --- a/src/main/starlark/core/repositories/kotlin/BUILD +++ b/src/main/starlark/core/repositories/kotlin/BUILD @@ -1,5 +1,4 @@ load("//src/main/starlark/release:packager.bzl", "release_archive") -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") release_archive( name = "pkg", @@ -7,9 +6,3 @@ release_archive( "BUILD", ] + glob(["capabilities_*.bazel"]), ) - -bzl_library( - name = "kotlin", - srcs = glob(["*.bzl"]), - visibility = ["//:__subpackages__"], -) From b9eb222c8af27cda7456dab6b8259a6997c29f9b Mon Sep 17 00:00:00 2001 From: Benjamin Lee Date: Tue, 5 Sep 2023 11:49:06 -0700 Subject: [PATCH 5/6] More --- kotlin/internal/BUILD | 1 + src/main/starlark/core/options/BUILD.bazel | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/kotlin/internal/BUILD b/kotlin/internal/BUILD index 5c1210fe6..b98b89da9 100644 --- a/kotlin/internal/BUILD +++ b/kotlin/internal/BUILD @@ -43,5 +43,6 @@ bzl_library( "//kotlin/internal/jvm", "//kotlin/internal/lint", "//kotlin/internal/utils", + "//src/main/starlark", ], ) diff --git a/src/main/starlark/core/options/BUILD.bazel b/src/main/starlark/core/options/BUILD.bazel index aae25093f..59d6a7d7e 100644 --- a/src/main/starlark/core/options/BUILD.bazel +++ b/src/main/starlark/core/options/BUILD.bazel @@ -13,6 +13,8 @@ release_archive( bzl_library( name = "options", - srcs = glob(["*.bzl"]), + srcs = glob(["*.bzl"]) + [ + "@com_github_jetbrains_kotlin//:capabilities.bzl", + ], visibility = ["//:__subpackages__"], ) From bfc2a9cd1d74ee5759b2b6ada2099deb0a53036e Mon Sep 17 00:00:00 2001 From: Benjamin Lee Date: Tue, 5 Sep 2023 11:53:12 -0700 Subject: [PATCH 6/6] Docs --- docs/kotlin.md | 2 +- kotlin/internal/jvm/jvm.bzl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/kotlin.md b/docs/kotlin.md index a4aa912b1..26720f7a1 100755 --- a/docs/kotlin.md +++ b/docs/kotlin.md @@ -330,7 +330,7 @@ kt_compiler_plugin(name,