Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the KSP and compiler target definitions into rules_kotlin #1014

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ kt_compiler_plugin(
"annotation": "plugin.allopen.OpenForTesting",
},
deps = [
"@com_github_jetbrains_kotlin//:allopen-compiler-plugin",
"//kotlin/compiler:allopen-compiler-plugin",
],
)

Expand Down
4 changes: 2 additions & 2 deletions docs/kotlin.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ kt_jvm_test(<a href="#kt_jvm_test-name">name</a>, <a href="#kt_jvm_test-associat

**Notes:**
* The kotlin test library is not added implicitly, it is available with the label
`@com_github_jetbrains_kotlin//:kotlin-test`.
`@io_bazel_rules_kotlin//kotlin/compiler:kotlin-test`.


**ATTRIBUTES**
Expand Down Expand Up @@ -330,7 +330,7 @@ kt_compiler_plugin(<a href="#kt_compiler_plugin-name">name</a>, <a href="#kt_com
"annotation": "plugin.OpenForTesting",
},
deps = [
"@com_github_jetbrains_kotlin//:allopen-compiler-plugin",
"//kotlin/compiler:allopen-compiler-plugin",
],
)

Expand Down
2 changes: 1 addition & 1 deletion examples/android/libKtAndroid/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand Down
2 changes: 1 addition & 1 deletion examples/plugin/src/allopen/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand Down
6 changes: 3 additions & 3 deletions examples/plugin/src/allopennoarg/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand All @@ -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",
],
)

Expand Down Expand Up @@ -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",
],
)
4 changes: 2 additions & 2 deletions examples/plugin/src/noarg/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand All @@ -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",
],
)
4 changes: 2 additions & 2 deletions examples/plugin/src/parcelize/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand All @@ -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",
],
)

Expand Down
2 changes: 1 addition & 1 deletion examples/plugin/src/sam_with_receiver/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand Down
2 changes: 1 addition & 1 deletion examples/plugin/src/serialization/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand Down
1 change: 1 addition & 0 deletions kotlin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ release_archive(
"BUILD.release.bazel": "BUILD.bazel",
},
deps = [
"//kotlin/compiler:pkg",
"//kotlin/internal:pkg",
"//kotlin/settings:pkg",
],
Expand Down
32 changes: 32 additions & 0 deletions kotlin/compiler/BUILD
Original file line number Diff line number Diff line change
@@ -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",
},
)
23 changes: 23 additions & 0 deletions kotlin/compiler/BUILD.release.bazel
Original file line number Diff line number Diff line change
@@ -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()
127 changes: 127 additions & 0 deletions kotlin/compiler/compiler.bzl
Original file line number Diff line number Diff line change
@@ -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",
]
]
42 changes: 42 additions & 0 deletions kotlin/compiler/ksp.bzl
Original file line number Diff line number Diff line change
@@ -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",
)
4 changes: 2 additions & 2 deletions kotlin/internal/js/js.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
},
Expand All @@ -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", []) + ["@io_bazel_rules_kotlin//kotlin/compiler:kotlin-stdlib-js"]
kt_js_library(name = name, **kwargs)

kt_js_import = rule(
Expand Down
Loading