Skip to content
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
16 changes: 13 additions & 3 deletions kotlin/internal/jvm/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
load("//src/main/starlark/release:packager.bzl", "release_archive")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

# Copyright 2018 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,6 +11,10 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
# 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("//src/main/starlark/release:packager.bzl", "release_archive")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")

exports_files(["jetbrains-deshade.jarjar"])

release_archive(
Expand All @@ -30,6 +31,15 @@ bzl_library(
visibility = ["//kotlin:__subpackages__"],
deps = [
"//third_party:bzl",
"@bazel_skylib//rules:common_settings",
"@build_bazel_rules_android//android",
],
)

# Jdeps plugin can be enabled or disabled using the following flag ont the command line
# --@io_bazel_rules_kotlin//kotlin/internal/jvm:kotlin_deps=false
bool_flag(
name = "kotlin_deps",
build_setting_default = True, # Upstream default behavior
visibility = ["//visibility:public"],
)
10 changes: 10 additions & 0 deletions kotlin/internal/jvm/BUILD.release.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,14 @@
# 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("@bazel_skylib//rules:common_settings.bzl", "bool_flag")

exports_files(["jetbrains-deshade.jarjar"])

# Jdeps plugin can be enabled or disabled using the following flag ont the command line
# --@io_bazel_rules_kotlin//kotlin/internal/jvm:kotlin_deps=false
bool_flag(
name = "kotlin_deps",
build_setting_default = True, # Upstream default behavior
visibility = ["//visibility:public"],
)
64 changes: 37 additions & 27 deletions kotlin/internal/jvm/compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ load(
"find_java_runtime_toolchain",
"find_java_toolchain",
)
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")

# UTILITY ##############################################################################################################

Expand Down Expand Up @@ -487,7 +488,11 @@ def kt_jvm_produce_jar_actions(ctx, rule_kind):
generated_src_jars = []
annotation_processing = None
compile_jar = ctx.actions.declare_file(ctx.label.name + ".abi.jar")
output_jdeps = ctx.actions.declare_file(ctx.label.name + ".jdeps")

output_jdeps = None
if ctx.attr._kotlin_deps[BuildSettingInfo].value:
output_jdeps = ctx.actions.declare_file(ctx.label.name + ".jdeps")

outputs_struct = _run_kt_java_builder_actions(
ctx = ctx,
rule_kind = rule_kind,
Expand Down Expand Up @@ -629,21 +634,23 @@ def _run_kt_java_builder_actions(
# Build Kotlin
if has_kt_sources:
kt_runtime_jar = ctx.actions.declare_file(ctx.label.name + "-kt.jar")
kt_jdeps = ctx.actions.declare_file(ctx.label.name + "-kt.jdeps")
if not "kt_abi_plugin_incompatible" in ctx.attr.tags and toolchains.kt.experimental_use_abi_jars == True:
kt_compile_jar = ctx.actions.declare_file(ctx.label.name + "-kt.abi.jar")
outputs = {
"output": kt_runtime_jar,
"abi_jar": kt_compile_jar,
"kotlin_output_jdeps": kt_jdeps,
}
else:
kt_compile_jar = kt_runtime_jar
outputs = {
"output": kt_runtime_jar,
"kotlin_output_jdeps": kt_jdeps,
}

kt_jdeps = None
if ctx.attr._kotlin_deps[BuildSettingInfo].value:
kt_jdeps = ctx.actions.declare_file(ctx.label.name + "-kt.jdeps")
outputs["kotlin_output_jdeps"] = kt_jdeps

_run_kt_builder_action(
ctx = ctx,
rule_kind = rule_kind,
Expand Down Expand Up @@ -720,24 +727,25 @@ def _run_kt_java_builder_actions(
input_jars = compile_jars,
)

jdeps = []
for java_info in java_infos:
if java_info.outputs.jdeps:
jdeps.append(java_info.outputs.jdeps)

if jdeps:
_run_merge_jdeps_action(
ctx = ctx,
toolchains = toolchains,
jdeps = jdeps,
deps = compile_deps.deps,
outputs = {"output": output_jdeps},
)
else:
ctx.actions.symlink(
output = output_jdeps,
target_file = toolchains.kt.empty_jdeps,
)
if ctx.attr._kotlin_deps[BuildSettingInfo].value:
jdeps = []
for java_info in java_infos:
if java_info.outputs.jdeps:
jdeps.append(java_info.outputs.jdeps)

if jdeps:
_run_merge_jdeps_action(
ctx = ctx,
toolchains = toolchains,
jdeps = jdeps,
deps = compile_deps.deps,
outputs = {"output": output_jdeps},
)
else:
ctx.actions.symlink(
output = output_jdeps,
target_file = toolchains.kt.empty_jdeps,
)

annotation_processing = None
if annotation_processors:
Expand Down Expand Up @@ -781,7 +789,6 @@ def export_only_providers(ctx, actions, attr, outputs):
kt_compiler_result
"""
toolchains = _compiler_toolchains(ctx)
output_jdeps = ctx.actions.declare_file(ctx.label.name + ".jdeps")

# satisfy the outputs requirement. should never execute during normal compilation.
actions.symlink(
Expand All @@ -794,10 +801,13 @@ def export_only_providers(ctx, actions, attr, outputs):
target_file = toolchains.kt.empty_jar,
)

actions.symlink(
output = output_jdeps,
target_file = toolchains.kt.empty_jdeps,
)
output_jdeps = None
if ctx.attr._kotlin_deps[BuildSettingInfo].value:
output_jdeps = ctx.actions.declare_file(ctx.label.name + ".jdeps")
actions.symlink(
output = output_jdeps,
target_file = toolchains.kt.empty_jdeps,
)

java = JavaInfo(
output_jar = toolchains.kt.empty_jar,
Expand Down
5 changes: 4 additions & 1 deletion kotlin/internal/jvm/impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ def _is_absolute(path):
return path.startswith("/") or (len(path) > 2 and path[1] == ":")

def _make_providers(ctx, providers, transitive_files = depset(order = "default"), *additional_providers):
files = [ctx.outputs.jar]
if providers.java.outputs.jdeps:
files.append(providers.java.outputs.jdeps)
return struct(
kt = providers.kt,
providers = [
providers.java,
providers.kt,
providers.instrumented_files,
DefaultInfo(
files = depset([ctx.outputs.jar, providers.java.outputs.jdeps]),
files = depset(files),
runfiles = ctx.runfiles(
# explicitly include data files, otherwise they appear to be missing
files = ctx.files.data,
Expand Down
1 change: 1 addition & 0 deletions kotlin/internal/jvm/jvm.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ _common_attr = utils.add_dicts(
providers = [_JavacOptions],
mandatory = False,
),
"_kotlin_deps": attr.label(default = ":kotlin_deps"),
},
)

Expand Down
2 changes: 2 additions & 0 deletions src/main/starlark/core/repositories/download.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def kt_download_local_dev_dependencies():
],
)

# bazel_skylib is initialized twice during developement. This is intentional, as development
# needs to be able to run the starlark unittests, while production does not.
maybe(
http_archive,
name = "bazel_skylib",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,20 @@ def kotlin_repositories(
],
)

# See note in versions.bzl before updating bazel_skylib
maybe(
http_archive,
name = "bazel_skylib",
urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/%s/bazel-skylib-%s.tar.gz" % (versions.SKYLIB_VERSION, versions.SKYLIB_VERSION)],
sha256 = versions.SKYLIB_SHA,
)

selected_version = None
for (version, criteria) in versions.CORE.items():
if (criteria and compiler_release.version.startswith(criteria.prefix)) or (not selected_version and not criteria):
selected_version = version

if configured_repository_name: # without a repository name, no default kt_* rules repository is created.
print("Creating rules repository %s" % RULES_KOTLIN.workspace_name)
rules_repository(
name = configured_repository_name,
archive = Label("//:%s.tgz" % selected_version),
Expand Down
7 changes: 7 additions & 0 deletions src/main/starlark/core/repositories/versions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ versions = struct(
RULES_NODEJS_SHA = "f10a3a12894fc3c9bf578ee5a5691769f6805c4be84359681a785a0c12e8d2b6",
BAZEL_TOOLCHAINS_VERSION = "4.1.0",
BAZEL_TOOLCHAINS_SHA = "179ec02f809e86abf56356d8898c8bd74069f1bd7c56044050c2cd3d79d0e024",
# IMPORTANT! rules_kotlin does not use the bazel_skylib unittest in production
# This means the bazel_skylib_workspace call is skipped, as it only registers the unittest
# toolchains. However, if a new workspace dependency is introduced, this precondition will fail.
# Why skip it? Because it would introduce a 3rd function call to rules kotlin setup:
# 1. Download archive
# 2. Download dependencies and Configure rules
# --> 3. Configure dependencies <--
SKYLIB_VERSION = "1.2.1",
SKYLIB_SHA = "f7be3474d42aae265405a592bb7da8e171919d74c16f082a5457840f06054728",
PROTOBUF_VERSION = "3.11.3",
Expand Down